-
Notifications
You must be signed in to change notification settings - Fork 50
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: Update paywall tester to be able to display paywall footer #1315
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.revenuecat.paywallstester.ui.screens.paywallfooter | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.material.AlertDialog | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
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.PaywallViewOptions | ||
|
||
@Composable | ||
fun PaywallFooterScreen( | ||
viewModel: PaywallScreenViewModel = viewModel<PaywallScreenViewModelImpl>(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm reusing the same view model as the full screen one. No need to create a separate view model. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup 👍🏻 |
||
) { | ||
Column( | ||
modifier = Modifier.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
verticalArrangement = Arrangement.Center, | ||
) { | ||
when (val state = viewModel.state.collectAsState().value) { | ||
is PaywallScreenState.Loading -> { | ||
Text(text = "Loading...") | ||
} | ||
is PaywallScreenState.Error -> { | ||
Text(text = "Error: ${state.errorMessage}") | ||
} | ||
is PaywallScreenState.Loaded -> { | ||
PaywallFooter( | ||
options = PaywallViewOptions.Builder() | ||
.setOffering(state.offering) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait hmmm does this mean that in order to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, this setter is optional. If you don't set it, we will load the |
||
.setListener(viewModel) | ||
.build(), | ||
) { | ||
SamplePaywall(paddingValues = it) | ||
} | ||
state.dialogText?.let { | ||
PurchaseAlertDialog(viewModel, it) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Suppress("MagicNumber") | ||
@Composable | ||
private fun SamplePaywall(paddingValues: PaddingValues) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.verticalScroll(rememberScrollState()) | ||
.padding(paddingValues), | ||
) { | ||
// TODO-Paywalls: Implement an actual sample paywall | ||
for (i in 1..50) { | ||
Text(text = "Main content $i") | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun PurchaseAlertDialog( | ||
viewModel: PaywallScreenViewModel, | ||
text: String, | ||
) { | ||
AlertDialog( | ||
onDismissRequest = { | ||
viewModel.onDialogDismissed() | ||
}, | ||
buttons = { | ||
TextButton( | ||
onClick = { | ||
viewModel.onDialogDismissed() | ||
}, | ||
) { | ||
Text("Ok") | ||
} | ||
}, | ||
text = { | ||
Text(text) | ||
}, | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I've made showing the paywall as a footer a top level destination in the navhost, same as the normal navigation one. We might want to think about adding another composable to display the PaywallFooter as a dialog, but that can come later.