react-native-google-mobile-ads 14.2.3 → 14.2.5
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/__tests__/banner.test.tsx +14 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt +166 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.kt +42 -0
- package/docs/testing.mdx +17 -0
- package/docs.json +2 -1
- package/jest.setup.ts +1 -4
- package/lib/commonjs/version.js +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -5
- package/src/version.ts +1 -1
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +0 -207
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +0 -49
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { render } from '@testing-library/react-native';
|
|
3
4
|
import { BannerAd, BannerAdSize } from '../src';
|
|
4
5
|
|
|
5
6
|
const MOCK_ID = 'MOCK_ID';
|
|
6
7
|
|
|
8
|
+
jest.doMock('react-native', () => {
|
|
9
|
+
return Object.setPrototypeOf(
|
|
10
|
+
{
|
|
11
|
+
...ReactNative,
|
|
12
|
+
Platform: {
|
|
13
|
+
OS: 'android',
|
|
14
|
+
select: () => {},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
ReactNative,
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
7
21
|
describe('Google Mobile Ads Banner', function () {
|
|
8
22
|
it('throws if no unit ID was provided.', function () {
|
|
9
23
|
let errorMsg;
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
package io.invertase.googlemobileads
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import com.facebook.react.bridge.*
|
|
21
|
+
import com.google.android.gms.ads.MobileAds
|
|
22
|
+
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener
|
|
23
|
+
import com.google.android.gms.ads.RequestConfiguration
|
|
24
|
+
import com.google.android.gms.ads.AdInspectorError
|
|
25
|
+
import com.google.android.gms.ads.AdRequest
|
|
26
|
+
import com.google.android.gms.ads.OnAdInspectorClosedListener
|
|
27
|
+
|
|
28
|
+
private const val SERVICE = "RNGoogleMobileAdsModule";
|
|
29
|
+
|
|
30
|
+
class ReactNativeGoogleMobileAdsModule(
|
|
31
|
+
reactContext: ReactApplicationContext
|
|
32
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
33
|
+
|
|
34
|
+
override fun getName() = SERVICE
|
|
35
|
+
|
|
36
|
+
private fun buildRequestConfiguration(
|
|
37
|
+
requestConfiguration: ReadableMap
|
|
38
|
+
): RequestConfiguration {
|
|
39
|
+
val builder = RequestConfiguration.Builder()
|
|
40
|
+
|
|
41
|
+
if (requestConfiguration.hasKey("testDeviceIdentifiers")) {
|
|
42
|
+
val devices = checkNotNull(requestConfiguration.getArray("testDeviceIdentifiers")).toArrayList()
|
|
43
|
+
val testDeviceIds = devices.map {
|
|
44
|
+
val id = it as String;
|
|
45
|
+
if (id == "EMULATOR") {
|
|
46
|
+
AdRequest.DEVICE_ID_EMULATOR
|
|
47
|
+
} else {
|
|
48
|
+
id
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
builder.setTestDeviceIds(testDeviceIds)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (requestConfiguration.hasKey("maxAdContentRating")) {
|
|
56
|
+
val rating = requestConfiguration.getString("maxAdContentRating")
|
|
57
|
+
|
|
58
|
+
when (rating) {
|
|
59
|
+
"G" -> builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G)
|
|
60
|
+
"PG" -> builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG)
|
|
61
|
+
"T" -> builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T)
|
|
62
|
+
"MA" -> builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (requestConfiguration.hasKey("tagForChildDirectedTreatment")) {
|
|
67
|
+
val tagForChildDirectedTreatment = requestConfiguration.getBoolean("tagForChildDirectedTreatment")
|
|
68
|
+
builder.setTagForChildDirectedTreatment(
|
|
69
|
+
if (tagForChildDirectedTreatment) {
|
|
70
|
+
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE
|
|
71
|
+
} else {
|
|
72
|
+
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
} else {
|
|
76
|
+
builder.setTagForChildDirectedTreatment(RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (requestConfiguration.hasKey("tagForUnderAgeOfConsent")) {
|
|
80
|
+
val tagForUnderAgeOfConsent = requestConfiguration.getBoolean("tagForUnderAgeOfConsent")
|
|
81
|
+
builder.setTagForUnderAgeOfConsent(
|
|
82
|
+
if (tagForUnderAgeOfConsent) {
|
|
83
|
+
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE
|
|
84
|
+
} else {
|
|
85
|
+
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
} else {
|
|
89
|
+
builder.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return builder.build()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@ReactMethod
|
|
96
|
+
fun initialize(promise: Promise) {
|
|
97
|
+
MobileAds.initialize(
|
|
98
|
+
reactApplicationContext,
|
|
99
|
+
OnInitializationCompleteListener { initializationStatus ->
|
|
100
|
+
val result = Arguments.createArray()
|
|
101
|
+
for ((key, value) in initializationStatus.adapterStatusMap) {
|
|
102
|
+
val info = Arguments.createMap();
|
|
103
|
+
info.putString("name", key)
|
|
104
|
+
info.putInt("state", value.initializationState.ordinal)
|
|
105
|
+
info.putString("description", value.description)
|
|
106
|
+
result.pushMap(info);
|
|
107
|
+
}
|
|
108
|
+
promise.resolve(result)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@ReactMethod
|
|
113
|
+
fun setRequestConfiguration(
|
|
114
|
+
requestConfiguration: ReadableMap,
|
|
115
|
+
promise: Promise
|
|
116
|
+
) {
|
|
117
|
+
MobileAds.setRequestConfiguration(buildRequestConfiguration(requestConfiguration))
|
|
118
|
+
promise.resolve(null)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@ReactMethod
|
|
122
|
+
fun openAdInspector(promise: Promise) {
|
|
123
|
+
val activity = currentActivity
|
|
124
|
+
if (activity == null) {
|
|
125
|
+
promise.reject("null-activity", "Ad Inspector attempted to open but the current Activity was null.")
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
activity.runOnUiThread {
|
|
129
|
+
MobileAds.openAdInspector(
|
|
130
|
+
reactApplicationContext,
|
|
131
|
+
OnAdInspectorClosedListener { adInspectorError ->
|
|
132
|
+
if (adInspectorError != null) {
|
|
133
|
+
val code = when (adInspectorError.code) {
|
|
134
|
+
AdInspectorError.ERROR_CODE_INTERNAL_ERROR -> "INTERNAL_ERROR"
|
|
135
|
+
AdInspectorError.ERROR_CODE_FAILED_TO_LOAD -> "FAILED_TO_LOAD"
|
|
136
|
+
AdInspectorError.ERROR_CODE_NOT_IN_TEST_MODE -> "NOT_IN_TEST_MODE"
|
|
137
|
+
AdInspectorError.ERROR_CODE_ALREADY_OPEN -> "ALREADY_OPEN"
|
|
138
|
+
else -> ""
|
|
139
|
+
}
|
|
140
|
+
promise.reject(code, adInspectorError.message)
|
|
141
|
+
} else {
|
|
142
|
+
promise.resolve(null)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@ReactMethod
|
|
151
|
+
fun openDebugMenu(adUnit: String) {
|
|
152
|
+
currentActivity?.runOnUiThread {
|
|
153
|
+
MobileAds.openDebugMenu(currentActivity!!, adUnit)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@ReactMethod
|
|
158
|
+
fun setAppVolume(volume: Float) {
|
|
159
|
+
MobileAds.setAppVolume(volume)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@ReactMethod
|
|
163
|
+
fun setAppMuted(muted: Boolean) {
|
|
164
|
+
MobileAds.setAppMuted(muted)
|
|
165
|
+
}
|
|
166
|
+
}
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.kt
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
package io.invertase.googlemobileads
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import com.facebook.react.ReactPackage
|
|
21
|
+
import com.facebook.react.bridge.NativeModule
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
23
|
+
import com.facebook.react.uimanager.ViewManager
|
|
24
|
+
|
|
25
|
+
@SuppressWarnings("unused")
|
|
26
|
+
class ReactNativeGoogleMobileAdsPackage : ReactPackage {
|
|
27
|
+
override fun createNativeModules(reactContext: ReactApplicationContext) = listOf(
|
|
28
|
+
ReactNativeAppModule(reactContext),
|
|
29
|
+
ReactNativeGoogleMobileAdsModule(reactContext),
|
|
30
|
+
ReactNativeGoogleMobileAdsConsentModule(reactContext),
|
|
31
|
+
ReactNativeGoogleMobileAdsAppOpenModule(reactContext),
|
|
32
|
+
ReactNativeGoogleMobileAdsInterstitialModule(reactContext),
|
|
33
|
+
ReactNativeGoogleMobileAdsRewardedModule(reactContext),
|
|
34
|
+
ReactNativeGoogleMobileAdsRewardedInterstitialModule(reactContext)
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
override fun createViewManagers(
|
|
38
|
+
reactContext: ReactApplicationContext
|
|
39
|
+
): List<ViewManager<*, *>> {
|
|
40
|
+
return listOf(ReactNativeGoogleMobileAdsBannerAdViewManager())
|
|
41
|
+
}
|
|
42
|
+
}
|
package/docs/testing.mdx
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
The React Native Google Mobile Ads library depends on a lot of platform-specific native code which you likely want to mock in your tests.
|
|
4
|
+
|
|
5
|
+
## Testing with Jest
|
|
6
|
+
|
|
7
|
+
This library ships with a Jest setup file that mocks the native code for you.
|
|
8
|
+
To use it, add the following to your Jest configuration:
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
// jest.config.js|ts|mjs|cjs|json
|
|
12
|
+
{
|
|
13
|
+
"setupFiles": [
|
|
14
|
+
"./node_modules/react-native-google-mobile-ads/jest.setup.ts"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
```
|
package/docs.json
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
["European User Consent", "/european-user-consent"],
|
|
19
19
|
["Ad Inspector", "/ad-inspector"],
|
|
20
20
|
["Impression-level ad revenue", "/impression-level-ad-revenue"],
|
|
21
|
-
["Video ad volume control", "/video-ad_volume-control"]
|
|
21
|
+
["Video ad volume control", "/video-ad_volume-control"],
|
|
22
|
+
["Testing", "/testing"]
|
|
22
23
|
]
|
|
23
24
|
],
|
|
24
25
|
[
|
package/jest.setup.ts
CHANGED
|
@@ -3,10 +3,6 @@ import * as ReactNative from 'react-native';
|
|
|
3
3
|
jest.doMock('react-native', () => {
|
|
4
4
|
return Object.setPrototypeOf(
|
|
5
5
|
{
|
|
6
|
-
Platform: {
|
|
7
|
-
OS: 'android',
|
|
8
|
-
select: () => {},
|
|
9
|
-
},
|
|
10
6
|
NativeModules: {
|
|
11
7
|
...ReactNative.NativeModules,
|
|
12
8
|
RNAppModule: {
|
|
@@ -28,6 +24,7 @@ jest.doMock('react-native', () => {
|
|
|
28
24
|
RNGoogleMobileAdsConsentModule: {},
|
|
29
25
|
},
|
|
30
26
|
TurboModuleRegistry: {
|
|
27
|
+
...ReactNative.TurboModuleRegistry,
|
|
31
28
|
getEnforcing: () => {
|
|
32
29
|
return {
|
|
33
30
|
initialize: jest.fn(),
|
package/lib/commonjs/version.js
CHANGED
package/lib/module/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "14.2.
|
|
1
|
+
export declare const SDK_VERSION = "14.2.5";
|
|
2
2
|
export { default, MobileAds } from './MobileAds';
|
|
3
3
|
export { AdsConsentDebugGeography } from './AdsConsentDebugGeography';
|
|
4
4
|
export { AdsConsentPurposes } from './AdsConsentPurposes';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "14.2.
|
|
1
|
+
export declare const version = "14.2.5";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-google-mobile-ads",
|
|
3
|
-
"version": "14.2.
|
|
3
|
+
"version": "14.2.5",
|
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
|
5
5
|
"description": "React Native Google Mobile Ads is an easy way to monetize mobile apps with targeted, in-app advertising.",
|
|
6
6
|
"main": "lib/commonjs/index.js",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"lint:markdown:fix": "prettier --write \"docs/**/*.md[x]\"",
|
|
79
79
|
"lint:report": "eslint --output-file=eslint-report.json --format=json src/ --ext .js,.jsx,.ts,.tsx",
|
|
80
80
|
"lint:spellcheck": "spellchecker --quiet --files=\"docs/**/*.md\" --dictionaries=\"./.spellcheck.dict.txt\" --reports=\"spelling.json\" --plugins spell indefinite-article repeated-words syntax-mentions syntax-urls frontmatter",
|
|
81
|
-
"tsc:compile": "tsc --project .
|
|
81
|
+
"tsc:compile": "tsc --project tsconfig.test.json",
|
|
82
82
|
"lint": "yarn lint:code && yarn tsc:compile",
|
|
83
83
|
"tests:jest": "jest",
|
|
84
84
|
"tests:jest-watch": "jest --watch",
|
|
@@ -146,10 +146,10 @@
|
|
|
146
146
|
"jest": "^29.2.2",
|
|
147
147
|
"metro-react-native-babel-preset": "^0.77.0",
|
|
148
148
|
"prettier": "^2.7.1",
|
|
149
|
-
"react": "^18.
|
|
150
|
-
"react-native": "^0.
|
|
149
|
+
"react": "^18.3.1",
|
|
150
|
+
"react-native": "^0.75.4",
|
|
151
151
|
"react-native-builder-bob": "^0.20.0",
|
|
152
|
-
"react-test-renderer": "^18.
|
|
152
|
+
"react-test-renderer": "^18.3.1",
|
|
153
153
|
"rimraf": "^3.0.2",
|
|
154
154
|
"semantic-release": "^19.0.5",
|
|
155
155
|
"spellchecker-cli": "^6.1.1",
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '14.2.
|
|
2
|
+
export const version = '14.2.5';
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
package io.invertase.googlemobileads;
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this library except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import androidx.annotation.Nullable;
|
|
21
|
-
import com.facebook.react.bridge.Arguments;
|
|
22
|
-
import com.facebook.react.bridge.Promise;
|
|
23
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
24
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
25
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
26
|
-
import com.facebook.react.bridge.WritableArray;
|
|
27
|
-
import com.facebook.react.bridge.WritableMap;
|
|
28
|
-
import com.google.android.gms.ads.AdInspectorError;
|
|
29
|
-
import com.google.android.gms.ads.AdRequest;
|
|
30
|
-
import com.google.android.gms.ads.MobileAds;
|
|
31
|
-
import com.google.android.gms.ads.OnAdInspectorClosedListener;
|
|
32
|
-
import com.google.android.gms.ads.RequestConfiguration;
|
|
33
|
-
import com.google.android.gms.ads.initialization.AdapterStatus;
|
|
34
|
-
import com.google.android.gms.ads.initialization.InitializationStatus;
|
|
35
|
-
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
|
|
36
|
-
import io.invertase.googlemobileads.common.ReactNativeModule;
|
|
37
|
-
import java.util.ArrayList;
|
|
38
|
-
import java.util.List;
|
|
39
|
-
import java.util.Map;
|
|
40
|
-
import java.util.Objects;
|
|
41
|
-
|
|
42
|
-
public class ReactNativeGoogleMobileAdsModule extends ReactNativeModule {
|
|
43
|
-
private static final String SERVICE = "RNGoogleMobileAdsModule";
|
|
44
|
-
|
|
45
|
-
ReactNativeGoogleMobileAdsModule(ReactApplicationContext reactContext) {
|
|
46
|
-
super(reactContext, SERVICE);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
private RequestConfiguration buildRequestConfiguration(ReadableMap requestConfiguration) {
|
|
50
|
-
RequestConfiguration.Builder builder = new RequestConfiguration.Builder();
|
|
51
|
-
|
|
52
|
-
if (requestConfiguration.hasKey("testDeviceIdentifiers")) {
|
|
53
|
-
ArrayList<Object> devices =
|
|
54
|
-
Objects.requireNonNull(requestConfiguration.getArray("testDeviceIdentifiers"))
|
|
55
|
-
.toArrayList();
|
|
56
|
-
|
|
57
|
-
List<String> testDeviceIds = new ArrayList<>();
|
|
58
|
-
|
|
59
|
-
for (Object device : devices) {
|
|
60
|
-
String id = (String) device;
|
|
61
|
-
|
|
62
|
-
if (id.equals("EMULATOR")) {
|
|
63
|
-
testDeviceIds.add(AdRequest.DEVICE_ID_EMULATOR);
|
|
64
|
-
} else {
|
|
65
|
-
testDeviceIds.add(id);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
builder.setTestDeviceIds(testDeviceIds);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (requestConfiguration.hasKey("maxAdContentRating")) {
|
|
72
|
-
String rating = requestConfiguration.getString("maxAdContentRating");
|
|
73
|
-
|
|
74
|
-
switch (Objects.requireNonNull(rating)) {
|
|
75
|
-
case "G":
|
|
76
|
-
builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G);
|
|
77
|
-
break;
|
|
78
|
-
case "PG":
|
|
79
|
-
builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG);
|
|
80
|
-
break;
|
|
81
|
-
case "T":
|
|
82
|
-
builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T);
|
|
83
|
-
break;
|
|
84
|
-
case "MA":
|
|
85
|
-
builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA);
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (requestConfiguration.hasKey("tagForChildDirectedTreatment")) {
|
|
91
|
-
boolean tagForChildDirectedTreatment =
|
|
92
|
-
requestConfiguration.getBoolean("tagForChildDirectedTreatment");
|
|
93
|
-
if (tagForChildDirectedTreatment) {
|
|
94
|
-
builder.setTagForChildDirectedTreatment(
|
|
95
|
-
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);
|
|
96
|
-
} else {
|
|
97
|
-
builder.setTagForChildDirectedTreatment(
|
|
98
|
-
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);
|
|
99
|
-
}
|
|
100
|
-
} else {
|
|
101
|
-
builder.setTagForChildDirectedTreatment(
|
|
102
|
-
RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (requestConfiguration.hasKey("tagForUnderAgeOfConsent")) {
|
|
106
|
-
boolean tagForUnderAgeOfConsent = requestConfiguration.getBoolean("tagForUnderAgeOfConsent");
|
|
107
|
-
if (tagForUnderAgeOfConsent) {
|
|
108
|
-
builder.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);
|
|
109
|
-
} else {
|
|
110
|
-
builder.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
builder.setTagForUnderAgeOfConsent(
|
|
114
|
-
RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return builder.build();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@ReactMethod
|
|
121
|
-
public void initialize(Promise promise) {
|
|
122
|
-
MobileAds.initialize(
|
|
123
|
-
getApplicationContext(),
|
|
124
|
-
new OnInitializationCompleteListener() {
|
|
125
|
-
@Override
|
|
126
|
-
public void onInitializationComplete(InitializationStatus initializationStatus) {
|
|
127
|
-
WritableArray result = Arguments.createArray();
|
|
128
|
-
for (Map.Entry<String, AdapterStatus> entry :
|
|
129
|
-
initializationStatus.getAdapterStatusMap().entrySet()) {
|
|
130
|
-
WritableMap info = Arguments.createMap();
|
|
131
|
-
info.putString("name", entry.getKey());
|
|
132
|
-
info.putInt("state", entry.getValue().getInitializationState().ordinal());
|
|
133
|
-
info.putString("description", entry.getValue().getDescription());
|
|
134
|
-
result.pushMap(info);
|
|
135
|
-
}
|
|
136
|
-
promise.resolve(result);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
@ReactMethod
|
|
142
|
-
public void setRequestConfiguration(ReadableMap requestConfiguration, Promise promise) {
|
|
143
|
-
MobileAds.setRequestConfiguration(buildRequestConfiguration(requestConfiguration));
|
|
144
|
-
promise.resolve(null);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
@ReactMethod
|
|
148
|
-
public void openAdInspector(Promise promise) {
|
|
149
|
-
if (getCurrentActivity() == null) {
|
|
150
|
-
rejectPromiseWithCodeAndMessage(
|
|
151
|
-
promise,
|
|
152
|
-
"null-activity",
|
|
153
|
-
"Ad Inspector attempted to open but the current Activity was null.");
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
getCurrentActivity()
|
|
157
|
-
.runOnUiThread(
|
|
158
|
-
() -> {
|
|
159
|
-
MobileAds.openAdInspector(
|
|
160
|
-
getApplicationContext(),
|
|
161
|
-
new OnAdInspectorClosedListener() {
|
|
162
|
-
@Override
|
|
163
|
-
public void onAdInspectorClosed(@Nullable AdInspectorError adInspectorError) {
|
|
164
|
-
if (adInspectorError != null) {
|
|
165
|
-
String code = "";
|
|
166
|
-
switch (adInspectorError.getCode()) {
|
|
167
|
-
case AdInspectorError.ERROR_CODE_INTERNAL_ERROR:
|
|
168
|
-
code = "INTERNAL_ERROR";
|
|
169
|
-
break;
|
|
170
|
-
case AdInspectorError.ERROR_CODE_FAILED_TO_LOAD:
|
|
171
|
-
code = "FAILED_TO_LOAD";
|
|
172
|
-
break;
|
|
173
|
-
case AdInspectorError.ERROR_CODE_NOT_IN_TEST_MODE:
|
|
174
|
-
code = "NOT_IN_TEST_MODE";
|
|
175
|
-
break;
|
|
176
|
-
case AdInspectorError.ERROR_CODE_ALREADY_OPEN:
|
|
177
|
-
code = "ALREADY_OPEN";
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
rejectPromiseWithCodeAndMessage(
|
|
181
|
-
promise, code, adInspectorError.getMessage());
|
|
182
|
-
} else {
|
|
183
|
-
promise.resolve(null);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
@ReactMethod
|
|
191
|
-
public void openDebugMenu(final String adUnit) {
|
|
192
|
-
if (getCurrentActivity() != null) {
|
|
193
|
-
getCurrentActivity()
|
|
194
|
-
.runOnUiThread(() -> MobileAds.openDebugMenu(getCurrentActivity(), adUnit));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
@ReactMethod
|
|
199
|
-
public void setAppVolume(final Float volume) {
|
|
200
|
-
MobileAds.setAppVolume(volume);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@ReactMethod
|
|
204
|
-
public void setAppMuted(final Boolean muted) {
|
|
205
|
-
MobileAds.setAppMuted(muted);
|
|
206
|
-
}
|
|
207
|
-
}
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
package io.invertase.googlemobileads;
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this library except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import com.facebook.react.ReactPackage;
|
|
21
|
-
import com.facebook.react.bridge.NativeModule;
|
|
22
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
23
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
24
|
-
import java.util.ArrayList;
|
|
25
|
-
import java.util.Arrays;
|
|
26
|
-
import java.util.List;
|
|
27
|
-
import javax.annotation.Nonnull;
|
|
28
|
-
|
|
29
|
-
@SuppressWarnings("unused")
|
|
30
|
-
public class ReactNativeGoogleMobileAdsPackage implements ReactPackage {
|
|
31
|
-
@Override
|
|
32
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
33
|
-
List<NativeModule> modules = new ArrayList<>();
|
|
34
|
-
modules.add(new ReactNativeAppModule(reactContext));
|
|
35
|
-
modules.add(new ReactNativeGoogleMobileAdsModule(reactContext));
|
|
36
|
-
modules.add(new ReactNativeGoogleMobileAdsConsentModule(reactContext));
|
|
37
|
-
modules.add(new ReactNativeGoogleMobileAdsAppOpenModule(reactContext));
|
|
38
|
-
modules.add(new ReactNativeGoogleMobileAdsInterstitialModule(reactContext));
|
|
39
|
-
modules.add(new ReactNativeGoogleMobileAdsRewardedModule(reactContext));
|
|
40
|
-
modules.add(new ReactNativeGoogleMobileAdsRewardedInterstitialModule(reactContext));
|
|
41
|
-
return modules;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@Nonnull
|
|
45
|
-
@Override
|
|
46
|
-
public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) {
|
|
47
|
-
return Arrays.asList(new ReactNativeGoogleMobileAdsBannerAdViewManager());
|
|
48
|
-
}
|
|
49
|
-
}
|