Most of the time you’ll want to use presentUpsell() to show paywalls. This approach is covered in each platform’s quickstart guide (see navigation menu on the left). But if you need more control over how and where paywalls appear in your app, there are a few other options.
You’ll need to handle loading states, fallback scenarios, and dismissal logic yourself with these methods. We recommend sticking with presentUpsell() unless you have a specific reason to use these alternatives.
Get the paywall view directly and embed it in your own SwiftUI view hierarchy using Helium.shared.upsellViewForTrigger:
Copy
Ask AI
let heliumView: AnyView? = Helium.shared.upsellViewForTrigger( trigger: "post_onboarding")
You’ll need to handle presentation and dismissal yourself when using this method. You can handle user dismissal with PaywallEventHandlers.
Example with PaywallEventHandlers
Copy
Ask AI
Helium.shared.upsellViewForTrigger( trigger: "post_onboarding", eventHandlers: PaywallEventHandlers() .onOpen { event in print("open for trigger \(event.triggerName)") } .onClose { event in print("close for trigger \(event.triggerName)") } .onDismissed { event in // handle user dismissal here (i.e. hide the upsell view) print("dismiss for trigger \(event.triggerName)") } .onPurchaseSucceeded { event in print("purchase made for trigger \(event.triggerName)") } .onCustomPaywallAction { event in print("Custom action: \(event.actionName) with params: \(event.params)") })
Create an Intent using the createPaywallIntent helper function. This function configures and returns an Intent that can be used to launch the HeliumPaywallActivity.Here are the available options for createPaywallIntent:
context: The Android Context required to create the intent. Use this in an Activity or LocalContext.current in a Composable.
trigger: The specific paywall trigger you want to display. This is a required parameter.
fullscreen: A Boolean to determine if the paywall should be displayed in fullscreen immersive mode, where the system bars (status and navigation) are hidden. This is optional and defaults to false.
disableSystemBackNavigation: A Boolean to control the system back button behavior. If true, the back button will not close the paywall. This is optional and defaults to true.
Copy
Ask AI
// Create the intent to launch the paywallval heliumIntent = createPaywallIntent( context = this, trigger = "sdk_test")
Once you have your intent, you can launch it using either Jetpack Compose or the Android View System:
Jetpack Compose
Android View System
With Compose you can start the HeliumPaywallActivity using rememberLauncherForActivityResult. This approach allows you to receive a result back from the paywall, such as whether a purchase was successful.Here is an example of how to set it up in your Composable function:
You can use HeliumPaywallFragment to display a paywall within a fragment container.Use the HeliumPaywallFragment.newInstance() method to create an instance of the fragment with your desired trigger. Then, use the FragmentManager to add it to your view hierarchy.
Copy
Ask AI
// To launch your paywall from an Activity or another Fragmentval fragment = HeliumPaywallFragment.newInstance("sdk_test")if (fragment != null) { supportFragmentManager.beginTransaction() .replace(R.id.fragment_container, fragment) .addToBackStack(null) .commit()}
The newInstance function will return null if the paywall is configured not to show for the current user. You should handle this case by not attempting to show the fragment.