Respond to flow actions - React Native

If you are building flows in the Adapty Flow & Paywall Builder, it’s crucial to set up buttons properly:

  1. Add a button in the builder and assign it either a pre-existing action or create a custom action ID.
  2. Write code in your app to handle each action you’ve assigned.

This guide shows how to handle custom and pre-existing actions in your code.

Warning

Purchases, restorations, flow/paywall closures, and URL opening are handled automatically. You can configure their default behavior or implement responses for custom actions.

Close flows and paywalls

To add a button that will close your flow or paywall:

  1. In the builder, add a button and assign it the Close action.
  2. In your app code, implement a handler for the close action that dismisses the flow or paywall.
Info

In the React Native SDK, the close action triggers closing the flow or paywall by default. However, you can override this behavior in your code if needed. For example, closing one flow might trigger opening another.

For React component, handle the close action through individual event handler props:

import React, { useCallback } from 'react';
import { AdaptyFlowView } from 'react-native-adapty';
import type { FlowEventHandlers } from 'react-native-adapty';

function MyPaywall({ flow }) {
  const onCloseButtonPress = useCallback<FlowEventHandlers['onCloseButtonPress']>(() => {
    // Handle close button press - navigate away or hide component
    navigation.goBack();
  }, [navigation]);

  return (
    <AdaptyFlowView
      flow={flow}
      style={styles.container}
      onCloseButtonPress={onCloseButtonPress}
    />
  );
}

Open URLs from flows and paywalls

Tip

If you want to add a group of links (e.g., terms of use and purchase restoration), add a Link element in the builder and handle it the same way as buttons with the Open URL action.

To add a button that opens a link from your flow or paywall (e.g., Terms of use or Privacy policy):

  1. In the builder, add a button, assign it the Open URL action, and enter the URL you want to open.
  2. In your app code, implement a handler for the openUrl action that opens the received URL in a browser.
Info

In the React Native SDK, the openUrl action triggers opening the URL by default. However, you can override this behavior in your code if needed.

For React component, handle URL opening through the event handler prop:

import React, { useCallback } from 'react';
import { Linking } from 'react-native';
import { AdaptyFlowView } from 'react-native-adapty';
import type { FlowEventHandlers } from 'react-native-adapty';

function MyPaywall({ flow }) {
  const onUrlPress = useCallback<FlowEventHandlers['onUrlPress']>((url) => {
    Linking.openURL(url);
  }, []);

  return (
    <AdaptyFlowView
      flow={flow}
      style={styles.container}
      onUrlPress={onUrlPress}
    />
  );
}

Handle custom actions

To add a button that handles any other actions:

  1. In the builder, add a button, assign it the Custom action, and assign it an ID.
  2. In your app code, implement a handler for the action ID you’ve created.

For example, if you have another set of subscription offers or one-time purchases, you can add a button that will display another flow or paywall:

For React component, handle custom actions through the event handler prop:

import React, { useCallback } from 'react';
import { AdaptyFlowView } from 'react-native-adapty';
import type { FlowEventHandlers } from 'react-native-adapty';

function MyPaywall({ flow }) {
  const onCustomAction = useCallback<FlowEventHandlers['onCustomAction']>((actionId) => {
    if (actionId === 'openNewPaywall') {
      // Display another flow or paywall
    }
  }, []);

  return (
    <AdaptyFlowView
      flow={flow}
      style={styles.container}
      onCustomAction={onCustomAction}
    />
  );
}

The second parameter of onCustomAction, args, is reserved for future Flow & Paywall Builder capabilities, so you don’t need to read it.

Handle permission requests

A flow can ask users for a system permission, such as push notifications or camera access, with the Request permission action. When the flow runs this action, the Adapty SDK sends the permission request to the permission handler in your app, not to the onCustomAction handler. To set up the handler:

  1. When you create a flow view, set the asynchronous onRequestPermission handler on it.
  2. In this handler, show the system dialog.
  3. Resolve the promise of the handler with { status: 'granted' } if the user granted the permission, and with { status: 'denied', detail: 'denied' } if the user declined it.

Without this handler, the user never sees the system permission dialog: the Adapty SDK passes { status: 'denied' } to the flow right away, and the flow runs the After response actions. For the full setup, see Handle permission requests in flows.

