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 handleronPurchaseCompleted
— if user purchase succeeds, this method will be invoked and provide updatedAdaptyProfile
. It is recommended to dismiss the paywall view in this handleronPurchaseStarted
— if user presses "Purchase" action button starting purchase process, this method will be invokedonPurchaseCancelled
— if user initiates the purchase process and manually interrupts it, this method will be invokedonPurchaseFailed
— if purchase process fails, this method will be invoked and provideAdaptyError
onRestoreCompleted
— if user restore purchases succeeds, this method will be invoked and provide updatedAdaptyProfile
. It is recommended to dismiss the screen if user has the requiredaccessLevel
.onRestoreFailed
— if restoring process fails, this method will be invoked and provideAdaptyError
onProductSelected
— when any product in paywall view is selected, this method will be invoked, so that you can monitor what user selects before purchaseonRenderingFailed
— if an error occurs during view rendering, this method will be invoked and provideAdaptyError
. Such errors should not occur, so if you come across one, please let us know about it.onLoadingProductsFailed
— if you haven't setprefetchProducts: 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 provideAdaptyError
Updated about 2 months ago