@azerion/bluestack-sdk-react-native
Version:
BlueStack provides functionalities for monetizing your mobile application: from premium sales with rich media, video and innovative formats, it facilitates inserting native mobile ads as well all standard display formats. BlueStack SDK is a library that a
87 lines (84 loc) • 2.82 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { useState, useCallback } from 'react';
import { Platform, requireNativeComponent, UIManager } from 'react-native';
const sizeForType = {
standard: {
width: 320,
height: 50
},
large: {
width: 320,
height: 100
},
full: {
width: 468,
height: 60
},
mediumRectangle: {
width: 300,
height: 250
},
leaderboard: {
width: 728,
height: 90
},
dynamic: {
width: -1,
height: 50
},
dynamicLeaderboard: {
width: -1,
height: 90
}
};
const getSizeForType = type => sizeForType[type];
const LINKING_ERROR = `The package 'react-native-bluestack--module' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
ios: "- You have run 'pod install'\n",
default: ''
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n';
const ComponentName = 'BluestackModuleView';
export const BluestackModuleView = UIManager.getViewManagerConfig(ComponentName) != null ? requireNativeComponent(ComponentName) : () => {
throw new Error(LINKING_ERROR);
};
// export const BannerModuleView = (props: BannerViewProps) => {
export const BannerModuleView = props => {
const {
onBannerAdLoaded,
onBannerAdFailedToLoad,
onBannerAdRefreshed,
onBannerAdFailedToRefresh,
onBannerAdClicked,
type,
visible,
...restProps
} = props;
let adType = type;
if (adType === undefined) {
adType = 'standard';
}
const size = getSizeForType(adType);
// Track dynamic height from native side
const [dynamicHeight, setDynamicHeight] = useState(size.height);
// Handle ad loaded event and update height
const handleAdLoaded = useCallback(event => {
var _event$nativeEvent;
if (event !== null && event !== void 0 && (_event$nativeEvent = event.nativeEvent) !== null && _event$nativeEvent !== void 0 && _event$nativeEvent.size) {
setDynamicHeight(event.nativeEvent.size);
}
onBannerAdLoaded === null || onBannerAdLoaded === void 0 || onBannerAdLoaded(event);
}, [onBannerAdLoaded]);
return /*#__PURE__*/React.createElement(BluestackModuleView, _extends({}, restProps, {
style: [{
width: size.width,
height: dynamicHeight
}],
adSize: adType.toString(),
visible: visible,
onAdLoaded: handleAdLoaded,
onAdFailedToLoad: onBannerAdFailedToLoad,
onAdRefreshed: onBannerAdRefreshed,
onAdFailedToRefresh: onBannerAdFailedToRefresh,
onAdClicked: onBannerAdClicked
}));
};
//# sourceMappingURL=BannerViewManager.js.map