UNPKG

react-native-tapdaq

Version:
67 lines (66 loc) 2.58 kB
"use strict"; var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result["default"] = mod; return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const TapdaqNativeAdView = react_native_1.requireNativeComponent('TapdaqMediatedNativeAdView'); const TapdaqNativeAdViewConfig = react_native_1.UIManager.getViewManagerConfig('TapdaqMediatedNativeAdView'); const styles = { root: { width: '100%', height: 290, opacity: 1, }, }; // TODO: do not use Hooks const MediatedNativeAd = (compProps) => { const { style = {}, imageStyle = {}, onLoadStart = () => null, onClick = () => null, onError = () => null, onLoad = () => null, onDestroy = () => null, placement = 'default', ...other } = compProps; const [ad, setAd] = react_1.useState({}); const [ready, setReady] = react_1.useState(false); let ref = react_1.default.createRef(); const finalStyle = { ...styles.root, ...style }; if (!ready) { finalStyle.height = 0; finalStyle.opacity = 0; } const localOnLoad = (e) => { setReady(true); setAd(e.nativeEvent); if (compProps.onLoad) { compProps.onLoad(e); } }; const localOnLoadStart = (e) => { setReady(false); setAd({}); if (compProps.onLoadStart) { compProps.onLoadStart(e); } }; // const destroyNativeAd = () => { // setReady(false) // UIManager.dispatchViewManagerCommand(findNodeHandle(ref), TapdaqNativeAdViewConfig.Commands.destroyAd, []) // } // const playNativeAdVideo = () => { // if (!ad.hasVideoContent) { // return // } // UIManager.dispatchViewManagerCommand(findNodeHandle(ref), TapdaqNativeAdViewConfig.Commands.playAd, []) // } // const pauseNativeAdVideo = () => { // if (!ad.hasVideoContent) { // return // } // UIManager.dispatchViewManagerCommand(findNodeHandle(ref), TapdaqNativeAdViewConfig.Commands.pauseAd, []) // } return (<TapdaqNativeAdView ref={(r) => { ref = r; }} {...other} placement={placement} style={finalStyle} onLoad={localOnLoad} onLoadStart={localOnLoadStart} onClick={onClick} onError={onError} onDestroy={onDestroy}/>); }; exports.default = MediatedNativeAd;