react-native-google-mobile-ads 11.1.1 → 11.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNGoogleMobileAds.podspec +4 -0
- package/__tests__/interstitial.test.ts +22 -8
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +6 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +13 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.swift +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.swift +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +10 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.swift +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift +4 -0
- package/jest.setup.ts +2 -1
- package/lib/commonjs/MobileAds.js +28 -31
- package/lib/commonjs/MobileAds.js.map +1 -1
- package/lib/commonjs/ads/AppOpenAd.js +1 -2
- package/lib/commonjs/ads/AppOpenAd.js.map +1 -1
- package/lib/commonjs/ads/InterstitialAd.js +1 -2
- package/lib/commonjs/ads/InterstitialAd.js.map +1 -1
- package/lib/commonjs/ads/MobileAd.js +8 -6
- package/lib/commonjs/ads/MobileAd.js.map +1 -1
- package/lib/commonjs/ads/RewardedAd.js +1 -2
- package/lib/commonjs/ads/RewardedAd.js.map +1 -1
- package/lib/commonjs/ads/RewardedInterstitialAd.js +1 -2
- package/lib/commonjs/ads/RewardedInterstitialAd.js.map +1 -1
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/MobileAds.js +28 -31
- package/lib/module/MobileAds.js.map +1 -1
- package/lib/module/ads/AppOpenAd.js +1 -2
- package/lib/module/ads/AppOpenAd.js.map +1 -1
- package/lib/module/ads/InterstitialAd.js +1 -2
- package/lib/module/ads/InterstitialAd.js.map +1 -1
- package/lib/module/ads/MobileAd.js +8 -6
- package/lib/module/ads/MobileAd.js.map +1 -1
- package/lib/module/ads/RewardedAd.js +1 -2
- package/lib/module/ads/RewardedAd.js.map +1 -1
- package/lib/module/ads/RewardedInterstitialAd.js +1 -2
- package/lib/module/ads/RewardedInterstitialAd.js.map +1 -1
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/MobileAds.d.ts +6 -7
- package/lib/typescript/MobileAds.d.ts.map +1 -1
- package/lib/typescript/ads/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/ads/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/ads/MobileAd.d.ts +6 -5
- package/lib/typescript/ads/MobileAd.d.ts.map +1 -1
- package/lib/typescript/ads/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/ads/RewardedInterstitialAd.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts +2 -1
- package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts.map +1 -1
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +0 -13
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts.map +1 -1
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +0 -10
- package/lib/typescript/types/MobileAdsModule.interface.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/MobileAds.ts +32 -62
- package/src/ads/AppOpenAd.ts +7 -2
- package/src/ads/InterstitialAd.ts +7 -2
- package/src/ads/MobileAd.ts +22 -10
- package/src/ads/RewardedAd.ts +7 -2
- package/src/ads/RewardedInterstitialAd.ts +1 -2
- package/src/internal/GoogleMobileAdsNativeEventEmitter.ts +1 -1
- package/src/types/GoogleMobileAdsNativeModule.ts +0 -17
- package/src/types/MobileAdsModule.interface.ts +0 -13
- package/src/version.ts +1 -1
- package/lib/commonjs/internal/Module.js +0 -44
- package/lib/commonjs/internal/Module.js.map +0 -1
- package/lib/commonjs/internal/index.js +0 -44
- package/lib/commonjs/internal/index.js.map +0 -1
- package/lib/commonjs/internal/registry/nativeModule.js +0 -180
- package/lib/commonjs/internal/registry/nativeModule.js.map +0 -1
- package/lib/commonjs/types/Module.interface.js +0 -2
- package/lib/commonjs/types/Module.interface.js.map +0 -1
- package/lib/module/internal/Module.js +0 -54
- package/lib/module/internal/Module.js.map +0 -1
- package/lib/module/internal/index.js +0 -22
- package/lib/module/internal/index.js.map +0 -1
- package/lib/module/internal/registry/nativeModule.js +0 -174
- package/lib/module/internal/registry/nativeModule.js.map +0 -1
- package/lib/module/types/Module.interface.js +0 -2
- package/lib/module/types/Module.interface.js.map +0 -1
- package/lib/typescript/internal/Module.d.ts +0 -14
- package/lib/typescript/internal/Module.d.ts.map +0 -1
- package/lib/typescript/internal/index.d.ts +0 -5
- package/lib/typescript/internal/index.d.ts.map +0 -1
- package/lib/typescript/internal/registry/nativeModule.d.ts +0 -10
- package/lib/typescript/internal/registry/nativeModule.d.ts.map +0 -1
- package/lib/typescript/types/Module.interface.d.ts +0 -15
- package/lib/typescript/types/Module.interface.d.ts.map +0 -1
- package/src/internal/Module.ts +0 -58
- package/src/internal/index.ts +0 -21
- package/src/internal/registry/nativeModule.ts +0 -205
- package/src/types/Module.interface.ts +0 -16
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this library except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { NativeModules, Platform } from 'react-native';
|
|
19
|
-
import { NativeError } from '../NativeError';
|
|
20
|
-
import { GoogleMobileAdsNativeEventEmitter } from '../GoogleMobileAdsNativeEventEmitter';
|
|
21
|
-
import { SharedEventEmitter } from '../SharedEventEmitter';
|
|
22
|
-
import { isFunction } from '../../common';
|
|
23
|
-
import { ModuleInterface } from '../../types/Module.interface';
|
|
24
|
-
|
|
25
|
-
const NATIVE_MODULE_REGISTRY: Record<string, unknown> = {};
|
|
26
|
-
const NATIVE_MODULE_EVENT_SUBSCRIPTIONS: Record<string, unknown> = {};
|
|
27
|
-
|
|
28
|
-
function nativeModuleKey(module: ModuleInterface) {
|
|
29
|
-
return `${module._customUrlOrRegion || ''}:${module.app.name}:${module._config.namespace}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Wraps a native module method to provide
|
|
34
|
-
* auto prepended args and custom Error classes.
|
|
35
|
-
*
|
|
36
|
-
* @param namespace
|
|
37
|
-
* @param method
|
|
38
|
-
* @param argToPrepend
|
|
39
|
-
* @returns {Function}
|
|
40
|
-
*/
|
|
41
|
-
function nativeModuleMethodWrapped(
|
|
42
|
-
namespace: string,
|
|
43
|
-
method: (...args: unknown[]) => Promise<unknown> | void,
|
|
44
|
-
argToPrepend: [],
|
|
45
|
-
) {
|
|
46
|
-
return (...args: []) => {
|
|
47
|
-
const possiblePromise = method(...[...argToPrepend, ...args]);
|
|
48
|
-
|
|
49
|
-
// @ts-ignore -- return type is Promise, so tsc infers we *know* it is a promise and .then always exists, but
|
|
50
|
-
// but the typing is actually speculative, we do need to test it
|
|
51
|
-
if (possiblePromise && possiblePromise.then) {
|
|
52
|
-
const jsStack = new Error().stack || '';
|
|
53
|
-
return possiblePromise.catch(nativeError =>
|
|
54
|
-
Promise.reject(new NativeError(nativeError, jsStack, namespace)),
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return possiblePromise;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Prepends all arguments in prependArgs to all native method calls
|
|
64
|
-
*
|
|
65
|
-
* @param namespace
|
|
66
|
-
* @param NativeModule
|
|
67
|
-
* @param argToPrepend
|
|
68
|
-
*/
|
|
69
|
-
function nativeModuleWrapped(
|
|
70
|
-
namespace: string,
|
|
71
|
-
NativeModule: Record<string, (...args: unknown[]) => Promise<unknown> | void>,
|
|
72
|
-
argToPrepend: [],
|
|
73
|
-
) {
|
|
74
|
-
const native: Record<string, unknown> = {};
|
|
75
|
-
if (!NativeModule) {
|
|
76
|
-
return NativeModule;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const properties = Object.keys(NativeModule);
|
|
80
|
-
|
|
81
|
-
for (let i = 0, len = properties.length; i < len; i++) {
|
|
82
|
-
const property = properties[i];
|
|
83
|
-
if (isFunction(NativeModule[property])) {
|
|
84
|
-
native[property] = nativeModuleMethodWrapped(namespace, NativeModule[property], argToPrepend);
|
|
85
|
-
} else {
|
|
86
|
-
native[property] = NativeModule[property];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return native;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Initialises and wraps all the native module methods.
|
|
95
|
-
*
|
|
96
|
-
* @param module
|
|
97
|
-
* @returns {*}
|
|
98
|
-
*/
|
|
99
|
-
function initialiseNativeModule(module: ModuleInterface) {
|
|
100
|
-
const config = module._config;
|
|
101
|
-
const key = nativeModuleKey(module);
|
|
102
|
-
const { namespace, nativeEvents, nativeModuleName } = config;
|
|
103
|
-
const multiModuleRoot: Record<string, unknown> = {};
|
|
104
|
-
const multiModule = Array.isArray(nativeModuleName);
|
|
105
|
-
const nativeModuleNames = multiModule ? nativeModuleName : [nativeModuleName];
|
|
106
|
-
|
|
107
|
-
for (let i = 0; i < nativeModuleNames.length; i++) {
|
|
108
|
-
const nativeModule = NativeModules[nativeModuleNames[i]];
|
|
109
|
-
|
|
110
|
-
// only error if there's a single native module
|
|
111
|
-
// as multi modules can mean some are optional
|
|
112
|
-
if (!multiModule && !nativeModule) {
|
|
113
|
-
throw new Error(getMissingModuleHelpText(namespace));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (multiModule) {
|
|
117
|
-
multiModuleRoot[nativeModuleNames[i]] = !!nativeModule;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
Object.assign(multiModuleRoot, nativeModuleWrapped(namespace, nativeModule, []));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (nativeEvents && nativeEvents.length) {
|
|
124
|
-
for (let i = 0, len = nativeEvents.length; i < len; i++) {
|
|
125
|
-
subscribeToNativeModuleEvent(nativeEvents[i]);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
Object.freeze(multiModuleRoot);
|
|
130
|
-
|
|
131
|
-
NATIVE_MODULE_REGISTRY[key] = multiModuleRoot;
|
|
132
|
-
|
|
133
|
-
return NATIVE_MODULE_REGISTRY[key];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Subscribe to a native event for js side distribution by appName
|
|
138
|
-
* React Native events are hard set at compile - cant do dynamic event names
|
|
139
|
-
* so we use a single event send it to js and js then internally can prefix it
|
|
140
|
-
* and distribute dynamically.
|
|
141
|
-
*
|
|
142
|
-
* @param eventName
|
|
143
|
-
* @private
|
|
144
|
-
*/
|
|
145
|
-
function subscribeToNativeModuleEvent(eventName: string) {
|
|
146
|
-
if (!NATIVE_MODULE_EVENT_SUBSCRIPTIONS[eventName]) {
|
|
147
|
-
GoogleMobileAdsNativeEventEmitter.addListener(eventName, event => {
|
|
148
|
-
if (event.appName) {
|
|
149
|
-
// native event has an appName property - auto prefix and internally emit
|
|
150
|
-
SharedEventEmitter.emit(`${event.appName}-${eventName}`, event);
|
|
151
|
-
} else {
|
|
152
|
-
// standard event - no need to prefix
|
|
153
|
-
SharedEventEmitter.emit(eventName, event);
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
NATIVE_MODULE_EVENT_SUBSCRIPTIONS[eventName] = true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Help text for integrating the native counter parts for each module.
|
|
163
|
-
*
|
|
164
|
-
* @param namespace
|
|
165
|
-
* @returns {string}
|
|
166
|
-
*/
|
|
167
|
-
function getMissingModuleHelpText(namespace: string) {
|
|
168
|
-
const snippet = `${namespace}()`;
|
|
169
|
-
const nativeModule = namespace.charAt(0).toUpperCase() + namespace.slice(1);
|
|
170
|
-
|
|
171
|
-
if (Platform.OS === 'ios') {
|
|
172
|
-
return (
|
|
173
|
-
`You attempted to use a module that's not installed natively on your iOS project by calling ${snippet}.` +
|
|
174
|
-
'\r\n\r\nEnsure you have either linked the module or added it to your projects Podfile.' +
|
|
175
|
-
'\r\n\r\nSee http://invertase.link/ios for full setup instructions.'
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const rnPackage = `'io.invertase.${namespace}.ReactNative${nativeModule}Package'`;
|
|
180
|
-
const newInstance = `'new ReactNative${nativeModule}Package()'`;
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
`You attempted to use a module that's not installed on your Android project by calling ${snippet}.` +
|
|
184
|
-
`\r\n\r\nEnsure you have:\r\n\r\n1) imported the ${rnPackage} module in your 'MainApplication.java' file.\r\n\r\n2) Added the ` +
|
|
185
|
-
`${newInstance} line inside of the RN 'getPackages()' method list.` +
|
|
186
|
-
'\r\n\r\nSee http://invertase.link/android for full setup instructions.'
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Gets a wrapped native module instance for the provided module.
|
|
192
|
-
* Will attempt to create a new instance if non previously created.
|
|
193
|
-
*
|
|
194
|
-
* @param module
|
|
195
|
-
* @returns {*}
|
|
196
|
-
*/
|
|
197
|
-
export function getNativeModule(module: ModuleInterface) {
|
|
198
|
-
const key = nativeModuleKey(module);
|
|
199
|
-
|
|
200
|
-
if (NATIVE_MODULE_REGISTRY[key]) {
|
|
201
|
-
return NATIVE_MODULE_REGISTRY[key];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return initialiseNativeModule(module);
|
|
205
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export interface App {
|
|
2
|
-
name: string;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export interface Config {
|
|
6
|
-
version: string;
|
|
7
|
-
namespace: string;
|
|
8
|
-
nativeModuleName: string[];
|
|
9
|
-
nativeEvents: string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface ModuleInterface {
|
|
13
|
-
app: App;
|
|
14
|
-
_config: Config;
|
|
15
|
-
_customUrlOrRegion?: string;
|
|
16
|
-
}
|