UNPKG

@beletsky/react-native-yandex-ads

Version:
104 lines (103 loc) 7.94 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); } // @ts-nocheck import React, { useRef, useState } from 'react'; import { findNodeHandle, PixelRatio, StyleSheet, UIManager, View } from 'react-native'; import { AdNative as AdNativeComponent } from '../components'; import RES, { DEFAULT_CONFIG as defConfig, YA_NATIVE_ID } from '../resources'; import { ErrorException } from '../utils'; const createFragment = viewId => { const command = UIManager.getViewManagerConfig(RES.VIEW_MANAGERS.NATIVE).Commands.create; if (command) { UIManager.dispatchViewManagerCommand(viewId, command.toString(), [viewId, YA_NATIVE_ID.title, YA_NATIVE_ID.body, YA_NATIVE_ID.warning, YA_NATIVE_ID.sponsored, YA_NATIVE_ID.age, YA_NATIVE_ID.domain, YA_NATIVE_ID.icon, YA_NATIVE_ID.favicon, YA_NATIVE_ID.feedback, YA_NATIVE_ID.media]); } }; export const AdNative = _ref => { var _config$title, _config$title2, _config$body, _config$body2, _config$warning, _config$warning2, _config$sponsored, _config$sponsored2, _config$age, _config$age2, _config$domain, _config$domain2, _config$media, _config$media2, _config$title3, _config$body3, _config$warning3, _config$sponsored3, _config$age3, _config$domain3; let { adUnitId, style, config, width = 100, height = 100, requestParams = {}, ...props } = _ref; // if (!adUnitId) { // throw Error( // '[YandexAdsNative]\nThe adUnitId parameter is not set. It is mandatory. Perhaps you forgot to specify the adUnitId of the block?' // ) // } if (!(style !== null && style !== void 0 && style.width)) { throw Error('[YandexAdsNative]\nThe ad block width parameter is not set. It is mandatory. Perhaps you forgot to specify the width of the block?'); } if (!(style !== null && style !== void 0 && style.height)) { throw Error('[YandexAdsNative]\nThe ad block height parameter is not set. It is mandatory. Perhaps you forgot to specify the height of the block?'); } const ref = useRef(null); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [isLoading, setLoading] = useState(true); if (!React.Children.count(props.children)) { throw ErrorException('A native ad block must contain children inside it'); } return /*#__PURE__*/React.createElement(AdNativeComponent, { adUnitId: adUnitId ?? 'undefined', style: { flexDirection: 'row', display: 'flex', width, height }, requestParams: requestParams, height: PixelRatio.getPixelSizeForLayoutSize(height), width: PixelRatio.getPixelSizeForLayoutSize(width), titleColor: (config === null || config === void 0 ? void 0 : (_config$title = config.title) === null || _config$title === void 0 ? void 0 : _config$title.color) || defConfig.title.color, titleFontSize: (config === null || config === void 0 ? void 0 : (_config$title2 = config.title) === null || _config$title2 === void 0 ? void 0 : _config$title2.fontSize) || defConfig.title.fontSize, bodyColor: (config === null || config === void 0 ? void 0 : (_config$body = config.body) === null || _config$body === void 0 ? void 0 : _config$body.color) || defConfig.body.color, bodyFontSize: (config === null || config === void 0 ? void 0 : (_config$body2 = config.body) === null || _config$body2 === void 0 ? void 0 : _config$body2.fontSize) || defConfig.body.fontSize, warningColor: (config === null || config === void 0 ? void 0 : (_config$warning = config.warning) === null || _config$warning === void 0 ? void 0 : _config$warning.color) || defConfig.warning.color, warningFontSize: (config === null || config === void 0 ? void 0 : (_config$warning2 = config.warning) === null || _config$warning2 === void 0 ? void 0 : _config$warning2.fontSize) || defConfig.warning.fontSize, sponsoredColor: (config === null || config === void 0 ? void 0 : (_config$sponsored = config.sponsored) === null || _config$sponsored === void 0 ? void 0 : _config$sponsored.color) || defConfig.sponsored.color, sponsoredFontSize: (config === null || config === void 0 ? void 0 : (_config$sponsored2 = config.sponsored) === null || _config$sponsored2 === void 0 ? void 0 : _config$sponsored2.fontSize) || defConfig.sponsored.fontSize, ageColor: (config === null || config === void 0 ? void 0 : (_config$age = config.age) === null || _config$age === void 0 ? void 0 : _config$age.color) || defConfig.age.color, ageFontSize: (config === null || config === void 0 ? void 0 : (_config$age2 = config.age) === null || _config$age2 === void 0 ? void 0 : _config$age2.fontSize) || defConfig.age.fontSize, domainColor: (config === null || config === void 0 ? void 0 : (_config$domain = config.domain) === null || _config$domain === void 0 ? void 0 : _config$domain.color) || defConfig.domain.color, domainFontSize: (config === null || config === void 0 ? void 0 : (_config$domain2 = config.domain) === null || _config$domain2 === void 0 ? void 0 : _config$domain2.fontSize) || defConfig.domain.fontSize, mediaWidth: (config === null || config === void 0 ? void 0 : (_config$media = config.media) === null || _config$media === void 0 ? void 0 : _config$media.width) || defConfig.media.width, mediaHeight: (config === null || config === void 0 ? void 0 : (_config$media2 = config.media) === null || _config$media2 === void 0 ? void 0 : _config$media2.height) || defConfig.media.height, titleLines: (config === null || config === void 0 ? void 0 : (_config$title3 = config.title) === null || _config$title3 === void 0 ? void 0 : _config$title3.numberOfLines) || defConfig.title.numberOfLines, bodyLines: (config === null || config === void 0 ? void 0 : (_config$body3 = config.body) === null || _config$body3 === void 0 ? void 0 : _config$body3.numberOfLines) || defConfig.body.numberOfLines, warningLines: (config === null || config === void 0 ? void 0 : (_config$warning3 = config.warning) === null || _config$warning3 === void 0 ? void 0 : _config$warning3.numberOfLines) || defConfig.warning.numberOfLines, sponsoredLines: (config === null || config === void 0 ? void 0 : (_config$sponsored3 = config.sponsored) === null || _config$sponsored3 === void 0 ? void 0 : _config$sponsored3.numberOfLines) || defConfig.sponsored.numberOfLines, ageLines: (config === null || config === void 0 ? void 0 : (_config$age3 = config.age) === null || _config$age3 === void 0 ? void 0 : _config$age3.numberOfLines) || defConfig.age.numberOfLines, domainLines: (config === null || config === void 0 ? void 0 : (_config$domain3 = config.domain) === null || _config$domain3 === void 0 ? void 0 : _config$domain3.numberOfLines) || defConfig.domain.numberOfLines // onLoadEnd: () => setLoading(false), , onDidLoad: () => console.log('onDidLoad'), onClick: () => console.log('onClick'), onDidTrackImpression: () => console.log('onDidTrackImpression'), onDidFailLoading: () => console.log('onDidFailLoading'), onWillLeaveApp: () => console.log('onWillLeaveApp'), onDidReturnedToApplication: () => console.log('onDidReturnedToApplication'), ref: ref }, /*#__PURE__*/React.createElement(View, _extends({}, props, { nativeID: YA_NATIVE_ID.container, onLayout: () => { if (React.Children.count(props.children)) { if (ref && 'current' in ref) { const viewId = findNodeHandle(ref.current); if (viewId) { setLoading(true); createFragment(viewId); } } } }, style: [style, defStyle.content] }), props.children)); }; const defStyle = StyleSheet.create({ content: { flex: 1 } }); //# sourceMappingURL=index.android.js.map