@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
105 lines (104 loc) • 4.23 kB
JavaScript
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { findNodeHandle, UIManager } from 'react-native';
import React from 'react';
import { BluestackSDK } from '../BluestackManager';
import { BannerModuleView } from './BannerViewManager';
import logger from '../Utils/Logger';
export class BannerView extends React.Component {
constructor(props) {
super(props);
_defineProperty(this, "_preferenceJSON", '{}');
_defineProperty(this, "_shouldAutoLoadWhenReady", false);
this.handleBannerAdFailedToLoad = this.handleBannerAdFailedToLoad.bind(this);
this.state = {
shouldLoadNow: false,
visible: true
};
if (this.props.shouldLoadWhenReady != null) {
this._shouldAutoLoadWhenReady = this.props.shouldLoadWhenReady;
}
if (this.props.preference != null && this._preferenceJSON === '{}') {
this._preferenceJSON = this.props.preference.getPreferenceJSON();
} else {
this._preferenceJSON = '{}';
}
}
load(bsPreference) {
if (this._shouldAutoLoadWhenReady) {
logger.log('Banner load call is not required when shouldLoadWhenReady is true');
}
if (bsPreference != null) {
this._preferenceJSON = bsPreference.getPreferenceJSON();
} else {
this._preferenceJSON = '{}';
}
this.loadWithPreferenceJSON(this._preferenceJSON);
}
loadWithPreferenceJSON(preferenceJSON) {
this.setState({
shouldLoadNow: true
});
logger.log('Loading Banner ad with preference: ' + preferenceJSON);
UIManager.dispatchViewManagerCommand(findNodeHandle(this), 'create', [preferenceJSON]);
}
destroy() {
UIManager.dispatchViewManagerCommand(findNodeHandle(this), 'destroy', undefined);
}
toggleRefresh(state = false) {
UIManager.dispatchViewManagerCommand(findNodeHandle(this), 'refresh', [state]);
}
hide() {
this.setState({
visible: false
});
}
show() {
this.setState({
visible: true
});
}
handleBannerAdFailedToLoad(error) {
var _error$nativeEvent;
error.persist();
// If SDK is not initialized
if ((error === null || error === void 0 || (_error$nativeEvent = error.nativeEvent) === null || _error$nativeEvent === void 0 ? void 0 : _error$nativeEvent.message) === 'SDK is not initialized' && this._shouldAutoLoadWhenReady) {
// logger.log('handleBannerAdFailedToLoad: ' + error?.nativeEvent?.message);
let appId = this.props.placementId.split('/')[1];
BluestackSDK.initialize(appId, true).then(() => {
this.loadWithPreferenceJSON(this._preferenceJSON);
}).catch(() => {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(error);
}
});
} else if (this.props.onAdFailedToLoad) {
// logger.log('handleBannerAdFailedToLoad: onAdFailedToLoad');
this.props.onAdFailedToLoad(error);
}
}
render() {
return /*#__PURE__*/React.createElement(BannerModuleView, {
shouldLoadNow: this.state.shouldLoadNow,
shouldLoadWhenReady: this._shouldAutoLoadWhenReady,
visible: this.state.visible,
type: this.props.type,
placementId: this.props.placementId,
preference: this._preferenceJSON,
onBannerAdLoaded: this.props.onAdLoaded,
onBannerAdFailedToLoad: this.handleBannerAdFailedToLoad,
onBannerAdRefreshed: this.props.onAdRefreshed,
onBannerAdFailedToRefresh: this.props.onAdFailedToRefresh,
onBannerAdClicked: this.props.onAdClicked
//reset shouldLoadNow for next call
,
onBannerAdLoadCalled: () => {
this.setState({
shouldLoadNow: false
});
}
});
}
}
//# sourceMappingURL=BannerView.js.map