UNPKG

react-native-purchasely

Version:

Purchasely is a solution to ease the integration and boost your In-App Purchase & Subscriptions on the App Store, Google Play Store and Huawei App Gallery.

55 lines (51 loc) 2.03 kB
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import { useEffect, useRef, useCallback } from 'react'; import { Platform, UIManager, findNodeHandle, NativeModules, requireNativeComponent } from 'react-native'; import React from 'react'; //import {PurchaselyView} from './PurchaselyViewManager'; const PurchaselyView = requireNativeComponent('PurchaselyView'); const PLYPresentationViewBeta = ({ placementId, presentation, onPresentationClosed, flex = 1 }) => { const ref = useRef(null); const handlePresentationClosed = useCallback(result => { if (onPresentationClosed) { onPresentationClosed(result); } }, [onPresentationClosed]); NativeModules.PurchaselyView.onPresentationClosed().then(result => { handlePresentationClosed(result); }); if (Platform.OS === 'android') { const createFragment = viewId => UIManager.dispatchViewManagerCommand(viewId, // @ts-ignore UIManager.PurchaselyView.Commands.create.toString(), [viewId]); useEffect(() => { const viewId = findNodeHandle(ref.current); if (viewId) { createFragment(viewId); } // Assuming you're setting up an event listener or similar for onPresentationClosed // Ensure the implementation here matches how your native module expects to handle this callback return () => { // Clean up any event listeners or other resources }; }, []); } return /*#__PURE__*/React.createElement(PurchaselyView // @ts-ignore , _extends({ style: { flex }, placementId: placementId, presentation: presentation }, Platform.OS === 'android' && { ref: ref })); }; export { PLYPresentationViewBeta }; //# sourceMappingURL=PLYPresentationView.js.map