Skip to content

Commit

Permalink
[Paywalls V2] Deprecate PaywallFooter in favor of OriginalTemplatePay…
Browse files Browse the repository at this point in the history
…wallFooter (#2111)

### Description
This deprecates the existing Paywall Footer APIs with others to make it
clearer that they won't work as expected with the new V2 paywalls. It
additionally adds some docs about the `displayCloseButton` and
`fontProvider` paywall options to indicate they will be ignored with
paywalls V2.

---------

Co-authored-by: JayShortway <[email protected]>
  • Loading branch information
tonidero and JayShortway authored Feb 14, 2025
1 parent c5366c4 commit 19259bf
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.revenuecat.purchases.Offering;
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener;
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider;
import com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView;
import com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView;

@SuppressWarnings({"unused"})
Expand All @@ -18,17 +19,34 @@ static void checkConstructors(Context context,
PaywallListener listener,
FontProvider fontProvider,
Boolean condensed) {
PaywallFooterView footerView = new PaywallFooterView(context);
PaywallFooterView footerView2 = new PaywallFooterView(context, attrs);
PaywallFooterView footerView3 = new PaywallFooterView(context, attrs, defStyleAttr);
PaywallFooterView footerView4 = new PaywallFooterView(context, offering);
PaywallFooterView footerView5 = new PaywallFooterView(context, offering, listener);
PaywallFooterView footerView6 = new PaywallFooterView(context, offering, listener, fontProvider);
PaywallFooterView footerView7 = new PaywallFooterView(context, offering, listener, fontProvider, condensed);
PaywallFooterView footerView8 = new PaywallFooterView(context, offering, listener, fontProvider, condensed, () -> null);
PaywallFooterView deprecatedFooterView = new PaywallFooterView(context);
PaywallFooterView deprecatedFooterView2 = new PaywallFooterView(context, attrs);
PaywallFooterView deprecatedFooterView3 = new PaywallFooterView(context, attrs, defStyleAttr);
PaywallFooterView deprecatedFooterView4 = new PaywallFooterView(context, offering);
PaywallFooterView deprecatedFooterView5 = new PaywallFooterView(context, offering, listener);
PaywallFooterView deprecatedFooterView6 = new PaywallFooterView(context, offering, listener, fontProvider);
PaywallFooterView deprecatedFooterView7 = new PaywallFooterView(context, offering, listener, fontProvider, condensed);
PaywallFooterView deprecatedFooterView8 = new PaywallFooterView(context, offering, listener, fontProvider, condensed, () -> null);
OriginalTemplatePaywallFooterView footerView = new OriginalTemplatePaywallFooterView(context);
OriginalTemplatePaywallFooterView footerView2 = new OriginalTemplatePaywallFooterView(context, attrs);
OriginalTemplatePaywallFooterView footerView3 = new OriginalTemplatePaywallFooterView(context, attrs, defStyleAttr);
OriginalTemplatePaywallFooterView footerView4 = new OriginalTemplatePaywallFooterView(context, offering);
OriginalTemplatePaywallFooterView footerView5 = new OriginalTemplatePaywallFooterView(context, offering, listener);
OriginalTemplatePaywallFooterView footerView6 = new OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider);
OriginalTemplatePaywallFooterView footerView7 = new OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider, condensed);
OriginalTemplatePaywallFooterView footerView8 = new OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider, condensed, () -> null);
}

