Present onboardings in React Native SDK
If you've customized an onboarding using the builder, you don't need to worry about rendering it in your mobile app code to display it to the user. Such an onboarding contains both what should be shown within the onboarding and how it should be shown.
Before you start, ensure that:
- You have installed Adapty React Native SDK 3.8.0 or later.
- You have created an onboarding.
- You have added the onboarding to a placement.
Adapty React Native SDK provides two ways to present onboardings:
-
React component: Embedded component allows you to integrate it into your app's architecture and navigation system.
-
Modal presentation
React component
To embed an onboarding within your existing component tree, use the AdaptyOnboardingView component directly in your React Native component hierarchy. Embedded component allows you to integrate it into your app's architecture and navigation system.
- SDK version 3.14 or later
- SDK version < 3.14
import React, { useCallback } from 'react';
import { AdaptyOnboardingView } from 'react-native-adapty';
import type { OnboardingEventHandlers } from 'react-native-adapty';
function MyOnboarding({ onboarding }) {
const onAnalytics = useCallback<OnboardingEventHandlers['onAnalytics']>((event, meta) => {}, []);
const onClose = useCallback<OnboardingEventHandlers['onClose']>((actionId, meta) => {}, []);
const onCustom = useCallback<OnboardingEventHandlers['onCustom']>((actionId, meta) => {}, []);
const onPaywall = useCallback<OnboardingEventHandlers['onPaywall']>((actionId, meta) => {}, []);
const onStateUpdated = useCallback<OnboardingEventHandlers['onStateUpdated']>((action, meta) => {}, []);
const onFinishedLoading = useCallback<OnboardingEventHandlers['onFinishedLoading']>((meta) => {}, []);
const onError = useCallback<OnboardingEventHandlers['onError']>((error) => {}, []);
return (
<AdaptyOnboardingView
onboarding={onboarding}
style={styles.container}
onAnalytics={onAnalytics}
onClose={onClose}
onCustom={onCustom}
onPaywall={onPaywall}
onStateUpdated={onStateUpdated}
onFinishedLoading={onFinishedLoading}
onError={onError}
/>
);
}
import React from 'react';
import { AdaptyOnboardingView } from 'react-native-adapty';
function MyOnboarding({ onboarding }) {
return (
<AdaptyOnboardingView
onboarding={onboarding}
style={{ flex: 1 }}
eventHandlers={{
onAnalytics(event, meta) {
// Handle analytics events
},
onClose(actionId, meta) {
// Handle close actions
},
onCustom(actionId, meta) {
// Handle custom actions
},
onPaywall(actionId, meta) {
// Handle paywall actions
},
onStateUpdated(action, meta) {
// Handle state updates
},
onFinishedLoading(meta) {
// Handle when onboarding finishes loading
},
onError(error) {
// Handle errors
},
}}
/>
);
}
Modal presentation
To display an onboarding as a standalone screen that users can dismiss, use the view.present() method on the view created by the createOnboardingView method. Each view can only be used once. If you need to display the onboarding again, call createOnboardingView one more time to create a new view instance.
Reusing the same view without recreating it is forbidden. It will result in an AdaptyUIError.viewAlreadyPresented error.
- SDK version 3.14 or later
- SDK version < 3.14
import { createOnboardingView } from 'react-native-adapty';
const view = await createOnboardingView(onboarding);
// Optional: handle onboarding events (close, custom actions, etc)
// view.setEventHandlers({ ... });
try {
await view.present();
} catch (error) {
// handle the error
}
import { createOnboardingView } from 'react-native-adapty/dist/ui';
const view = await createOnboardingView(onboarding);
view.registerEventHandlers(); // handle close press, etc
try {
await view.present();
} catch (error) {
// handle the error
}
Configure iOS presentation style
Configure how the paywall is presented on iOS by passing the iosPresentationStyle parameter to the present() method. The parameter accepts 'full_screen' (default) or 'page_sheet' values.
try {
await view.present(iosPresentationStyle: 'page_sheet');
} catch (error) {
// handle the error
}
Customize how links open in onboardings
Customizing how links open in onboardings is supported starting from Adapty SDK v. 3.15.1.
By default, links in onboardings open in an in-app browser. This provides a seamless user experience by displaying web pages within your application, allowing users to view them without switching apps.
If you prefer to open links in an external browser instead, you can customize this behavior by setting the externalUrlsPresentation parameter to WebPresentation.BrowserOutApp:
- React component
- Modal presentation
import React, { useCallback } from 'react';
import { AdaptyOnboardingView, WebPresentation } from 'react-native-adapty';
import type { OnboardingEventHandlers } from 'react-native-adapty';
function MyOnboarding({ onboarding }) {
const onAnalytics = useCallback<OnboardingEventHandlers['onAnalytics']>((event, meta) => {}, []);
const onClose = useCallback<OnboardingEventHandlers['onClose']>((actionId, meta) => {}, []);
const onCustom = useCallback<OnboardingEventHandlers['onCustom']>((actionId, meta) => {}, []);
const onPaywall = useCallback<OnboardingEventHandlers['onPaywall']>((actionId, meta) => {}, []);
const onStateUpdated = useCallback<OnboardingEventHandlers['onStateUpdated']>((action, meta) => {}, []);
const onFinishedLoading = useCallback<OnboardingEventHandlers['onFinishedLoading']>((meta) => {}, []);
const onError = useCallback<OnboardingEventHandlers['onError']>((error) => {}, []);
return (
<AdaptyOnboardingView
onboarding={onboarding}
style={styles.container}
externalUrlsPresentation={WebPresentation.BrowserOutApp} // default – BrowserInApp
onAnalytics={onAnalytics}
onClose={onClose}
onCustom={onCustom}
onPaywall={onPaywall}
onStateUpdated={onStateUpdated}
onFinishedLoading={onFinishedLoading}
onError={onError}
/>
);
}
import { createOnboardingView, WebPresentation } from 'react-native-adapty';
const view = await createOnboardingView(
onboarding,
{ externalUrlsPresentation: WebPresentation.BrowserOutApp } // default – BrowserInApp
);
try {
await view.present();
} catch (error) {
// handle the error
}
Next steps
Once you've presented your onboarding, you'll want to handle user interactions and events. Learn how to handle onboarding events to respond to user actions and track analytics.