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.
48 lines (47 loc) • 1.41 kB
JavaScript
import React, { useEffect, useRef } from 'react';
import { findNodeHandle, NativeModules, Platform, requireNativeComponent, UIManager } from 'react-native';
import { jsx as _jsx } from "react/jsx-runtime";
const PurchaselyView = requireNativeComponent('PurchaselyView');
export const PLYPresentationView = ({
placementId,
presentation,
onPresentationClosed,
flex = 1
}) => {
const ref = useRef(null);
useEffect(() => {
if (!onPresentationClosed) return;
const handleClose = async () => {
const result = await NativeModules.PurchaselyView.onPresentationClosed();
onPresentationClosed(result);
};
handleClose();
}, [onPresentationClosed]);
useEffect(() => {
if (Platform.OS === 'android') {
const createFragment = viewId => UIManager.dispatchViewManagerCommand(viewId,
// @ts-ignore
UIManager.PurchaselyView.Commands.create.toString(), [viewId]);
const viewId = findNodeHandle(ref.current);
console.log('### viewId', viewId);
if (viewId) {
console.log('### creating Fragment');
createFragment(viewId);
}
}
}, []);
return /*#__PURE__*/_jsx(PurchaselyView
// @ts-ignore
, {
style: {
flex
},
placementId: placementId,
presentation: presentation,
...(Platform.OS === 'android' && {
ref: ref
})
});
};
//# sourceMappingURL=PLYPresentationView.js.map
;