react-native-google-mobile-ads 6.3.0 → 8.0.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 +1 -1
- package/android/build.gradle +32 -3
- package/android/src/main/AndroidManifest.xml +6 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAdHelper.kt +106 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.kt +74 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsFullScreenAdModule.kt +245 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.kt +74 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.kt +74 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.kt +74 -0
- package/docs/displaying-ads-hook.mdx +1 -1
- package/docs/displaying-ads.mdx +1 -1
- package/docs/european-user-consent.mdx +3 -2
- package/docs/index.mdx +5 -1
- package/docs/migrating-to-v6.mdx +2 -2
- package/ios/RNGoogleMobileAds/RNGoogleMobileAds-Bridging-Header.h +5 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +13 -68
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.swift +82 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenAd.swift +208 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.swift +72 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +13 -107
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.swift +119 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +13 -144
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.swift +81 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +13 -143
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.swift +81 -0
- package/ios_config.sh +10 -0
- package/lib/commonjs/hooks/useFullScreenAd.js +2 -1
- package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/hooks/useFullScreenAd.js +2 -1
- package/lib/module/hooks/useFullScreenAd.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/hooks/useFullScreenAd.ts +1 -1
- package/src/version.ts +1 -1
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +0 -159
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +0 -178
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +0 -199
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +0 -176
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +0 -29
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +0 -33
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +0 -72
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +0 -25
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +0 -25
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +0 -25
|
@@ -18,7 +18,7 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
s.source = { :git => "#{package["repository"]["url"]}.git", :tag => "v#{s.version}" }
|
|
19
19
|
s.social_media_url = 'http://twitter.com/invertaseio'
|
|
20
20
|
s.ios.deployment_target = "10.0"
|
|
21
|
-
s.source_files = 'ios/**/*.{h,m}'
|
|
21
|
+
s.source_files = 'ios/**/*.{h,m,swift}'
|
|
22
22
|
s.weak_frameworks = "AppTrackingTransparency"
|
|
23
23
|
|
|
24
24
|
# React Native dependencies
|
package/android/build.gradle
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import io.invertase.gradle.common.PackageJson
|
|
2
2
|
|
|
3
3
|
buildscript {
|
|
4
|
+
ext.getExtOrDefault = {name, version ->
|
|
5
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : version
|
|
6
|
+
}
|
|
7
|
+
|
|
4
8
|
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
|
5
9
|
// This avoids unnecessary downloads and potential conflicts when the library is included as a
|
|
6
10
|
// module dependency in an application project.
|
|
@@ -12,6 +16,15 @@ buildscript {
|
|
|
12
16
|
|
|
13
17
|
dependencies {
|
|
14
18
|
classpath("com.android.tools.build:gradle:7.0.4")
|
|
19
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion', '1.6.10')}"
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
repositories {
|
|
23
|
+
mavenCentral()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
dependencies {
|
|
27
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion', '1.6.10')}"
|
|
15
28
|
}
|
|
16
29
|
}
|
|
17
30
|
}
|
|
@@ -19,6 +32,7 @@ buildscript {
|
|
|
19
32
|
plugins {
|
|
20
33
|
id "io.invertase.gradle.build" version "1.5"
|
|
21
34
|
}
|
|
35
|
+
apply plugin: 'kotlin-android'
|
|
22
36
|
|
|
23
37
|
def packageJson = PackageJson.getForProject(project)
|
|
24
38
|
def googleMobileAdsVersion = packageJson['sdkVersions']['android']['googleMobileAds']
|
|
@@ -53,16 +67,28 @@ project.ext {
|
|
|
53
67
|
|
|
54
68
|
apply from: file("./app-json.gradle")
|
|
55
69
|
|
|
56
|
-
def appJSONGoogleMobileAdsAppIDString
|
|
70
|
+
def appJSONGoogleMobileAdsAppIDString
|
|
57
71
|
def appJSONGoogleMobileAdsDelayAppMeasurementInitBool = false
|
|
72
|
+
def appJSONGoogleMobileAdsOptimizeInitializationBool = true
|
|
73
|
+
def appJSONGoogleMobileAdsOptimizeAdLoadingBool = true
|
|
58
74
|
|
|
59
75
|
if (rootProject.ext.googleMobileAdsJson) {
|
|
60
76
|
appJSONGoogleMobileAdsAppIDString = rootProject.ext.googleMobileAdsJson.getStringValue("android_app_id", "")
|
|
61
77
|
appJSONGoogleMobileAdsDelayAppMeasurementInitBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("delay_app_measurement_init", false)
|
|
78
|
+
appJSONGoogleMobileAdsOptimizeInitializationBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("optimize_initialization", true)
|
|
79
|
+
appJSONGoogleMobileAdsOptimizeAdLoadingBool = rootProject.ext.googleMobileAdsJson.isFlagEnabled("optimize_ad_loading", true)
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
if (!appJSONGoogleMobileAdsAppIDString) {
|
|
65
|
-
|
|
83
|
+
println "\n\n\n"
|
|
84
|
+
println "**************************************************************************************************************"
|
|
85
|
+
println "\n\n\n"
|
|
86
|
+
println "ERROR: react-native-google-mobile-ads requires an 'android_app_id' property inside a 'react-native-google-mobile-ads' key in your app.json."
|
|
87
|
+
println " No android_app_id property was found in this location. The native Google Mobile Ads SDK will crash on startup without it."
|
|
88
|
+
println "\n\n\n"
|
|
89
|
+
println "**************************************************************************************************************"
|
|
90
|
+
println "\n\n\n"
|
|
91
|
+
System.exit(1)
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
android {
|
|
@@ -70,7 +96,9 @@ android {
|
|
|
70
96
|
multiDexEnabled true
|
|
71
97
|
manifestPlaceholders = [
|
|
72
98
|
appJSONGoogleMobileAdsAppID : appJSONGoogleMobileAdsAppIDString,
|
|
73
|
-
appJSONGoogleMobileAdsDelayAppMeasurementInit: appJSONGoogleMobileAdsDelayAppMeasurementInitBool
|
|
99
|
+
appJSONGoogleMobileAdsDelayAppMeasurementInit: appJSONGoogleMobileAdsDelayAppMeasurementInitBool,
|
|
100
|
+
appJSONGoogleMobileAdsOptimizeInitialization : appJSONGoogleMobileAdsOptimizeInitializationBool,
|
|
101
|
+
appJSONGoogleMobileAdsOptimizeAdLoading : appJSONGoogleMobileAdsOptimizeAdLoadingBool
|
|
74
102
|
]
|
|
75
103
|
}
|
|
76
104
|
lintOptions {
|
|
@@ -97,3 +125,4 @@ ReactNative.shared.applyPackageVersion()
|
|
|
97
125
|
ReactNative.shared.applyDefaultExcludes()
|
|
98
126
|
ReactNative.module.applyAndroidVersions()
|
|
99
127
|
ReactNative.module.applyReactNativeDependency("api")
|
|
128
|
+
|
|
@@ -13,5 +13,11 @@
|
|
|
13
13
|
<meta-data
|
|
14
14
|
android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
|
|
15
15
|
android:value="${appJSONGoogleMobileAdsDelayAppMeasurementInit}"/>
|
|
16
|
+
<meta-data
|
|
17
|
+
android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
|
|
18
|
+
android:value="${appJSONGoogleMobileAdsOptimizeInitialization}"/>
|
|
19
|
+
<meta-data
|
|
20
|
+
android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
|
|
21
|
+
android:value="${appJSONGoogleMobileAdsOptimizeAdLoading}"/>
|
|
16
22
|
</application>
|
|
17
23
|
</manifest>
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAdHelper.kt
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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 android.app.Activity
|
|
21
|
+
import com.google.android.gms.ads.AdLoadCallback
|
|
22
|
+
import com.google.android.gms.ads.FullScreenContentCallback
|
|
23
|
+
import com.google.android.gms.ads.LoadAdError
|
|
24
|
+
import com.google.android.gms.ads.OnUserEarnedRewardListener
|
|
25
|
+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
|
|
26
|
+
import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
|
|
27
|
+
import com.google.android.gms.ads.admanager.AppEventListener
|
|
28
|
+
import com.google.android.gms.ads.appopen.AppOpenAd
|
|
29
|
+
import com.google.android.gms.ads.interstitial.InterstitialAd
|
|
30
|
+
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
|
|
31
|
+
import com.google.android.gms.ads.rewarded.RewardItem
|
|
32
|
+
import com.google.android.gms.ads.rewarded.RewardedAd
|
|
33
|
+
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
|
|
34
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions
|
|
35
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
|
|
36
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
|
|
37
|
+
|
|
38
|
+
class ReactNativeGoogleMobileAdsAdHelper<T>(private val ad: T) {
|
|
39
|
+
fun show(activity: Activity, onUserEarnedRewardListener: OnUserEarnedRewardListener?) {
|
|
40
|
+
when (ad) {
|
|
41
|
+
is AppOpenAd, is InterstitialAd -> {
|
|
42
|
+
val method = ad.javaClass.getMethod("show", Activity::class.java)
|
|
43
|
+
method.invoke(ad, activity)
|
|
44
|
+
}
|
|
45
|
+
is RewardedAd, is RewardedInterstitialAd -> {
|
|
46
|
+
val method = ad.javaClass.getMethod(
|
|
47
|
+
"show",
|
|
48
|
+
Activity::class.java,
|
|
49
|
+
OnUserEarnedRewardListener::class.java
|
|
50
|
+
)
|
|
51
|
+
method.invoke(ad, activity, onUserEarnedRewardListener)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fun setFullScreenContentCallback(fullScreenContentCallback: FullScreenContentCallback) {
|
|
57
|
+
when (ad) {
|
|
58
|
+
is AppOpenAd, is InterstitialAd, is RewardedAd, is RewardedInterstitialAd -> {
|
|
59
|
+
val method = ad.javaClass.getMethod(
|
|
60
|
+
"setFullScreenContentCallback",
|
|
61
|
+
FullScreenContentCallback::class.java
|
|
62
|
+
)
|
|
63
|
+
method.invoke(ad, fullScreenContentCallback)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
fun setAppEventListener(appEventListener: AppEventListener) {
|
|
69
|
+
if (ad is AdManagerInterstitialAd) {
|
|
70
|
+
val method = ad.javaClass.getMethod("setAppEventListener", AppEventListener::class.java)
|
|
71
|
+
method.invoke(ad, appEventListener)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fun setImmersiveMode(enabled: Boolean) {
|
|
76
|
+
when (ad) {
|
|
77
|
+
is AppOpenAd, is InterstitialAd, is RewardedAd, is RewardedInterstitialAd -> {
|
|
78
|
+
val method = ad.javaClass.getMethod("setImmersiveMode", Boolean::class.javaPrimitiveType)
|
|
79
|
+
method.invoke(ad, enabled)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
fun setServerSideVerificationOptions(serverSideVerificationOptions: ServerSideVerificationOptions) {
|
|
85
|
+
when (ad) {
|
|
86
|
+
is RewardedAd, is RewardedInterstitialAd -> {
|
|
87
|
+
val method = ad.javaClass.getMethod(
|
|
88
|
+
"setServerSideVerificationOptions",
|
|
89
|
+
ServerSideVerificationOptions::class.java
|
|
90
|
+
)
|
|
91
|
+
method.invoke(ad, serverSideVerificationOptions)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
val rewardItem: RewardItem
|
|
97
|
+
get() {
|
|
98
|
+
when (ad) {
|
|
99
|
+
is RewardedAd, is RewardedInterstitialAd -> {
|
|
100
|
+
val method = ad.javaClass.getMethod("getRewardItem")
|
|
101
|
+
return method.invoke(ad) as RewardItem
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
throw IllegalStateException("Ad type not supported")
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 android.app.Activity
|
|
21
|
+
import com.facebook.react.bridge.Promise
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
23
|
+
import com.facebook.react.bridge.ReactMethod
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap
|
|
25
|
+
import com.google.android.gms.ads.AdLoadCallback
|
|
26
|
+
import com.google.android.gms.ads.LoadAdError
|
|
27
|
+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
|
|
28
|
+
import com.google.android.gms.ads.appopen.AppOpenAd
|
|
29
|
+
|
|
30
|
+
class ReactNativeGoogleMobileAdsAppOpenModule(reactContext: ReactApplicationContext?) :
|
|
31
|
+
ReactNativeGoogleMobileAdsFullScreenAdModule<AppOpenAd>(reactContext, NAME) {
|
|
32
|
+
|
|
33
|
+
override fun getAdEventName(): String {
|
|
34
|
+
return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_OPEN
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun appOpenLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
|
|
39
|
+
load(requestId, adUnitId, adRequestOptions)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
fun appOpenShow(
|
|
44
|
+
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
|
|
45
|
+
) {
|
|
46
|
+
show(requestId, adUnitId, showOptions, promise)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun loadAd(
|
|
50
|
+
activity: Activity,
|
|
51
|
+
adUnitId: String,
|
|
52
|
+
adRequest: AdManagerAdRequest,
|
|
53
|
+
adLoadCallback: AdLoadCallback<AppOpenAd>
|
|
54
|
+
) {
|
|
55
|
+
AppOpenAd.load(
|
|
56
|
+
activity,
|
|
57
|
+
adUnitId,
|
|
58
|
+
adRequest,
|
|
59
|
+
AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT,
|
|
60
|
+
object :
|
|
61
|
+
AppOpenAd.AppOpenAdLoadCallback() {
|
|
62
|
+
override fun onAdLoaded(ad: AppOpenAd) {
|
|
63
|
+
adLoadCallback.onAdLoaded(ad)
|
|
64
|
+
}
|
|
65
|
+
override fun onAdFailedToLoad(error: LoadAdError) {
|
|
66
|
+
adLoadCallback.onAdFailedToLoad(error)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
companion object {
|
|
72
|
+
const val NAME = "RNGoogleMobileAdsAppOpenModule"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
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 android.app.Activity
|
|
21
|
+
import android.util.SparseArray
|
|
22
|
+
import com.facebook.react.bridge.*
|
|
23
|
+
import com.google.android.gms.ads.AdLoadCallback
|
|
24
|
+
import com.google.android.gms.ads.FullScreenContentCallback
|
|
25
|
+
import com.google.android.gms.ads.LoadAdError
|
|
26
|
+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
|
|
27
|
+
import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
|
|
28
|
+
import com.google.android.gms.ads.rewarded.RewardedAd
|
|
29
|
+
import com.google.android.gms.ads.rewarded.ServerSideVerificationOptions
|
|
30
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
|
|
31
|
+
import io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_EVENT
|
|
32
|
+
import io.invertase.googlemobileads.common.ReactNativeModule
|
|
33
|
+
|
|
34
|
+
abstract class ReactNativeGoogleMobileAdsFullScreenAdModule<T>(
|
|
35
|
+
reactContext: ReactApplicationContext?,
|
|
36
|
+
moduleName: String
|
|
37
|
+
) : ReactNativeModule(reactContext, moduleName) {
|
|
38
|
+
private val adArray = SparseArray<T>()
|
|
39
|
+
|
|
40
|
+
abstract fun getAdEventName(): String
|
|
41
|
+
|
|
42
|
+
abstract fun loadAd(
|
|
43
|
+
activity: Activity,
|
|
44
|
+
adUnitId: String,
|
|
45
|
+
adRequest: AdManagerAdRequest,
|
|
46
|
+
adLoadCallback: AdLoadCallback<T>
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
private fun sendAdEvent(
|
|
50
|
+
type: String,
|
|
51
|
+
requestId: Int,
|
|
52
|
+
adUnitId: String,
|
|
53
|
+
error: WritableMap?,
|
|
54
|
+
data: WritableMap?
|
|
55
|
+
) {
|
|
56
|
+
ReactNativeGoogleMobileAdsCommon.sendAdEvent(
|
|
57
|
+
getAdEventName(),
|
|
58
|
+
requestId,
|
|
59
|
+
type,
|
|
60
|
+
adUnitId,
|
|
61
|
+
error,
|
|
62
|
+
data
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fun load(
|
|
67
|
+
requestId: Int, adUnitId: String, adRequestOptions: ReadableMap
|
|
68
|
+
) {
|
|
69
|
+
val activity = currentActivity
|
|
70
|
+
if (activity == null) {
|
|
71
|
+
val error = Arguments.createMap()
|
|
72
|
+
error.putString("code", "null-activity")
|
|
73
|
+
error.putString(
|
|
74
|
+
"message",
|
|
75
|
+
"Ad attempted to load but the current Activity was null."
|
|
76
|
+
)
|
|
77
|
+
sendAdEvent(
|
|
78
|
+
ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR,
|
|
79
|
+
requestId,
|
|
80
|
+
adUnitId,
|
|
81
|
+
error,
|
|
82
|
+
null
|
|
83
|
+
)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
val adRequest = ReactNativeGoogleMobileAdsCommon.buildAdRequest(adRequestOptions)
|
|
87
|
+
val adLoadCallback = ReactNativeGoogleMobileAdsAdLoadCallback(
|
|
88
|
+
requestId,
|
|
89
|
+
adUnitId,
|
|
90
|
+
adRequestOptions
|
|
91
|
+
)
|
|
92
|
+
activity.runOnUiThread {
|
|
93
|
+
loadAd(
|
|
94
|
+
activity,
|
|
95
|
+
adUnitId,
|
|
96
|
+
adRequest,
|
|
97
|
+
adLoadCallback
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fun show(
|
|
103
|
+
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
|
|
104
|
+
) {
|
|
105
|
+
val activity = currentActivity
|
|
106
|
+
if (activity == null) {
|
|
107
|
+
rejectPromiseWithCodeAndMessage(
|
|
108
|
+
promise,
|
|
109
|
+
"null-activity",
|
|
110
|
+
"Ad attempted to show but the current Activity was null."
|
|
111
|
+
)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
activity.runOnUiThread {
|
|
115
|
+
val ad = adArray[requestId]
|
|
116
|
+
val adHelper = ReactNativeGoogleMobileAdsAdHelper(ad)
|
|
117
|
+
|
|
118
|
+
var immersiveModeEnabled = false
|
|
119
|
+
if (showOptions.hasKey("immersiveModeEnabled")) {
|
|
120
|
+
immersiveModeEnabled = showOptions.getBoolean("immersiveModeEnabled")
|
|
121
|
+
}
|
|
122
|
+
adHelper.setImmersiveMode(immersiveModeEnabled)
|
|
123
|
+
|
|
124
|
+
adHelper.show(activity) { rewardItem ->
|
|
125
|
+
val data = Arguments.createMap()
|
|
126
|
+
data.putString("type", rewardItem.type)
|
|
127
|
+
data.putInt("amount", rewardItem.amount)
|
|
128
|
+
sendAdEvent(
|
|
129
|
+
ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD,
|
|
130
|
+
requestId,
|
|
131
|
+
adUnitId,
|
|
132
|
+
null,
|
|
133
|
+
data
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
promise.resolve(null)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
inner class ReactNativeGoogleMobileAdsAdLoadCallback(
|
|
141
|
+
private val requestId: Int,
|
|
142
|
+
private val adUnitId: String,
|
|
143
|
+
private val adRequestOptions: ReadableMap
|
|
144
|
+
) : AdLoadCallback<T>() {
|
|
145
|
+
override fun onAdLoaded(ad: T) {
|
|
146
|
+
val adHelper = ReactNativeGoogleMobileAdsAdHelper(ad)
|
|
147
|
+
var eventType = ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_LOADED
|
|
148
|
+
var data: WritableMap? = null
|
|
149
|
+
|
|
150
|
+
if (ad is RewardedAd || ad is RewardedInterstitialAd) {
|
|
151
|
+
eventType = ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED
|
|
152
|
+
|
|
153
|
+
val rewardItem = adHelper.rewardItem
|
|
154
|
+
data = Arguments.createMap()
|
|
155
|
+
data.putString("type", rewardItem.type)
|
|
156
|
+
data.putInt("amount", rewardItem.amount)
|
|
157
|
+
|
|
158
|
+
adRequestOptions.getMap("serverSideVerificationOptions")
|
|
159
|
+
?.let { serverSideVerificationOptions ->
|
|
160
|
+
val options =
|
|
161
|
+
ServerSideVerificationOptions.Builder()
|
|
162
|
+
serverSideVerificationOptions.getString("userId")?.let {
|
|
163
|
+
options.setUserId(it)
|
|
164
|
+
}
|
|
165
|
+
serverSideVerificationOptions.getString("customData")?.let {
|
|
166
|
+
options.setCustomData(it)
|
|
167
|
+
}
|
|
168
|
+
adHelper.setServerSideVerificationOptions(options.build())
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (ad is AdManagerInterstitialAd) {
|
|
173
|
+
adHelper.setAppEventListener { name, eventData ->
|
|
174
|
+
val payload = Arguments.createMap()
|
|
175
|
+
payload.putString("name", name)
|
|
176
|
+
payload.putString("data", eventData)
|
|
177
|
+
sendAdEvent(
|
|
178
|
+
GOOGLE_MOBILE_ADS_EVENT_APP_EVENT,
|
|
179
|
+
requestId,
|
|
180
|
+
adUnitId,
|
|
181
|
+
null,
|
|
182
|
+
payload
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
val fullScreenContentCallback: FullScreenContentCallback =
|
|
188
|
+
object : FullScreenContentCallback() {
|
|
189
|
+
override fun onAdShowedFullScreenContent() {
|
|
190
|
+
sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_OPENED)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
override fun onAdDismissedFullScreenContent() {
|
|
194
|
+
sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
override fun onAdClicked() {
|
|
198
|
+
sendAdEvent(ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLICKED)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
override fun onAdImpression() {
|
|
202
|
+
// Not Implemented Yet
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private fun sendAdEvent(type: String) {
|
|
206
|
+
sendAdEvent(
|
|
207
|
+
type,
|
|
208
|
+
requestId,
|
|
209
|
+
adUnitId,
|
|
210
|
+
null,
|
|
211
|
+
null
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
adHelper.setFullScreenContentCallback(fullScreenContentCallback)
|
|
216
|
+
|
|
217
|
+
adArray.put(
|
|
218
|
+
requestId,
|
|
219
|
+
ad
|
|
220
|
+
)
|
|
221
|
+
sendAdEvent(
|
|
222
|
+
eventType,
|
|
223
|
+
requestId,
|
|
224
|
+
adUnitId,
|
|
225
|
+
null,
|
|
226
|
+
data
|
|
227
|
+
)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
|
|
231
|
+
val error = Arguments.createMap()
|
|
232
|
+
val codeAndMessage =
|
|
233
|
+
ReactNativeGoogleMobileAdsCommon.getCodeAndMessageFromAdError(loadAdError)
|
|
234
|
+
error.putString("code", codeAndMessage[0])
|
|
235
|
+
error.putString("message", codeAndMessage[1])
|
|
236
|
+
sendAdEvent(
|
|
237
|
+
ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR,
|
|
238
|
+
requestId,
|
|
239
|
+
adUnitId,
|
|
240
|
+
error,
|
|
241
|
+
null
|
|
242
|
+
)
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 android.app.Activity
|
|
21
|
+
import com.facebook.react.bridge.Promise
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
23
|
+
import com.facebook.react.bridge.ReactMethod
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap
|
|
25
|
+
import com.google.android.gms.ads.AdLoadCallback
|
|
26
|
+
import com.google.android.gms.ads.LoadAdError
|
|
27
|
+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
|
|
28
|
+
import com.google.android.gms.ads.admanager.AdManagerInterstitialAd
|
|
29
|
+
import com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback
|
|
30
|
+
|
|
31
|
+
class ReactNativeGoogleMobileAdsInterstitialModule(reactContext: ReactApplicationContext?) :
|
|
32
|
+
ReactNativeGoogleMobileAdsFullScreenAdModule<AdManagerInterstitialAd>(reactContext, NAME) {
|
|
33
|
+
|
|
34
|
+
override fun getAdEventName(): String {
|
|
35
|
+
return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
fun interstitialLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
|
|
40
|
+
load(requestId, adUnitId, adRequestOptions)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun interstitialShow(
|
|
45
|
+
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
|
|
46
|
+
) {
|
|
47
|
+
show(requestId, adUnitId, showOptions, promise)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun loadAd(
|
|
51
|
+
activity: Activity,
|
|
52
|
+
adUnitId: String,
|
|
53
|
+
adRequest: AdManagerAdRequest,
|
|
54
|
+
adLoadCallback: AdLoadCallback<AdManagerInterstitialAd>
|
|
55
|
+
) {
|
|
56
|
+
AdManagerInterstitialAd.load(
|
|
57
|
+
activity,
|
|
58
|
+
adUnitId,
|
|
59
|
+
adRequest,
|
|
60
|
+
object :
|
|
61
|
+
AdManagerInterstitialAdLoadCallback() {
|
|
62
|
+
override fun onAdLoaded(ad: AdManagerInterstitialAd) {
|
|
63
|
+
adLoadCallback.onAdLoaded(ad)
|
|
64
|
+
}
|
|
65
|
+
override fun onAdFailedToLoad(error: LoadAdError) {
|
|
66
|
+
adLoadCallback.onAdFailedToLoad(error)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
companion object {
|
|
72
|
+
const val NAME = "RNGoogleMobileAdsInterstitialModule"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
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 android.app.Activity
|
|
21
|
+
import com.facebook.react.bridge.Promise
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
23
|
+
import com.facebook.react.bridge.ReactMethod
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap
|
|
25
|
+
import com.google.android.gms.ads.AdLoadCallback
|
|
26
|
+
import com.google.android.gms.ads.LoadAdError
|
|
27
|
+
import com.google.android.gms.ads.admanager.AdManagerAdRequest
|
|
28
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd
|
|
29
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback
|
|
30
|
+
|
|
31
|
+
class ReactNativeGoogleMobileAdsRewardedInterstitialModule(reactContext: ReactApplicationContext?) :
|
|
32
|
+
ReactNativeGoogleMobileAdsFullScreenAdModule<RewardedInterstitialAd>(reactContext, NAME) {
|
|
33
|
+
|
|
34
|
+
override fun getAdEventName(): String {
|
|
35
|
+
return ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
fun rewardedInterstitialLoad(requestId: Int, adUnitId: String, adRequestOptions: ReadableMap) {
|
|
40
|
+
load(requestId, adUnitId, adRequestOptions)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun rewardedInterstitialShow(
|
|
45
|
+
requestId: Int, adUnitId: String, showOptions: ReadableMap, promise: Promise
|
|
46
|
+
) {
|
|
47
|
+
show(requestId, adUnitId, showOptions, promise)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun loadAd(
|
|
51
|
+
activity: Activity,
|
|
52
|
+
adUnitId: String,
|
|
53
|
+
adRequest: AdManagerAdRequest,
|
|
54
|
+
adLoadCallback: AdLoadCallback<RewardedInterstitialAd>
|
|
55
|
+
) {
|
|
56
|
+
RewardedInterstitialAd.load(
|
|
57
|
+
activity,
|
|
58
|
+
adUnitId,
|
|
59
|
+
adRequest,
|
|
60
|
+
object :
|
|
61
|
+
RewardedInterstitialAdLoadCallback() {
|
|
62
|
+
override fun onAdLoaded(ad: RewardedInterstitialAd) {
|
|
63
|
+
adLoadCallback.onAdLoaded(ad)
|
|
64
|
+
}
|
|
65
|
+
override fun onAdFailedToLoad(error: LoadAdError) {
|
|
66
|
+
adLoadCallback.onAdFailedToLoad(error)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
companion object {
|
|
72
|
+
const val NAME = "RNGoogleMobileAdsRewardedInterstitialModule"
|
|
73
|
+
}
|
|
74
|
+
}
|