static void checkMethods(PaywallFooterView footerView, PaywallListener listener) {
static void checkDeprecatedMethods(PaywallFooterView footerView, PaywallListener listener) {
footerView.setPaywallListener(null);
footerView.setPaywallListener(listener);
footerView.setDismissHandler(null);
footerView.setDismissHandler(() -> null);
footerView.setOfferingId(null);
footerView.setOfferingId("offeringId");
}

static void checkMethods(OriginalTemplatePaywallFooterView footerView, PaywallListener listener) {
footerView.setPaywallListener(null);
footerView.setPaywallListener(listener);
footerView.setDismissHandler(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.revenuecat.apitester.kotlin.revenuecatui

import androidx.compose.runtime.Composable
import com.revenuecat.purchases.ui.revenuecatui.OriginalTemplatePaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.Paywall
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialogOptions
Expand All @@ -21,6 +22,10 @@ private class PaywallAPI {
PaywallFooter(options = options, condensed = true)
PaywallFooter(options = options) {}
PaywallFooter(options = options, condensed = true) {}
OriginalTemplatePaywallFooter(options = options)
OriginalTemplatePaywallFooter(options = options, condensed = true)
OriginalTemplatePaywallFooter(options = options) {}
OriginalTemplatePaywallFooter(options = options, condensed = true) {}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import android.widget.FrameLayout
import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider
import com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView
import com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView

@Suppress("unused", "UNUSED_VARIABLE")
private class PaywallFooterViewAPI {

fun checkType(context: Context) {
val paywallFooterView: FrameLayout = PaywallFooterView(context)
val paywallFooterView: FrameLayout = OriginalTemplatePaywallFooterView(context)
}

@Suppress("LongParameterList")
Expand All @@ -26,18 +26,18 @@ private class PaywallFooterViewAPI {
condensed: Boolean,
dismissHandler: () -> Unit,
) {
PaywallFooterView(context)
PaywallFooterView(context, attrs)
PaywallFooterView(context, attrs, defStyleAttr)
PaywallFooterView(context, offering)
PaywallFooterView(context, offering, listener)
PaywallFooterView(context, offering, listener, fontProvider)
PaywallFooterView(context, offering, listener, fontProvider, condensed)
PaywallFooterView(context, offering, listener, fontProvider, condensed, dismissHandler)
OriginalTemplatePaywallFooterView(context)
OriginalTemplatePaywallFooterView(context, attrs)
OriginalTemplatePaywallFooterView(context, attrs, defStyleAttr)
OriginalTemplatePaywallFooterView(context, offering)
OriginalTemplatePaywallFooterView(context, offering, listener)
OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider)
OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider, condensed)
OriginalTemplatePaywallFooterView(context, offering, listener, fontProvider, condensed, dismissHandler)
}

fun checkMethods(
paywallFooterView: PaywallFooterView,
paywallFooterView: OriginalTemplatePaywallFooterView,
paywallListener: PaywallListener,
dismissHandler: () -> Unit,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingDefaultResource">
<com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView
android:fontFamily="FONT"
app:offeringIdentifier="offering_id"
app:condensed="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView
android:fontFamily="FONT"
app:offeringIdentifier="offering_id"
Expand Down
1 change: 1 addition & 0 deletions config/detekt/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<ID>ModifierMissing:InsetSpacers.kt$SystemBarsSpacer</ID>
<ID>ModifierMissing:MainScreen.kt$MainScreen</ID>
<ID>ModifierMissing:MainScreen.kt$MainScreenNavigation</ID>
<ID>ModifierMissing:PaywallFooter.kt$OriginalTemplatePaywallFooter</ID>
<ID>ModifierMissing:PaywallFooter.kt$PaywallFooter</ID>
<ID>ModifierMissing:PaywallFooterScreen.kt$PaywallFooterScreen</ID>
<ID>ModifierMissing:PaywallScreen.kt$PaywallScreen</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.PurchasesErrorCode
import com.revenuecat.purchases.ui.revenuecatui.OriginalTemplatePaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialogOptions
import com.revenuecat.purchases.ui.revenuecatui.PaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions
import com.revenuecat.purchases.ui.revenuecatui.PurchaseLogic
import com.revenuecat.purchases.ui.revenuecatui.PurchaseLogicResult
Expand Down Expand Up @@ -209,7 +209,7 @@ private fun FooterDialog(currentState: DisplayPaywallState.Footer, onDismiss: ()
) {
Scaffold { scaffoldPadding ->
Box(modifier = Modifier.padding(scaffoldPadding)) {
PaywallFooter(
OriginalTemplatePaywallFooter(
options = PaywallOptions.Builder(dismissRequest = onDismiss)
.setOffering(currentState.offering)
.setPurchaseLogic(currentState.purchaseLogic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.revenuecat.paywallstester.ui.screens.paywall.PaywallScreenState
import com.revenuecat.paywallstester.ui.screens.paywall.PaywallScreenViewModel
import com.revenuecat.paywallstester.ui.screens.paywall.PaywallScreenViewModelImpl
import com.revenuecat.purchases.ui.revenuecatui.PaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.OriginalTemplatePaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions

@Composable
Expand All @@ -40,7 +40,7 @@ fun PaywallFooterScreen(
Text(text = "Error: ${state.errorMessage}")
}
is PaywallScreenState.Loaded -> {
PaywallFooter(
OriginalTemplatePaywallFooter(
options = PaywallOptions.Builder(dismissRequest)
.setOffering(state.offering)
.setListener(viewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:layout_height="wrap_content"/>
</LinearLayout>

<com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView
<com.revenuecat.purchases.ui.revenuecatui.views.OriginalTemplatePaywallFooterView
android:id="@+id/paywall_footer_view"
android:layout_marginTop="-20dp"
android:fontFamily="@font/lobster_two"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,45 @@ import androidx.compose.ui.Modifier
/**
* Composable offering a minified screen Paywall UI configured from the RevenueCat dashboard.
* You can pass in your own Composables to be displayed in the main content area.
* Only compatible with original Paywalls. If using V2 Paywalls, this will display a fallback paywall instead.
*
* @param options The options to configure the [Paywall] if needed.
* @param condensed Whether to condense the composable even more.
* @param mainContent The content to display in the main area of the [Paywall]. We give a [PaddingValues] so you can
* add that padding to your own content. This padding corresponds to the height of the rounded corner area of
* the paywall.
*/
@Deprecated(
"Use OriginalTemplatePaywallFooter instead",
ReplaceWith(
"OriginalTemplatePaywallFooter(options, condensed, mainContent)",
),
)
@Composable
fun PaywallFooter(
options: PaywallOptions,
condensed: Boolean = false,
mainContent: @Composable ((PaddingValues) -> Unit)? = null,
) {
OriginalTemplatePaywallFooter(options, condensed, mainContent)
}

/**
* Composable offering a minified screen Paywall UI configured from the RevenueCat dashboard.
* You can pass in your own Composables to be displayed in the main content area.
* Only compatible with original Paywalls. If using V2 Paywalls, this will display a fallback paywall instead.
*
* @param options The options to configure the [Paywall] if needed.
* @param condensed Whether to condense the composable even more.
* @param mainContent The content to display in the main area of the [Paywall]. We give a [PaddingValues] so you can
* add that padding to your own content. This padding corresponds to the height of the rounded corner area of
* the paywall.
*/
@Composable
fun OriginalTemplatePaywallFooter(
options: PaywallOptions,
condensed: Boolean = false,
mainContent: @Composable ((PaddingValues) -> Unit)? = null,
) {
val paywallComposable = @Composable {
Paywall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,17 @@ data class PaywallOptions internal constructor(

/**
* Sets whether to display a close button on the paywall screen. Only available when using
* [Paywall]. Ignored when using [PaywallFooter]. Defaults to false.
* [Paywall] and original template paywalls. Ignored when using [OriginalTemplatePaywallFooter] or
* using V2 Paywalls. Defaults to false.
*/
fun setShouldDisplayDismissButton(shouldDisplayDismissButton: Boolean) = apply {
this.shouldDisplayDismissButton = shouldDisplayDismissButton
}

/**
* Sets a font provider to provide the paywall with your custom fonts.
* Only available for original template paywalls. Ignored for V2 Paywalls.
*/
fun setFontProvider(fontProvider: FontProvider?) = apply {
this.fontProvider = fontProvider
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class PaywallActivityLauncher(resultCaller: ActivityResultCaller, resultHandler:
* Launch the paywall activity.
* @param offering The offering to be shown in the paywall. If null, the current offering will be shown.
* @param fontProvider The [ParcelizableFontProvider] to be used in the paywall. If null, the default fonts
* will be used.
* will be used. Only available for original template paywalls. Ignored for V2 Paywalls.
* @param shouldDisplayDismissButton Whether to display the dismiss button in the paywall.
* Only available for original template paywalls. Ignored for V2 Paywalls.
*/
@JvmOverloads
fun launch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,45 @@ import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.ui.revenuecatui.OfferingSelection
import com.revenuecat.purchases.ui.revenuecatui.PaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.OriginalTemplatePaywallFooter
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions
import com.revenuecat.purchases.ui.revenuecatui.R
import com.revenuecat.purchases.ui.revenuecatui.fonts.FontProvider

/**
* View that wraps the [PaywallFooter] Composable to display the Paywall Footer through XML layouts and the View system.
* View that wraps the [OriginalTemplatePaywallFooter] Composable to display the Paywall Footer
* through XML layouts and the View system.
*/
open class PaywallFooterView : FrameLayout {
@Deprecated(
"Use OriginalTemplatePaywallFooterView instead",
ReplaceWith(
"OriginalTemplatePaywallFooterView",
),
)
open class PaywallFooterView(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int,
) : OriginalTemplatePaywallFooterView(context, attrs, defStyleAttr) {
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

@JvmOverloads
constructor(
context: Context,
offering: Offering? = null,
listener: PaywallListener? = null,
fontProvider: FontProvider? = null,
condensed: Boolean = PaywallViewAttributesReader.DEFAULT_CONDENSED,
dismissHandler: (() -> Unit)? = null,
) : this(context, attrs = null)
}

/**
* View that wraps the [OriginalTemplatePaywallFooter] Composable to display the Paywall Footer
* through XML layouts and the View system.
*/
open class OriginalTemplatePaywallFooterView : FrameLayout {

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init(context, attrs)
Expand Down Expand Up @@ -112,6 +141,7 @@ open class PaywallFooterView : FrameLayout {

/**
* Sets the font provider to be used for the Paywall. If not set, the default one will be used.
* Only available for original template paywalls. Ignored for V2 Paywalls.
*/
fun setFontProvider(fontProvider: FontProvider?) {
paywallOptions = paywallOptions.copy(fontProvider = fontProvider)
Expand All @@ -130,7 +160,7 @@ open class PaywallFooterView : FrameLayout {
val paywallOptions by remember {
paywallOptionsState
}
PaywallFooter(
OriginalTemplatePaywallFooter(
options = paywallOptions,
condensed = initialCondensed,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ class PaywallView : AbstractComposeView {

/**
* Sets the font provider to be used for the Paywall. If not set, the default one will be used.
* Only available for original template paywalls. Ignored for V2 Paywalls.
*/
fun setFontProvider(fontProvider: FontProvider?) {
paywallOptions = paywallOptions.copy(fontProvider = fontProvider)
}

/**
* Sets the visibility of the dismiss button in the Paywall.
* Only available for original template paywalls. Ignored for V2 Paywalls.
*/
fun setDisplayDismissButton(shouldDisplayDismissButton: Boolean) {
paywallOptions = paywallOptions.copy(shouldDisplayDismissButton = shouldDisplayDismissButton)
Expand Down

0 comments on commit 19259bf

Please sign in to comment.