React Native — Handling events

If you need to control or monitor the processes that take place on the purchase screen, you can use view.registerEventHandlers method.

import {createPaywallView} from '@adapty/react-native-ui';

const view = await createPaywallView(paywall);

const unsubscribe = view.registerEventHandlers({
  onCloseButtonPress() {
    return true;
  },
  onPurchaseCompleted(profile) {
    return true;
  },
  onPurchaseStarted() { /***/},
  onPurchaseCancelled() { /***/ },
  onPurchaseFailed(error) { /***/ },
  onRestoreCompleted(profile) { /***/ },
  onRestoreFailed(error) { /***/ },
  onProductSelected() { /***/},
  onRenderingFailed(error) { /***/ },
  onLoadingProductsFailed(error) { /***/ },
});

You can register event handlers you need, while missing others. This way unused event listeners would not be created.

Event handlers can return boolean. If true is returned, than displaying process is considered complete, thus view dismisses (closes) and event listeners for this view are removed. Note, that onCloseButtonPress, onPurchaseCompleted and onRestoreCompleted in example above return true — this is their default behavior that you can override.

Event handlers

  • onCloseButtonPress — if close button is visible and the user presses it, this method will be invoked. It is recommended to dismiss the paywall view in this handler
  • onPurchaseCompleted — if user purchase succeeds, this method will be invoked and provide updated AdaptyProfile. It is recommended to dismiss the paywall view in this handler
  • onPurchaseStarted — if user presses "Purchase" action button starting purchase process, this method will be invoked
  • onPurchaseCancelled — if user initiates the purchase process and manually interrupts it, this method will be invoked
  • onPurchaseFailed — if purchase process fails, this method will be invoked and provide AdaptyError
  • onRestoreCompleted— if user restore purchases succeeds, this method will be invoked and provide updated AdaptyProfile. It is recommended to dismiss the screen if user has the required accessLevel.
  • onRestoreFailed — if restoring process fails, this method will be invoked and provide AdaptyError
  • onProductSelected — when any product in paywall view is selected, this method will be invoked, so that you can monitor what user selects before purchase
  • onRenderingFailed — if an error occurs during view rendering, this method will be invoked and provide AdaptyError. Such errors should not occur, so if you come across one, please let us know about it.
  • onLoadingProductsFailed — if you haven't set prefetchProducts: true in view creation, AdaptyUI will retrieve the necessary objects from the server by itself. If this operation fails, this method would be invoked and provide AdaptyError