Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paywalls: Rename PaywallView to Paywall #1351

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ import com.revenuecat.purchases.Offerings
import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialogOptions
import com.revenuecat.purchases.ui.revenuecatui.PaywallViewListener
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
@@ -126,7 +126,7 @@ private fun OfferingsListScreen(
},
)
.setOffering(displayPaywallDialogOffering)
.setListener(object : PaywallViewListener {
.setListener(object : PaywallListener {
override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {
displayPaywallDialogOffering = null
}
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ import com.revenuecat.purchases.Offering
import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialog
import com.revenuecat.purchases.ui.revenuecatui.PaywallDialogOptions
import com.revenuecat.purchases.ui.revenuecatui.PaywallViewListener
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener

@Composable
fun PaywallsScreen(
@@ -80,7 +80,7 @@ fun PaywallsScreen(
},
)
.setOffering(displayPaywallDialogOffering)
.setListener(object : PaywallViewListener {
.setListener(object : PaywallListener {
override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {
displayPaywallDialogOffering = null
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.revenuecat.purchases.ui.revenuecatui.PaywallView
import com.revenuecat.purchases.ui.revenuecatui.PaywallViewOptions
import com.revenuecat.purchases.ui.revenuecatui.Paywall
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions

@Composable
fun PaywallScreen(
@@ -31,8 +31,8 @@ fun PaywallScreen(
Text(text = "Error: ${state.errorMessage}")
}
is PaywallScreenState.Loaded -> {
PaywallView(
PaywallViewOptions.Builder()
Paywall(
PaywallOptions.Builder()
.setOffering(state.offering)
.setListener(viewModel)
.build(),
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@ import com.revenuecat.purchases.PurchasesErrorCode
import com.revenuecat.purchases.PurchasesException
import com.revenuecat.purchases.awaitOfferings
import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.ui.revenuecatui.PaywallViewListener
import com.revenuecat.purchases.ui.revenuecatui.PaywallListener
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

interface PaywallScreenViewModel : PaywallViewListener {
interface PaywallScreenViewModel : PaywallListener {
companion object {
const val OFFERING_ID_KEY = "offering_id"
}
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ 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.PaywallViewOptions
import com.revenuecat.purchases.ui.revenuecatui.PaywallOptions

@Composable
fun PaywallFooterScreen(
@@ -40,7 +40,7 @@ fun PaywallFooterScreen(
}
is PaywallScreenState.Loaded -> {
PaywallFooter(
options = PaywallViewOptions.Builder()
options = PaywallOptions.Builder()
.setOffering(state.offering)
.setListener(viewModel)
.build(),
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.viewmodel.compose.viewModel
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallState
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModelFactory
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModelImpl
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewState
import com.revenuecat.purchases.ui.revenuecatui.data.isInFullScreenMode
import com.revenuecat.purchases.ui.revenuecatui.data.processed.PaywallTemplate
import com.revenuecat.purchases.ui.revenuecatui.extensions.conditional
@@ -26,29 +26,29 @@ import com.revenuecat.purchases.ui.revenuecatui.templates.Template2
import com.revenuecat.purchases.ui.revenuecatui.templates.Template3

@Composable
internal fun InternalPaywallView(
options: PaywallViewOptions,
internal fun InternalPaywall(
options: PaywallOptions,
viewModel: PaywallViewModel = getPaywallViewModel(options),
) {
viewModel.refreshStateIfLocaleChanged()
val colors = MaterialTheme.colorScheme
viewModel.refreshStateIfColorsChanged(colors)

when (val state = viewModel.state.collectAsState().value) {
is PaywallViewState.Loading -> {
LoadingPaywallView(mode = options.mode)
is PaywallState.Loading -> {
LoadingPaywall(mode = options.mode)
}
is PaywallViewState.Error -> {
is PaywallState.Error -> {
Text(text = "Error: ${state.errorMessage}")
}
is PaywallViewState.Loaded -> {
LoadedPaywallView(state = state, viewModel = viewModel)
is PaywallState.Loaded -> {
LoadedPaywall(state = state, viewModel = viewModel)
}
}
}

@Composable
private fun LoadedPaywallView(state: PaywallViewState.Loaded, viewModel: PaywallViewModel) {
private fun LoadedPaywall(state: PaywallState.Loaded, viewModel: PaywallViewModel) {
val backgroundColor = state.templateConfiguration.getCurrentColors().background
Box(
modifier = Modifier
@@ -67,12 +67,12 @@ private fun LoadedPaywallView(state: PaywallViewState.Loaded, viewModel: Paywall
.padding(top = UIConstant.footerRoundedBorderHeight)
},
) {
TemplatePaywallView(state = state, viewModel = viewModel)
TemplatePaywall(state = state, viewModel = viewModel)
}
}

@Composable
private fun TemplatePaywallView(state: PaywallViewState.Loaded, viewModel: PaywallViewModel) {
private fun TemplatePaywall(state: PaywallState.Loaded, viewModel: PaywallViewModel) {
when (state.templateConfiguration.template) {
PaywallTemplate.TEMPLATE_1 -> Template1(state = state, viewModel = viewModel)
PaywallTemplate.TEMPLATE_2 -> Template2(state = state, viewModel = viewModel)
@@ -84,7 +84,7 @@ private fun TemplatePaywallView(state: PaywallViewState.Loaded, viewModel: Paywa

@Composable
private fun getPaywallViewModel(
options: PaywallViewOptions,
options: PaywallOptions,
): PaywallViewModel {
val applicationContext = LocalContext.current.applicationContext
return viewModel<PaywallViewModelImpl>(
Original file line number Diff line number Diff line change
@@ -22,23 +22,23 @@ import com.revenuecat.purchases.ui.revenuecatui.composables.DisableTouchesCompos
import com.revenuecat.purchases.ui.revenuecatui.composables.Fade
import com.revenuecat.purchases.ui.revenuecatui.composables.PlaceholderDefaults
import com.revenuecat.purchases.ui.revenuecatui.composables.placeholder
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallState
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewState
import com.revenuecat.purchases.ui.revenuecatui.data.processed.PaywallTemplate
import com.revenuecat.purchases.ui.revenuecatui.data.processed.TemplateConfiguration
import com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableDataProvider
import com.revenuecat.purchases.ui.revenuecatui.extensions.createDefault
import com.revenuecat.purchases.ui.revenuecatui.helpers.isInPreviewMode
import com.revenuecat.purchases.ui.revenuecatui.helpers.toAndroidContext
import com.revenuecat.purchases.ui.revenuecatui.helpers.toPaywallViewState
import com.revenuecat.purchases.ui.revenuecatui.helpers.toPaywallState
import com.revenuecat.purchases.ui.revenuecatui.templates.Template2
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import java.net.URL

@Composable
internal fun LoadingPaywallView(mode: PaywallViewMode) {
internal fun LoadingPaywall(mode: PaywallMode) {
val paywallData: PaywallData = PaywallData.createDefault(
LoadingPaywallConstants.packages,
MaterialTheme.colorScheme,
@@ -52,7 +52,7 @@ internal fun LoadingPaywallView(mode: PaywallViewMode) {
paywall = paywallData,
)

val state = offering.toPaywallViewState(
val state = offering.toPaywallState(
VariableDataProvider(
LocalContext.current.applicationContext.toAndroidContext(),
isInPreviewMode(),
@@ -66,16 +66,16 @@ internal fun LoadingPaywallView(mode: PaywallViewMode) {
when (state) {
// The loading PaywallData is known at compile time
// and snapshots ensure that these 2 states are impossible.
is PaywallViewState.Error,
is PaywallViewState.Loading,
is PaywallState.Error,
is PaywallState.Loading,
-> Box {}

is PaywallViewState.Loaded -> LoadingPaywallView(state, LoadingViewModel(state))
is PaywallState.Loaded -> LoadingPaywall(state, LoadingViewModel(state))
}
}

@Composable
private fun LoadingPaywallView(state: PaywallViewState.Loaded, viewModel: PaywallViewModel) {
private fun LoadingPaywall(state: PaywallState.Loaded, viewModel: PaywallViewModel) {
DisableTouchesComposable {
// Template
Template2(
@@ -142,9 +142,9 @@ private object LoadingPaywallConstants {
}

private class LoadingViewModel(
state: PaywallViewState,
state: PaywallState,
) : PaywallViewModel {
override val state: StateFlow<PaywallViewState>
override val state: StateFlow<PaywallState>
get() = _state.asStateFlow()

override val actionInProgress: State<Boolean> = mutableStateOf(false)
@@ -173,6 +173,6 @@ private class LoadingViewModel(

@Preview(showBackground = true)
@Composable
internal fun LoadingPaywallViewPreview() {
LoadingPaywallView(mode = PaywallViewMode.FULL_SCREEN)
internal fun LoadingPaywallPreview() {
LoadingPaywall(mode = PaywallMode.FULL_SCREEN)
}
Original file line number Diff line number Diff line change
@@ -4,12 +4,12 @@ import androidx.compose.runtime.Composable

/**
* Composable offering a full screen Paywall UI configured from the RevenueCat dashboard.
* @param options The options to configure the PaywallView if needed.
* @param options The options to configure the [Paywall] if needed.
*/
@Suppress("unused")
@Composable
fun PaywallView(
options: PaywallViewOptions = PaywallViewOptions.Builder().build(),
fun Paywall(
options: PaywallOptions = PaywallOptions.Builder().build(),
) {
InternalPaywallView(options)
InternalPaywall(options)
}
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ private fun DialogScaffold(paywallDialogOptions: PaywallDialogOptions) {
.fillMaxSize()
.padding(paddingValues),
) {
PaywallView(paywallDialogOptions.toPaywallViewOptions())
Paywall(paywallDialogOptions.toPaywallOptions())
}
}
}
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class PaywallDialogOptions(builder: Builder) {
val shouldDisplayBlock: ((CustomerInfo) -> Boolean)?
val offering: Offering?
val shouldDisplayDismissButton: Boolean
val listener: PaywallViewListener?
val listener: PaywallListener?

init {
this.shouldDisplayBlock = builder.shouldDisplayBlock
@@ -20,8 +20,8 @@ class PaywallDialogOptions(builder: Builder) {
this.listener = builder.listener
}

fun toPaywallViewOptions(): PaywallViewOptions {
return PaywallViewOptions.Builder()
fun toPaywallOptions(): PaywallOptions {
return PaywallOptions.Builder()
.setOffering(offering)
.setShouldDisplayDismissButton(shouldDisplayDismissButton)
.setListener(listener)
@@ -34,7 +34,7 @@ class PaywallDialogOptions(builder: Builder) {
internal var shouldDisplayBlock: ((CustomerInfo) -> Boolean)? = null
internal var offering: Offering? = null
internal var shouldDisplayDismissButton: Boolean = true
internal var listener: PaywallViewListener? = null
internal var listener: PaywallListener? = null

/**
* Allows to configure whether to display the paywall dialog depending on operations on the CustomerInfo
@@ -60,7 +60,7 @@ class PaywallDialogOptions(builder: Builder) {
this.shouldDisplayDismissButton = shouldDisplayDismissButton
}

fun setListener(listener: PaywallViewListener?) = apply {
fun setListener(listener: PaywallListener?) = apply {
this.listener = listener
}

Original file line number Diff line number Diff line change
@@ -18,15 +18,15 @@ import androidx.compose.ui.tooling.preview.Preview
* 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.
*
* @param options The options to configure the PaywallView if needed.
* @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 PaywallView. We give a [PaddingValues] so you can
* @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 PaywallFooter(
options: PaywallViewOptions = PaywallViewOptions.Builder().build(),
options: PaywallOptions = PaywallOptions.Builder().build(),
condensed: Boolean = false,
mainContent: @Composable (PaddingValues) -> Unit,
) {
@@ -43,8 +43,8 @@ fun PaywallFooter(
) {
mainContent(PaddingValues(bottom = UIConstant.footerRoundedBorderHeight))
}
options.mode = PaywallViewMode.footerMode(condensed)
PaywallView(options)
options.mode = PaywallMode.footerMode(condensed)
Paywall(options)
}
}

Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.models.StoreTransaction

interface PaywallViewListener {
interface PaywallListener {
fun onPurchaseStarted(rcPackage: Package) {}
fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {}
fun onPurchaseError(error: PurchasesError) {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.revenuecat.purchases.ui.revenuecatui

internal enum class PaywallViewMode {
internal enum class PaywallMode {
FULL_SCREEN,
FOOTER,
FOOTER_CONDENSED,
@@ -9,7 +9,7 @@ internal enum class PaywallViewMode {
companion object {
val default = FULL_SCREEN

fun footerMode(condensed: Boolean): PaywallViewMode {
fun footerMode(condensed: Boolean): PaywallMode {
return if (condensed) FOOTER_CONDENSED else FOOTER
}
}
Loading