react-native-google-mobile-ads 14.7.1 → 14.8.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/README.md +86 -1
- package/android/build.gradle +10 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +2 -2
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +2 -2
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsMediaView.kt +57 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsMediaViewManager.kt +55 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt +5 -4
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeAdView.kt +107 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeAdViewManager.kt +85 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeModule.kt +211 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.kt +102 -13
- package/android/src/oldarch/com/facebook/react/viewmanagers/RNGoogleMobileAdsMediaViewManagerDelegate.java +29 -0
- package/android/src/oldarch/com/facebook/react/viewmanagers/RNGoogleMobileAdsMediaViewManagerInterface.java +10 -0
- package/android/src/oldarch/com/facebook/react/viewmanagers/RNGoogleMobileAdsNativeViewManagerDelegate.java +33 -0
- package/android/src/oldarch/com/facebook/react/viewmanagers/RNGoogleMobileAdsNativeViewManagerInterface.java +10 -0
- package/android/src/oldarch/io/invertase/googlemobileads/NativeGoogleMobileAdsNativeModuleSpec.kt +18 -0
- package/docs/displaying-ads.mdx +4 -0
- package/docs/european-user-consent.mdx +2 -0
- package/docs/index.mdx +5 -4
- package/docs/native-ads.mdx +365 -0
- package/docs.json +1 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsMediaView.h +49 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsMediaView.mm +152 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.h +35 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeModule.mm +290 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeView.h +48 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsNativeView.mm +218 -0
- package/jest.setup.ts +7 -0
- package/lib/commonjs/NativeAdEventType.js +19 -0
- package/lib/commonjs/NativeAdEventType.js.map +1 -0
- package/lib/commonjs/TestIds.js +15 -8
- package/lib/commonjs/TestIds.js.map +1 -1
- package/lib/commonjs/ads/native-ad/NativeAd.js +122 -0
- package/lib/commonjs/ads/native-ad/NativeAd.js.map +1 -0
- package/lib/commonjs/ads/native-ad/NativeAdContext.js +26 -0
- package/lib/commonjs/ads/native-ad/NativeAdContext.js.map +1 -0
- package/lib/commonjs/ads/native-ad/NativeAdView.js +48 -0
- package/lib/commonjs/ads/native-ad/NativeAdView.js.map +1 -0
- package/lib/commonjs/ads/native-ad/NativeAsset.js +71 -0
- package/lib/commonjs/ads/native-ad/NativeAsset.js.map +1 -0
- package/lib/commonjs/ads/native-ad/NativeMediaView.js +58 -0
- package/lib/commonjs/ads/native-ad/NativeMediaView.js.map +1 -0
- package/lib/commonjs/common/ref.js +45 -0
- package/lib/commonjs/common/ref.js.map +1 -0
- package/lib/commonjs/index.js +47 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/components/GoogleMobileAdsBannerViewNativeComponent.js +17 -0
- package/lib/commonjs/specs/components/GoogleMobileAdsBannerViewNativeComponent.js.map +1 -1
- package/lib/commonjs/specs/components/GoogleMobileAdsMediaViewNativeComponent.js +26 -0
- package/lib/commonjs/specs/components/GoogleMobileAdsMediaViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/components/GoogleMobileAdsNativeViewNativeComponent.js +31 -0
- package/lib/commonjs/specs/components/GoogleMobileAdsNativeViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/modules/NativeConsentModule.js.map +1 -1
- package/lib/commonjs/specs/modules/NativeGoogleMobileAdsModule.js +1 -1
- package/lib/commonjs/specs/modules/NativeGoogleMobileAdsNativeModule.js +25 -0
- package/lib/commonjs/specs/modules/NativeGoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/commonjs/types/NativeAdRequestOptions.js +37 -0
- package/lib/commonjs/types/NativeAdRequestOptions.js.map +1 -0
- package/lib/commonjs/types/index.js +11 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/NativeAdEventType.js +13 -0
- package/lib/module/NativeAdEventType.js.map +1 -0
- package/lib/module/TestIds.js +15 -8
- package/lib/module/TestIds.js.map +1 -1
- package/lib/module/ads/native-ad/NativeAd.js +115 -0
- package/lib/module/ads/native-ad/NativeAd.js.map +1 -0
- package/lib/module/ads/native-ad/NativeAdContext.js +20 -0
- package/lib/module/ads/native-ad/NativeAdContext.js.map +1 -0
- package/lib/module/ads/native-ad/NativeAdView.js +40 -0
- package/lib/module/ads/native-ad/NativeAdView.js.map +1 -0
- package/lib/module/ads/native-ad/NativeAsset.js +63 -0
- package/lib/module/ads/native-ad/NativeAsset.js.map +1 -0
- package/lib/module/ads/native-ad/NativeMediaView.js +50 -0
- package/lib/module/ads/native-ad/NativeMediaView.js.map +1 -0
- package/lib/module/common/ref.js +38 -0
- package/lib/module/common/ref.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/components/GoogleMobileAdsBannerViewNativeComponent.js +17 -0
- package/lib/module/specs/components/GoogleMobileAdsBannerViewNativeComponent.js.map +1 -1
- package/lib/module/specs/components/GoogleMobileAdsMediaViewNativeComponent.js +20 -0
- package/lib/module/specs/components/GoogleMobileAdsMediaViewNativeComponent.js.map +1 -0
- package/lib/module/specs/components/GoogleMobileAdsNativeViewNativeComponent.js +24 -0
- package/lib/module/specs/components/GoogleMobileAdsNativeViewNativeComponent.js.map +1 -0
- package/lib/module/specs/modules/NativeConsentModule.js.map +1 -1
- package/lib/module/specs/modules/NativeGoogleMobileAdsModule.js +1 -1
- package/lib/module/specs/modules/NativeGoogleMobileAdsNativeModule.js +20 -0
- package/lib/module/specs/modules/NativeGoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/module/types/NativeAdRequestOptions.js +32 -0
- package/lib/module/types/NativeAdRequestOptions.js.map +1 -0
- package/lib/module/types/index.js +1 -0
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/NativeAdEventType.d.ts +39 -0
- package/lib/typescript/NativeAdEventType.d.ts.map +1 -0
- package/lib/typescript/TestIds.d.ts +3 -0
- package/lib/typescript/TestIds.d.ts.map +1 -1
- package/lib/typescript/ads/native-ad/NativeAd.d.ts +46 -0
- package/lib/typescript/ads/native-ad/NativeAd.d.ts.map +1 -0
- package/lib/typescript/ads/native-ad/NativeAdContext.d.ts +10 -0
- package/lib/typescript/ads/native-ad/NativeAdContext.d.ts.map +1 -0
- package/lib/typescript/ads/native-ad/NativeAdView.d.ts +8 -0
- package/lib/typescript/ads/native-ad/NativeAdView.d.ts.map +1 -0
- package/lib/typescript/ads/native-ad/NativeAsset.d.ts +18 -0
- package/lib/typescript/ads/native-ad/NativeAsset.d.ts.map +1 -0
- package/lib/typescript/ads/native-ad/NativeMediaView.d.ts +7 -0
- package/lib/typescript/ads/native-ad/NativeMediaView.d.ts.map +1 -0
- package/lib/typescript/common/ref.d.ts +13 -0
- package/lib/typescript/common/ref.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/components/GoogleMobileAdsBannerViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/specs/components/GoogleMobileAdsMediaViewNativeComponent.d.ts +9 -0
- package/lib/typescript/specs/components/GoogleMobileAdsMediaViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/components/GoogleMobileAdsNativeViewNativeComponent.d.ts +14 -0
- package/lib/typescript/specs/components/GoogleMobileAdsNativeViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/modules/NativeConsentModule.d.ts +3 -4
- package/lib/typescript/specs/modules/NativeConsentModule.d.ts.map +1 -1
- package/lib/typescript/specs/modules/NativeGoogleMobileAdsModule.d.ts +1 -17
- package/lib/typescript/specs/modules/NativeGoogleMobileAdsModule.d.ts.map +1 -1
- package/lib/typescript/specs/modules/NativeGoogleMobileAdsNativeModule.d.ts +37 -0
- package/lib/typescript/specs/modules/NativeGoogleMobileAdsNativeModule.d.ts.map +1 -0
- package/lib/typescript/types/NativeAdRequestOptions.d.ts +36 -0
- package/lib/typescript/types/NativeAdRequestOptions.d.ts.map +1 -0
- package/lib/typescript/types/index.d.ts +1 -0
- package/lib/typescript/types/index.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/NativeAdEventType.ts +46 -0
- package/src/TestIds.ts +13 -6
- package/src/ads/native-ad/NativeAd.ts +152 -0
- package/src/ads/native-ad/NativeAdContext.ts +26 -0
- package/src/ads/native-ad/NativeAdView.tsx +43 -0
- package/src/ads/native-ad/NativeAsset.tsx +66 -0
- package/src/ads/native-ad/NativeMediaView.tsx +44 -0
- package/src/common/ref.ts +44 -0
- package/src/index.ts +5 -0
- package/src/specs/components/GoogleMobileAdsBannerViewNativeComponent.ts +17 -0
- package/src/specs/components/GoogleMobileAdsMediaViewNativeComponent.ts +30 -0
- package/src/specs/components/GoogleMobileAdsNativeViewNativeComponent.ts +44 -0
- package/src/specs/modules/NativeConsentModule.ts +3 -4
- package/src/specs/modules/NativeGoogleMobileAdsModule.ts +2 -2
- package/src/specs/modules/NativeGoogleMobileAdsNativeModule.ts +64 -0
- package/src/types/NativeAdRequestOptions.ts +55 -0
- package/src/types/index.ts +1 -0
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -30,22 +30,107 @@ React Native Google Mobile Ads is built with three key principals in mind;
|
|
|
30
30
|
- 📄 **Well documented**
|
|
31
31
|
- full reference & installation documentation alongside detailed guides and FAQs
|
|
32
32
|
|
|
33
|
+
## Ad formats
|
|
34
|
+
|
|
35
|
+
### App open
|
|
36
|
+
|
|
37
|
+
App open ads are a special ad format intended for publishers wishing to monetize their app load screens.
|
|
38
|
+
|
|
39
|
+
<img width="200" src="https://developers.google.com/static/admob/images/app-open-ad.png" alt="App open ad">
|
|
40
|
+
|
|
41
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#app-open-ads)
|
|
42
|
+
|
|
43
|
+
### Banner
|
|
44
|
+
|
|
45
|
+
Banner ad units display rectangular ads that occupy a portion of an app's layout.
|
|
46
|
+
They stay on screen while users are interacting with the app, either anchored at the top or bottom of the screen or inline with content as the user scrolls.
|
|
47
|
+
Banner ads can refresh automatically after a certain period of time.
|
|
48
|
+
|
|
49
|
+
#### Anchored adaptive
|
|
50
|
+
|
|
51
|
+
A dynamically sized banner that is full-width and auto-height. Anchored adaptive banners are expected to be always on-screen, locked to the screen’s top or bottom.
|
|
52
|
+
|
|
53
|
+
<img width="200" src="https://developers.google.com/static/admob/images/Android_adaptive.png" alt="Anchored adaptive">
|
|
54
|
+
|
|
55
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#banner-ads-component)
|
|
56
|
+
|
|
57
|
+
#### Inline adaptive
|
|
58
|
+
|
|
59
|
+
Inline adaptive banners are larger, taller banners compared to anchored adaptive banners.
|
|
60
|
+
They are of variable height, and can be as tall as the device screen.
|
|
61
|
+
They are intended to be placed in scrolling content.
|
|
62
|
+
|
|
63
|
+
<img width="600" src="https://developers.google.com/static/admob/images/inline-adaptive.png" alt="Inline adaptive">
|
|
64
|
+
|
|
65
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#banner-ads-component)
|
|
66
|
+
|
|
67
|
+
#### Collapsible
|
|
68
|
+
|
|
69
|
+
Collapsible banner ads are intended to improve performance of anchored ads that are otherwise a smaller size.
|
|
70
|
+
|
|
71
|
+
<img width="400" src="https://developers.google.com/static/admob/images/collapsible-banner.png" alt="Collapsible banner">
|
|
72
|
+
|
|
73
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#collapsible-banner-ads)
|
|
74
|
+
|
|
75
|
+
#### Fixed size (legacy)
|
|
76
|
+
|
|
77
|
+
The Google Mobile Ads SDK supports fixed ad sizes for situations where adaptive banners ads don't meet your needs.
|
|
78
|
+
Banner (320x50), Large banner (320x100), Medium rectangle (300x250), full banner (468x60) and leaderboard (728x90).
|
|
79
|
+
|
|
80
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#banner-ads-component)
|
|
81
|
+
|
|
82
|
+
### Native
|
|
83
|
+
|
|
84
|
+
Native ads allow you to customize the look and feel of the ads that appear in your app.
|
|
85
|
+
You decide how and where they're placed, so the layout is more consistent your app's design.
|
|
86
|
+
|
|
87
|
+
<img width="300" src="https://developers.google.com/static/admob/images/format-native.svg" alt="Native">
|
|
88
|
+
|
|
89
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/native-ads)
|
|
90
|
+
|
|
91
|
+
### Interstitial
|
|
92
|
+
|
|
93
|
+
Interstitial ad units show full-page ads in your app. Place them at natural breaks & transitions in your app's interface, such as after level completion in a gaming app.
|
|
94
|
+
|
|
95
|
+
<img width="300" src="https://developers.google.com/static/admob/images/format-interstitial.svg" alt="Interstitial">
|
|
96
|
+
|
|
97
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#interstitial-ads)
|
|
98
|
+
|
|
99
|
+
### Rewarded
|
|
100
|
+
|
|
101
|
+
AdMob rewarded ad units allow you to reward users with in-app items for interacting with video ads, playable ads, and surveys.
|
|
102
|
+
|
|
103
|
+
<img width="300" src="https://developers.google.com/static/admob/images/format-rewarded.svg" alt="Rewarded">
|
|
104
|
+
|
|
105
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#rewarded-ads)
|
|
106
|
+
|
|
107
|
+
### Rewarded Interstitial
|
|
108
|
+
|
|
109
|
+
Rewarded interstitial is a type of incentivized ad format that allows you offer rewards for ads that appear automatically during natural app transitions.
|
|
110
|
+
Unlike rewarded ads, users aren't required to opt-in to view a rewarded interstitial.
|
|
111
|
+
|
|
112
|
+
<img width="300" src="https://developers.google.com/static/admob/images/format-rewarded-interstitial.svg" alt="Rewarded interstitial">
|
|
113
|
+
|
|
114
|
+
[Learn More](https://docs.page/invertase/react-native-google-mobile-ads/displaying-ads#rewarded-interstitial-ads)
|
|
115
|
+
|
|
33
116
|
## Migrating to the New Architecture Status (backwards compatible)
|
|
34
117
|
|
|
35
118
|
This package can be used in both The Old and [The New Architecture](https://reactnative.dev/docs/the-new-architecture/landing-page).
|
|
36
119
|
When using The New Architecture, some legacy code will still be used though. See status below:
|
|
37
120
|
|
|
38
121
|
| Platform | Feature | Status |
|
|
39
|
-
| --------
|
|
122
|
+
| -------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------| ----------- |
|
|
40
123
|
| iOS | Mobile Ads SDK Methods (Turbo Native Module) | ✅ Complete |
|
|
41
124
|
| iOS | Banners (Fabric Native Component) | ✅ Complete |
|
|
42
125
|
| iOS | Full Screen Ads (Turbo Native Module) | ✅ Complete |
|
|
126
|
+
| iOS | Native Ads (Turbo Native Module, Fabric Native Component) | ✅ Complete |
|
|
43
127
|
| iOS | User Messaging Platform (Turbo Native Module) | ✅ Complete |
|
|
44
128
|
| iOS | [EventEmitter](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md#add-event-emitting-capabilities) (Turbo Native Module) | ⏳ To-Do |
|
|
45
129
|
| iOS | Revenue Precision Constants (Turbo Native Module) | ✅ Complete |
|
|
46
130
|
| Android | Mobile Ads SDK Methods (Turbo Native Module) | ⏳ To-Do |
|
|
47
131
|
| Android | Banners (Fabric Native Component) | ⏳ To-Do |
|
|
48
132
|
| Android | Full Screen Ads (Turbo Native Module) | ⏳ To-Do |
|
|
133
|
+
| Android | Native Ads (Turbo Native Module, Fabric Native Component) | ✅ Complete |
|
|
49
134
|
| Android | User Messaging Platform (Turbo Native Module) | ⏳ To-Do |
|
|
50
135
|
| Android | [EventEmitter](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/turbo-modules.md#add-event-emitting-capabilities) (Turbo Native Module) | ⏳ To-Do |
|
|
51
136
|
| Android | Revenue Precision Constants (Turbo Native Module) | ⏳ To-Do |
|
package/android/build.gradle
CHANGED
|
@@ -108,6 +108,16 @@ android {
|
|
|
108
108
|
appJSONGoogleMobileAdsOptimizeAdLoading : appJSONGoogleMobileAdsOptimizeAdLoadingBool
|
|
109
109
|
]
|
|
110
110
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
111
|
+
|
|
112
|
+
sourceSets {
|
|
113
|
+
main {
|
|
114
|
+
if (isNewArchitectureEnabled()) {
|
|
115
|
+
java.srcDirs += ['src/newarch']
|
|
116
|
+
} else {
|
|
117
|
+
java.srcDirs += ['src/oldarch']
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
122
|
lintOptions {
|
|
113
123
|
disable 'GradleCompatible'
|
|
@@ -30,10 +30,10 @@ import io.invertase.googlemobileads.common.ReactNativeModule;
|
|
|
30
30
|
import io.invertase.googlemobileads.common.ReactNativePreferences;
|
|
31
31
|
|
|
32
32
|
public class ReactNativeAppModule extends ReactNativeModule {
|
|
33
|
-
|
|
33
|
+
static final String NAME = "RNAppModule";
|
|
34
34
|
|
|
35
35
|
ReactNativeAppModule(ReactApplicationContext reactContext) {
|
|
36
|
-
super(reactContext,
|
|
36
|
+
super(reactContext, NAME);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
@Override
|
|
@@ -35,11 +35,11 @@ import javax.annotation.Nonnull;
|
|
|
35
35
|
|
|
36
36
|
public class ReactNativeGoogleMobileAdsConsentModule extends ReactNativeModule {
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
static final String NAME = "RNGoogleMobileAdsConsentModule";
|
|
39
39
|
private ConsentInformation consentInformation;
|
|
40
40
|
|
|
41
41
|
public ReactNativeGoogleMobileAdsConsentModule(ReactApplicationContext reactContext) {
|
|
42
|
-
super(reactContext,
|
|
42
|
+
super(reactContext, NAME);
|
|
43
43
|
consentInformation = UserMessagingPlatform.getConsentInformation(reactContext);
|
|
44
44
|
}
|
|
45
45
|
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsMediaView.kt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
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.annotation.SuppressLint
|
|
21
|
+
import android.widget.ImageView
|
|
22
|
+
import com.facebook.react.bridge.ReactContext
|
|
23
|
+
import com.google.android.gms.ads.nativead.MediaView
|
|
24
|
+
|
|
25
|
+
@SuppressLint("ViewConstructor")
|
|
26
|
+
class ReactNativeGoogleMobileAdsMediaView(
|
|
27
|
+
private val context: ReactContext
|
|
28
|
+
): MediaView(context) {
|
|
29
|
+
fun setResponseId(responseId: String?) {
|
|
30
|
+
val nativeModule = context.getNativeModule(ReactNativeGoogleMobileAdsNativeModule::class.java)
|
|
31
|
+
nativeModule?.getNativeAd(responseId ?: "")?.let {
|
|
32
|
+
this.mediaContent = it.mediaContent
|
|
33
|
+
requestLayout()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun setResizeMode(resizeMode: String?) {
|
|
38
|
+
when (resizeMode) {
|
|
39
|
+
"cover" -> setImageScaleType(ImageView.ScaleType.CENTER_CROP)
|
|
40
|
+
"contain" -> setImageScaleType(ImageView.ScaleType.CENTER_INSIDE)
|
|
41
|
+
"stretch" -> setImageScaleType(ImageView.ScaleType.FIT_XY)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun requestLayout() {
|
|
46
|
+
super.requestLayout()
|
|
47
|
+
post(measureAndLayout)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private val measureAndLayout = Runnable {
|
|
51
|
+
measure(
|
|
52
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
53
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
54
|
+
)
|
|
55
|
+
layout(left, top, right, bottom)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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.ReactApplicationContext
|
|
21
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
22
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
23
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
24
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
25
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
26
|
+
import com.facebook.react.viewmanagers.RNGoogleMobileAdsMediaViewManagerDelegate
|
|
27
|
+
import com.facebook.react.viewmanagers.RNGoogleMobileAdsMediaViewManagerInterface
|
|
28
|
+
|
|
29
|
+
@ReactModule(name = ReactNativeGoogleMobileAdsMediaViewManager.NAME)
|
|
30
|
+
class ReactNativeGoogleMobileAdsMediaViewManager(
|
|
31
|
+
reactContext: ReactApplicationContext
|
|
32
|
+
) : ViewGroupManager<ReactNativeGoogleMobileAdsMediaView>(reactContext),
|
|
33
|
+
RNGoogleMobileAdsMediaViewManagerInterface<ReactNativeGoogleMobileAdsMediaView> {
|
|
34
|
+
private val delegate: ViewManagerDelegate<ReactNativeGoogleMobileAdsMediaView> = RNGoogleMobileAdsMediaViewManagerDelegate(this)
|
|
35
|
+
|
|
36
|
+
override fun getDelegate(): ViewManagerDelegate<ReactNativeGoogleMobileAdsMediaView> = delegate
|
|
37
|
+
|
|
38
|
+
override fun getName(): String = NAME
|
|
39
|
+
|
|
40
|
+
override fun createViewInstance(context: ThemedReactContext): ReactNativeGoogleMobileAdsMediaView = ReactNativeGoogleMobileAdsMediaView(context)
|
|
41
|
+
|
|
42
|
+
@ReactProp(name = "responseId")
|
|
43
|
+
override fun setResponseId(view: ReactNativeGoogleMobileAdsMediaView, responseId: String?) {
|
|
44
|
+
view.setResponseId(responseId)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactProp(name = "resizeMode")
|
|
48
|
+
override fun setResizeMode(view: ReactNativeGoogleMobileAdsMediaView, resizeMode: String?) {
|
|
49
|
+
view.setResizeMode(resizeMode)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
companion object {
|
|
53
|
+
const val NAME = "RNGoogleMobileAdsMediaView"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.kt
CHANGED
|
@@ -26,13 +26,11 @@ import com.google.android.gms.ads.AdRequest
|
|
|
26
26
|
import com.google.android.gms.ads.AdValue;
|
|
27
27
|
import com.google.android.gms.ads.OnAdInspectorClosedListener
|
|
28
28
|
|
|
29
|
-
private const val SERVICE = "RNGoogleMobileAdsModule";
|
|
30
|
-
|
|
31
29
|
class ReactNativeGoogleMobileAdsModule(
|
|
32
30
|
reactContext: ReactApplicationContext
|
|
33
31
|
) : ReactContextBaseJavaModule(reactContext) {
|
|
34
32
|
|
|
35
|
-
override fun getName() =
|
|
33
|
+
override fun getName() = NAME
|
|
36
34
|
|
|
37
35
|
override fun getConstants(): Map<String, Any> {
|
|
38
36
|
return mapOf(
|
|
@@ -164,7 +162,6 @@ class ReactNativeGoogleMobileAdsModule(
|
|
|
164
162
|
}
|
|
165
163
|
}
|
|
166
164
|
|
|
167
|
-
|
|
168
165
|
@ReactMethod
|
|
169
166
|
fun openDebugMenu(adUnit: String) {
|
|
170
167
|
currentActivity?.runOnUiThread {
|
|
@@ -181,4 +178,8 @@ class ReactNativeGoogleMobileAdsModule(
|
|
|
181
178
|
fun setAppMuted(muted: Boolean) {
|
|
182
179
|
MobileAds.setAppMuted(muted)
|
|
183
180
|
}
|
|
181
|
+
|
|
182
|
+
companion object {
|
|
183
|
+
const val NAME = "RNGoogleMobileAdsModule"
|
|
184
|
+
}
|
|
184
185
|
}
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsNativeAdView.kt
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
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.annotation.SuppressLint
|
|
21
|
+
import android.widget.FrameLayout
|
|
22
|
+
import com.facebook.react.bridge.ReactContext
|
|
23
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
24
|
+
import com.facebook.react.uimanager.common.UIManagerType
|
|
25
|
+
import com.facebook.react.views.view.ReactViewGroup
|
|
26
|
+
import com.google.android.gms.ads.nativead.MediaView
|
|
27
|
+
import com.google.android.gms.ads.nativead.NativeAd
|
|
28
|
+
import com.google.android.gms.ads.nativead.NativeAdView
|
|
29
|
+
import kotlinx.coroutines.CoroutineScope
|
|
30
|
+
import kotlinx.coroutines.Dispatchers
|
|
31
|
+
import kotlinx.coroutines.Job
|
|
32
|
+
import kotlinx.coroutines.delay
|
|
33
|
+
import kotlinx.coroutines.launch
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@SuppressLint("ViewConstructor")
|
|
37
|
+
class ReactNativeGoogleMobileAdsNativeAdView(
|
|
38
|
+
private val context: ReactContext
|
|
39
|
+
): FrameLayout(context) {
|
|
40
|
+
val viewGroup = ReactViewGroup(context)
|
|
41
|
+
private val nativeAdView = NativeAdView(context)
|
|
42
|
+
private var nativeAd: NativeAd? = null
|
|
43
|
+
private var reloadJob: Job? = null
|
|
44
|
+
|
|
45
|
+
init {
|
|
46
|
+
nativeAdView.addView(viewGroup)
|
|
47
|
+
addView(nativeAdView)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fun setResponseId(responseId: String?) {
|
|
51
|
+
val nativeModule = context.getNativeModule(ReactNativeGoogleMobileAdsNativeModule::class.java)
|
|
52
|
+
nativeModule?.getNativeAd(responseId ?: "")?.let {
|
|
53
|
+
if (nativeAd == it) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
nativeAd = it
|
|
57
|
+
reloadAd()
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
fun registerAsset(assetType: String, reactTag: Int) {
|
|
62
|
+
val uiManager = UIManagerHelper.getUIManagerForReactTag(context, reactTag)
|
|
63
|
+
val assetView = uiManager?.resolveView(reactTag) ?: return
|
|
64
|
+
when (assetType) {
|
|
65
|
+
"advertiser" -> nativeAdView.advertiserView = assetView
|
|
66
|
+
"body" -> nativeAdView.bodyView = assetView
|
|
67
|
+
"callToAction" -> nativeAdView.callToActionView = assetView
|
|
68
|
+
"headline" -> nativeAdView.headlineView = assetView
|
|
69
|
+
"price" -> nativeAdView.priceView = assetView
|
|
70
|
+
"store" -> nativeAdView.storeView = assetView
|
|
71
|
+
"starRating" -> nativeAdView.starRatingView = assetView
|
|
72
|
+
"icon" -> nativeAdView.iconView = assetView
|
|
73
|
+
"image" -> nativeAdView.imageView = assetView
|
|
74
|
+
"media" -> nativeAdView.mediaView = assetView as MediaView
|
|
75
|
+
}
|
|
76
|
+
reloadAd()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private fun reloadAd() {
|
|
80
|
+
reloadJob?.cancel()
|
|
81
|
+
reloadJob = CoroutineScope(Dispatchers.Main).launch {
|
|
82
|
+
delay(100)
|
|
83
|
+
nativeAd?.let { nativeAdView.setNativeAd(it) }
|
|
84
|
+
nativeAdView.rootView.requestLayout()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
override fun requestLayout() {
|
|
89
|
+
super.requestLayout()
|
|
90
|
+
post(measureAndLayout)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fun destroy() {
|
|
94
|
+
reloadJob?.cancel()
|
|
95
|
+
reloadJob = null
|
|
96
|
+
nativeAdView.removeView(viewGroup)
|
|
97
|
+
nativeAdView.destroy()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private val measureAndLayout = Runnable {
|
|
101
|
+
measure(
|
|
102
|
+
MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
|
|
103
|
+
MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
|
|
104
|
+
)
|
|
105
|
+
layout(left, top, right, bottom)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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.view.View
|
|
21
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
22
|
+
import com.facebook.react.bridge.ReactMethod
|
|
23
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
24
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
25
|
+
import com.facebook.react.uimanager.ViewGroupManager
|
|
26
|
+
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
27
|
+
import com.facebook.react.uimanager.annotations.ReactProp
|
|
28
|
+
import com.facebook.react.viewmanagers.RNGoogleMobileAdsNativeViewManagerDelegate
|
|
29
|
+
import com.facebook.react.viewmanagers.RNGoogleMobileAdsNativeViewManagerInterface
|
|
30
|
+
|
|
31
|
+
@ReactModule(name = ReactNativeGoogleMobileAdsNativeAdViewManager.NAME)
|
|
32
|
+
class ReactNativeGoogleMobileAdsNativeAdViewManager(
|
|
33
|
+
reactContext: ReactApplicationContext
|
|
34
|
+
) : ViewGroupManager<ReactNativeGoogleMobileAdsNativeAdView>(reactContext),
|
|
35
|
+
RNGoogleMobileAdsNativeViewManagerInterface<ReactNativeGoogleMobileAdsNativeAdView> {
|
|
36
|
+
private val delegate: ViewManagerDelegate<ReactNativeGoogleMobileAdsNativeAdView> = RNGoogleMobileAdsNativeViewManagerDelegate(this)
|
|
37
|
+
|
|
38
|
+
override fun getDelegate(): ViewManagerDelegate<ReactNativeGoogleMobileAdsNativeAdView> = delegate
|
|
39
|
+
|
|
40
|
+
override fun getName(): String = NAME
|
|
41
|
+
|
|
42
|
+
override fun createViewInstance(context: ThemedReactContext): ReactNativeGoogleMobileAdsNativeAdView = ReactNativeGoogleMobileAdsNativeAdView(context)
|
|
43
|
+
|
|
44
|
+
override fun onDropViewInstance(adView: ReactNativeGoogleMobileAdsNativeAdView) {
|
|
45
|
+
super.onDropViewInstance(adView)
|
|
46
|
+
adView.destroy()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override fun prepareToRecycleView(
|
|
50
|
+
reactContext: ThemedReactContext,
|
|
51
|
+
view: ReactNativeGoogleMobileAdsNativeAdView
|
|
52
|
+
): ReactNativeGoogleMobileAdsNativeAdView? {
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
@ReactProp(name = "responseId")
|
|
57
|
+
override fun setResponseId(view: ReactNativeGoogleMobileAdsNativeAdView, responseId: String?) {
|
|
58
|
+
view.setResponseId(responseId)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactMethod
|
|
62
|
+
override fun registerAsset(view: ReactNativeGoogleMobileAdsNativeAdView, assetKey: String, reactTag: Int) {
|
|
63
|
+
view.registerAsset(assetKey, reactTag)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
override fun addView(parent: ReactNativeGoogleMobileAdsNativeAdView, child: View, index: Int) {
|
|
67
|
+
parent.viewGroup.addView(child, index)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun getChildCount(parent: ReactNativeGoogleMobileAdsNativeAdView): Int {
|
|
71
|
+
return parent.viewGroup.childCount
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
override fun getChildAt(parent: ReactNativeGoogleMobileAdsNativeAdView, index: Int): View? {
|
|
75
|
+
return parent.viewGroup.getChildAt(index)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override fun removeViewAt(parent: ReactNativeGoogleMobileAdsNativeAdView, index: Int) {
|
|
79
|
+
parent.viewGroup.removeViewAt(index)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
companion object {
|
|
83
|
+
const val NAME = "RNGoogleMobileAdsNativeView"
|
|
84
|
+
}
|
|
85
|
+
}
|