If you are building paywalls using the Adapty paywall builder, it’s crucial to set up buttons properly:

  1. In the old Paywall Builder, add a button and assign it either a pre-existing action or a custom action ID.
  2. Write code in your app to handle each action you’ve assigned.

This guide shows how to handle custom and pre-existing actions in your code.

Warning

Only purchases, restorations, paywall closures, and URL opening are handled automatically. All other button actions require proper response implementation in the app code.

Close paywalls

To add a button that will close your paywall:

  1. In the paywall builder, add a button and assign it the Close action.
  2. In your app code, implement a handler for the close action that dismisses the paywall.
Info

In the React Native SDK, the close action triggers closing the paywall by default. However, you can override this behavior in your code if needed. For example, closing one paywall might trigger opening another.

For React component, handle the close action through individual event handler props:

import React, { useCallback } from 'react';
import { AdaptyPaywallView } from 'react-native-adapty';
import type { EventHandlers } from 'react-native-adapty';

function MyPaywall({ paywall }) {
  const onCloseButtonPress = useCallback<EventHandlers['onCloseButtonPress']>(() => {
    // Handle close button press - navigate away or hide component
    navigation.goBack();
  }, [navigation]);

  return (
    <AdaptyPaywallView
      paywall={paywall}
      style={styles.container}
      onCloseButtonPress={onCloseButtonPress}
    />
  );
}

Open URLs from paywalls

Tip

If you want to add a group of links (e.g., terms of use and purchase restoration), add a Link element in the paywall builder and handle it the same way as buttons with the Open URL action.

To add a button that opens a link from your paywall (e.g., Terms of use or Privacy policy):

  1. In the paywall builder, add a button, assign it the Open URL action, and enter the URL you want to open.
  2. In your app code, implement a handler for the openUrl action that opens the received URL in a browser.
Info

In the React Native SDK, the openUrl action triggers opening the URL by default. However, you can override this behavior in your code if needed.

For React component, handle URL opening through the event handler prop:

import React, { useCallback } from 'react';
import { Linking } from 'react-native';
import { AdaptyPaywallView } from 'react-native-adapty';
import type { EventHandlers } from 'react-native-adapty';

function MyPaywall({ paywall }) {
  const onUrlPress = useCallback<EventHandlers['onUrlPress']>((url) => {
    Linking.openURL(url);
  }, []);

  return (
    <AdaptyPaywallView
      paywall={paywall}
      style={styles.container}
      onUrlPress={onUrlPress}
    />
  );
}

Log into the app

To add a button that logs users into your app:

  1. In the paywall builder, add a button and assign it the Login action.
  2. In your app code, implement a handler for the login action that identifies your user.

For React component, handle login through the event handler prop:

import React, { useCallback } from 'react';
import { AdaptyPaywallView } from 'react-native-adapty';
import type { EventHandlers } from 'react-native-adapty';

function MyPaywall({ paywall }) {
  const onCustomAction = useCallback<EventHandlers['onCustomAction']>((actionId) => {
    if (actionId === 'login') {
      navigation.navigate('Login');
    }
  }, [navigation]);

  return (
    <AdaptyPaywallView
      paywall={paywall}
      style={styles.container}
      onCustomAction={onCustomAction}
    />
  );
}

Handle custom actions

To add a button that handles any other actions:

  1. In the paywall builder, add a button, assign it the Custom action, and assign it an ID.
  2. In your app code, implement a handler for the action ID you’ve created.

For example, if you have another set of subscription offers or one-time purchases, you can add a button that will display another paywall:

For React component, handle custom actions through the event handler prop:

import React, { useCallback } from 'react';
import { AdaptyPaywallView } from 'react-native-adapty';
import type { EventHandlers } from 'react-native-adapty';

function MyPaywall({ paywall }) {
  const onCustomAction = useCallback<EventHandlers['onCustomAction']>((actionId) => {
    if (actionId === 'openNewPaywall') {
      // Display another paywall
    }
  }, []);

  return (
    <AdaptyPaywallView
      paywall={paywall}
      style={styles.container}
      onCustomAction={onCustomAction}
    />
  );
}