-
Notifications
You must be signed in to change notification settings - Fork 3
Paywalls
: updated Android docs with new dismissRequest
parameters
#450
Conversation
paywallActivityLauncher.launch() | ||
} | ||
} | ||
paywallActivityLauncher.launchIfNeeded(requiredEntitlementIdentifier = Constants.ENTITLEMENT_ID) |
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.
Updated this to use the much nicer API.
PreviewsSee contentsDisplaying PaywallsiOSHow to display a fullscreen Paywall in your appRevenueCat Paywalls will, by default, show paywalls fullscreen and there are multiple ways to do this with SwiftUI and UIKit.
import SwiftUI
import RevenueCat
import RevenueCatUI
struct App: View {
var body: some View {
ContentView()
.presentPaywallIfNeeded(
requiredEntitlementIdentifier: "pro",
purchaseCompleted: { customerInfo in
print("Purchase completed: \(customerInfo.entitlements)")
},
restoreCompleted: { customerInfo in
// Paywall will be dismissed automatically if "pro" is now active.
print("Purchases restored: \(customerInfo.entitlements)")
}
)
}
} import SwiftUI
import RevenueCat
import RevenueCatUI
struct App: View {
var body: some View {
ContentView()
.presentPaywallIfNeeded { customerInfo in
// Returning `true` will present the paywall
return customerInfo.entitlements.active.keys.contains("pro")
} purchaseCompleted: { customerInfo in
print("Purchase completed: \(customerInfo.entitlements)")
} restoreCompleted: {
// Paywall will be dismissed automatically if "pro" is now active.
print("Purchases restored: \(customerInfo.entitlements)")
}
}
} import SwiftUI
import RevenueCat
import RevenueCatUI
struct App: View {
@State
var displayPaywall = false
var body: some View {
ContentView()
.sheet(isPresented: self.$displayPaywall) {
PaywallView()
// PaywallView does not have a close button
// Manually add one to match your app's style
.toolbar {
ToolbarItem(placement: .destructiveAction) {
Button {
self.displayPaywall = false
} label: {
Image(systemName: "xmark")
}
}
}
}
}
} import UIKit
import RevenueCat
import RevenueCatUI
class ViewController: UIViewController {
@IBAction func presentPaywall() {
let controller = PaywallViewController()
controller.delegate = self
present(controller, animated: true, completion: nil)
}
}
extension ViewController: PaywallViewControllerDelegate {
func paywallViewController(_ controller: PaywallViewController,
didFinishPurchasingWith customerInfo: CustomerInfo) {
}
} Close ButtonPaywalls displayed with How to display a footer Paywall on your custom paywallRevenueCatUI also has a paywall variation that can be displayed as a footer below your custom paywall. This allows you to design your paywall exactly as you want with native components while still using RevenueCat UI to handle it. This is done by adding the The footer paywall mainly consists of the following:
This is all remotely configured and RevenueCatUI handles all the intro offer eligibility and purchase logic. import SwiftUI
import RevenueCat
import RevenueCatUI
struct YourPaywall: View {
var body: some View {
ScrollView {
// Your custom paywall design content
}
.paywallFooter()
}
} import SwiftUI
import RevenueCat
import RevenueCatUI
struct YourPaywall: View {
let offering: Offering
var body: some View {
ScrollView {
// Your custom paywall design content
}
.paywallFooter(offering: offering, condensed: true) { customerInfo in
// Purchase completed! Thank your user and dismiss your paywall
}
}
} How to use custom fontsPaywalls can be configured to use the same font as your app using a By default, a paywall will use the We also offer a If you need more control over your font preferences, you can create your own import SwiftUI
import RevenueCat
import RevenueCatUI
struct App: View {
var body: some View {
ContentView()
.presentPaywallIfNeeded(
fonts: CustomPaywallFontProvider(fontName: "Arial")
) { customerInfo in
// Returning `true` will present the paywall
return customerInfo.entitlements.active.keys.contains("pro")
}
}
} import SwiftUI
import RevenueCat
import RevenueCatUI
struct App: View {
var body: some View {
ContentView()
.presentPaywallIfNeeded(
fonts: RoundedSystemFontProvider()
) { customerInfo in
// Returning `true` will present the paywall
return customerInfo.entitlements.active.keys.contains("pro")
}
}
}
class RoundedSystemFontProvider: PaywallFontProvider {
func font(for textStyle: Font.TextStyle) -> Font {
return Font.system(textStyle, design: .rounded)
}
} Android (Beta)How to display a fullscreen Paywall in your appRevenueCat Paywalls will, by default, show paywalls fullscreen and there are multiple ways to do this with
@Composable
private fun LockedScreen() {
YourContent()
PaywallDialog(
PaywallDialogOptions.Builder()
.setRequiredEntitlementIdentifier(Constants.ENTITLEMENT_ID)
.setListener(
object : PaywallListener {
override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {}
override fun onRestoreCompleted(customerInfo: CustomerInfo) {}
}
)
.build()
)
} @Composable
private fun NavGraph(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = Screen.Main.route,
) {
composable(route = Screen.Main.route) {
MainScreen()
PaywallDialog(
PaywallDialogOptions.Builder()
.setShouldDisplayBlock { !it.entitlements.active.isEmpty() }
.setListener(
object : PaywallListener {
override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {}
override fun onRestoreCompleted(customerInfo: CustomerInfo) {}
}
)
.build()
)
}
}
} @Composable
private fun NavGraph(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = Screen.Main.route,
) {
composable(route = Screen.Main.route) {
MainScreen()
}
composable(route = Screen.Paywall.route) {
Paywall(
options = PaywallOptions.Builder(
onDismiss = { navController.popBackStack() }
)
.setListener(
object : PaywallListener {
override fun onPurchaseCompleted(customerInfo: CustomerInfo, storeTransaction: StoreTransaction) {}
override fun onRestoreCompleted(customerInfo: CustomerInfo) {}
}
)
.build()
)
}
}
} class MainActivity : AppCompatActivity(), PaywallResultHandler {
private lateinit var paywallActivityLauncher: PaywallActivityLauncher
private lateinit var root: View
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
paywallActivityLauncher = PaywallActivityLauncher(this, this)
}
private fun performMagic() {
paywallActivityLauncher.launchIfNeeded(requiredEntitlementIdentifier = Constants.ENTITLEMENT_ID)
}
override fun onActivityResult(result: PaywallResult) {}
} How to display a footer Paywall on your custom paywallRevenueCatUI also has a paywall variation that can be displayed as a footer below your custom paywall. This allows you to design your paywall exactly as you want with native components while still using RevenueCat UI to handle it. The footer paywall mainly consists of the following:
This is all remotely configured and RevenueCatUI handles all the intro offer eligibility and purchase logic. @Composable
private fun PaywallScreen(dismissRequest: () -> Unit) {
PaywallFooter(
options = PaywallOptions.Builder(dismissRequest).build()
) {
CustomPaywallContent()
}
} @Composable
private fun PaywallScreen(offering: Offering, dismissRequest: () -> Unit) {
PaywallFooter(
options = PaywallOptions.Builder(
options = PaywallOptions.Builder(dismissRequest).build()
)
.setOffering(offering)
.build()
) {
CustomPaywallContent()
}
} How to use custom fontsPaywalls can be configured to use the same font as your app using a By default, a paywall will not use a font provider. This uses the current Material3 theme's Typography by default. We offer a If you need more control over your font preferences, you can create your own @Composable
fun MyComposable() {
PaywallDialog(
PaywallDialogOptions.Builder { /* on dismiss */ }
.setFontProvider(CustomFontProvider(myFontFamily))
.build()
)
} @Composable
fun MyComposable() {
PaywallDialog(
PaywallDialogOptions.Builder { /* on dismiss */ }
.setFontProvider(object : FontProvider {
override fun getFont(type: TypographyType): FontFamily? {
return when (type) {
TypographyType.HEADLINE_LARGE -> headlineFontFamily
TypographyType.BODY_LARGE -> bodyFontFamily
else -> null // Will use default font
}
}
})
.build()
)
} class MyActivity : ComponentActivity(), PaywallResultHandler {
private lateinit var paywallActivityLauncher: PaywallActivityLauncher
private val fontFamily = PaywallFontFamily(
fonts = listOf(
PaywallFont.ResourceFont(R.font.my_font)
)
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
paywallActivityLauncher = PaywallActivityLauncher(this, this)
}
fun launchPaywall(offering: Offering? = null) {
paywallActivityLauncher.launch(
offering,
CustomParcelizableFontProvider(fontFamily)
)
}
} class MyActivity : ComponentActivity(), PaywallResultHandler {
private lateinit var paywallActivityLauncher: PaywallActivityLauncher
private val googleFontProvider = GoogleFontProvider(R.array.com_google_android_gms_fonts_certs)
private val fontFamily = PaywallFontFamily(
fonts = listOf(
PaywallFont.GoogleFont("GOOGLE_FONT_NAME", googleFontProvider)
)
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
paywallActivityLauncher = PaywallActivityLauncher(this, this)
}
fun launchPaywall(offering: Offering? = null) {
paywallActivityLauncher.launch(
offering,
CustomParcelizableFontProvider(fontFamily)
)
}
} Default PaywallIf you attempt to display a Paywall for an Offering that doesn't have one configured, the RevenueCatUI SDK will display a default Paywall. On iOS it uses the app's |
#1386) `PaywallDialog` works by presenting paywalls automatically based on a provided condition. Because of this, it should also know how to dismiss itself. I changed it to implement this automatically, but also provide a way to optionally pass a block for it. Also updated the docs to reflect the new APIs: RevenueCat/revenuecat-docs#450
#1386) `PaywallDialog` works by presenting paywalls automatically based on a provided condition. Because of this, it should also know how to dismiss itself. I changed it to implement this automatically, but also provide a way to optionally pass a block for it. Also updated the docs to reflect the new APIs: RevenueCat/revenuecat-docs#450
No description provided.