UNPKG

@beletsky/react-native-yandex-ads

Version:
112 lines (110 loc) 9.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AdNative = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _components = require("../components"); var _resources = _interopRequireWildcard(require("../resources")); var _utils = require("../utils"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } 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); } const createFragment = viewId => { const command = _reactNative.UIManager.getViewManagerConfig(_resources.default.VIEW_MANAGERS.NATIVE).Commands.create; if (command) { _reactNative.UIManager.dispatchViewManagerCommand(viewId, command.toString(), [viewId, _resources.YA_NATIVE_ID.title, _resources.YA_NATIVE_ID.body, _resources.YA_NATIVE_ID.warning, _resources.YA_NATIVE_ID.sponsored, _resources.YA_NATIVE_ID.age, _resources.YA_NATIVE_ID.domain, _resources.YA_NATIVE_ID.icon, _resources.YA_NATIVE_ID.favicon, _resources.YA_NATIVE_ID.feedback, _resources.YA_NATIVE_ID.media]); } }; 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 = (0, _react.useRef)(null); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [isLoading, setLoading] = (0, _react.useState)(true); if (!_react.default.Children.count(props.children)) { throw (0, _utils.ErrorException)('A native ad block must contain children inside it'); } return /*#__PURE__*/_react.default.createElement(_components.AdNative, { adUnitId: adUnitId ?? 'undefined', style: { flexDirection: 'row', display: 'flex', width, height }, requestParams: requestParams, height: _reactNative.PixelRatio.getPixelSizeForLayoutSize(height), width: _reactNative.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) || _resources.DEFAULT_CONFIG.title.color, titleFontSize: (config === null || config === void 0 ? void 0 : (_config$title2 = config.title) === null || _config$title2 === void 0 ? void 0 : _config$title2.fontSize) || _resources.DEFAULT_CONFIG.title.fontSize, bodyColor: (config === null || config === void 0 ? void 0 : (_config$body = config.body) === null || _config$body === void 0 ? void 0 : _config$body.color) || _resources.DEFAULT_CONFIG.body.color, bodyFontSize: (config === null || config === void 0 ? void 0 : (_config$body2 = config.body) === null || _config$body2 === void 0 ? void 0 : _config$body2.fontSize) || _resources.DEFAULT_CONFIG.body.fontSize, warningColor: (config === null || config === void 0 ? void 0 : (_config$warning = config.warning) === null || _config$warning === void 0 ? void 0 : _config$warning.color) || _resources.DEFAULT_CONFIG.warning.color, warningFontSize: (config === null || config === void 0 ? void 0 : (_config$warning2 = config.warning) === null || _config$warning2 === void 0 ? void 0 : _config$warning2.fontSize) || _resources.DEFAULT_CONFIG.warning.fontSize, sponsoredColor: (config === null || config === void 0 ? void 0 : (_config$sponsored = config.sponsored) === null || _config$sponsored === void 0 ? void 0 : _config$sponsored.color) || _resources.DEFAULT_CONFIG.sponsored.color, sponsoredFontSize: (config === null || config === void 0 ? void 0 : (_config$sponsored2 = config.sponsored) === null || _config$sponsored2 === void 0 ? void 0 : _config$sponsored2.fontSize) || _resources.DEFAULT_CONFIG.sponsored.fontSize, ageColor: (config === null || config === void 0 ? void 0 : (_config$age = config.age) === null || _config$age === void 0 ? void 0 : _config$age.color) || _resources.DEFAULT_CONFIG.age.color, ageFontSize: (config === null || config === void 0 ? void 0 : (_config$age2 = config.age) === null || _config$age2 === void 0 ? void 0 : _config$age2.fontSize) || _resources.DEFAULT_CONFIG.age.fontSize, domainColor: (config === null || config === void 0 ? void 0 : (_config$domain = config.domain) === null || _config$domain === void 0 ? void 0 : _config$domain.color) || _resources.DEFAULT_CONFIG.domain.color, domainFontSize: (config === null || config === void 0 ? void 0 : (_config$domain2 = config.domain) === null || _config$domain2 === void 0 ? void 0 : _config$domain2.fontSize) || _resources.DEFAULT_CONFIG.domain.fontSize, mediaWidth: (config === null || config === void 0 ? void 0 : (_config$media = config.media) === null || _config$media === void 0 ? void 0 : _config$media.width) || _resources.DEFAULT_CONFIG.media.width, mediaHeight: (config === null || config === void 0 ? void 0 : (_config$media2 = config.media) === null || _config$media2 === void 0 ? void 0 : _config$media2.height) || _resources.DEFAULT_CONFIG.media.height, titleLines: (config === null || config === void 0 ? void 0 : (_config$title3 = config.title) === null || _config$title3 === void 0 ? void 0 : _config$title3.numberOfLines) || _resources.DEFAULT_CONFIG.title.numberOfLines, bodyLines: (config === null || config === void 0 ? void 0 : (_config$body3 = config.body) === null || _config$body3 === void 0 ? void 0 : _config$body3.numberOfLines) || _resources.DEFAULT_CONFIG.body.numberOfLines, warningLines: (config === null || config === void 0 ? void 0 : (_config$warning3 = config.warning) === null || _config$warning3 === void 0 ? void 0 : _config$warning3.numberOfLines) || _resources.DEFAULT_CONFIG.warning.numberOfLines, sponsoredLines: (config === null || config === void 0 ? void 0 : (_config$sponsored3 = config.sponsored) === null || _config$sponsored3 === void 0 ? void 0 : _config$sponsored3.numberOfLines) || _resources.DEFAULT_CONFIG.sponsored.numberOfLines, ageLines: (config === null || config === void 0 ? void 0 : (_config$age3 = config.age) === null || _config$age3 === void 0 ? void 0 : _config$age3.numberOfLines) || _resources.DEFAULT_CONFIG.age.numberOfLines, domainLines: (config === null || config === void 0 ? void 0 : (_config$domain3 = config.domain) === null || _config$domain3 === void 0 ? void 0 : _config$domain3.numberOfLines) || _resources.DEFAULT_CONFIG.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.default.createElement(_reactNative.View, _extends({}, props, { nativeID: _resources.YA_NATIVE_ID.container, onLayout: () => { if (_react.default.Children.count(props.children)) { if (ref && 'current' in ref) { const viewId = (0, _reactNative.findNodeHandle)(ref.current); if (viewId) { setLoading(true); createFragment(viewId); } } } }, style: [style, defStyle.content] }), props.children)); }; exports.AdNative = AdNative; const defStyle = _reactNative.StyleSheet.create({ content: { flex: 1 } }); //# sourceMappingURL=index.android.js.map