react-native-google-mobile-ads 9.1.1 → 9.1.2
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/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +36 -33
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeAdView.java +68 -0
- package/docs/displaying-ads-hook.mdx +1 -0
- 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 +1 -1
- package/src/version.ts +1 -1
|
@@ -38,6 +38,7 @@ import com.google.android.gms.ads.BaseAdView;
|
|
|
38
38
|
import com.google.android.gms.ads.LoadAdError;
|
|
39
39
|
import com.google.android.gms.ads.admanager.AdManagerAdView;
|
|
40
40
|
import com.google.android.gms.ads.admanager.AppEventListener;
|
|
41
|
+
import io.invertase.googlemobileads.common.ReactNativeAdView;
|
|
41
42
|
import java.util.ArrayList;
|
|
42
43
|
import java.util.List;
|
|
43
44
|
import java.util.Map;
|
|
@@ -45,7 +46,7 @@ import javax.annotation.Nonnull;
|
|
|
45
46
|
import javax.annotation.Nullable;
|
|
46
47
|
|
|
47
48
|
public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
48
|
-
extends SimpleViewManager<
|
|
49
|
+
extends SimpleViewManager<ReactNativeAdView> {
|
|
49
50
|
private static final String REACT_CLASS = "RNGoogleMobileAdsBannerView";
|
|
50
51
|
private final String EVENT_AD_LOADED = "onAdLoaded";
|
|
51
52
|
private final String EVENT_AD_FAILED_TO_LOAD = "onAdFailedToLoad";
|
|
@@ -55,13 +56,6 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
55
56
|
private final String EVENT_APP_EVENT = "onAppEvent";
|
|
56
57
|
private final int COMMAND_ID_RECORD_MANUAL_IMPRESSION = 1;
|
|
57
58
|
|
|
58
|
-
private AdRequest request;
|
|
59
|
-
private List<AdSize> sizes;
|
|
60
|
-
private String unitId;
|
|
61
|
-
private Boolean manualImpressionsEnabled;
|
|
62
|
-
private boolean propsChanged;
|
|
63
|
-
private boolean isFluid;
|
|
64
|
-
|
|
65
59
|
@Nonnull
|
|
66
60
|
@Override
|
|
67
61
|
public String getName() {
|
|
@@ -70,8 +64,8 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
70
64
|
|
|
71
65
|
@Nonnull
|
|
72
66
|
@Override
|
|
73
|
-
public
|
|
74
|
-
return new
|
|
67
|
+
public ReactNativeAdView createViewInstance(@Nonnull ThemedReactContext themedReactContext) {
|
|
68
|
+
return new ReactNativeAdView(themedReactContext);
|
|
75
69
|
}
|
|
76
70
|
|
|
77
71
|
@Override
|
|
@@ -89,7 +83,7 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
89
83
|
|
|
90
84
|
@Override
|
|
91
85
|
public void receiveCommand(
|
|
92
|
-
@NonNull
|
|
86
|
+
@NonNull ReactNativeAdView reactViewGroup, String commandId, @Nullable ReadableArray args) {
|
|
93
87
|
super.receiveCommand(reactViewGroup, commandId, args);
|
|
94
88
|
int commandIdInt = Integer.parseInt(commandId);
|
|
95
89
|
|
|
@@ -102,19 +96,19 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
102
96
|
}
|
|
103
97
|
|
|
104
98
|
@ReactProp(name = "unitId")
|
|
105
|
-
public void setUnitId(
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
public void setUnitId(ReactNativeAdView reactViewGroup, String value) {
|
|
100
|
+
reactViewGroup.setUnitId(value);
|
|
101
|
+
reactViewGroup.setPropsChanged(true);
|
|
108
102
|
}
|
|
109
103
|
|
|
110
104
|
@ReactProp(name = "request")
|
|
111
|
-
public void setRequest(
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
public void setRequest(ReactNativeAdView reactViewGroup, ReadableMap value) {
|
|
106
|
+
reactViewGroup.setRequest(ReactNativeGoogleMobileAdsCommon.buildAdRequest(value));
|
|
107
|
+
reactViewGroup.setPropsChanged(true);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
@ReactProp(name = "sizes")
|
|
117
|
-
public void setSizes(
|
|
111
|
+
public void setSizes(ReactNativeAdView reactViewGroup, ReadableArray value) {
|
|
118
112
|
List<AdSize> sizeList = new ArrayList<>();
|
|
119
113
|
for (Object size : value.toArrayList()) {
|
|
120
114
|
if (size instanceof String) {
|
|
@@ -131,33 +125,37 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
131
125
|
sendEvent(reactViewGroup, EVENT_SIZE_CHANGE, payload);
|
|
132
126
|
}
|
|
133
127
|
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
reactViewGroup.setSizes(sizeList);
|
|
129
|
+
reactViewGroup.setPropsChanged(true);
|
|
136
130
|
}
|
|
137
131
|
|
|
138
132
|
@ReactProp(name = "manualImpressionsEnabled")
|
|
139
|
-
public void setManualImpressionsEnabled(
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
public void setManualImpressionsEnabled(ReactNativeAdView reactViewGroup, boolean value) {
|
|
134
|
+
reactViewGroup.setManualImpressionsEnabled(value);
|
|
135
|
+
reactViewGroup.setPropsChanged(true);
|
|
142
136
|
}
|
|
143
137
|
|
|
144
138
|
@Override
|
|
145
|
-
public void onAfterUpdateTransaction(@NonNull
|
|
139
|
+
public void onAfterUpdateTransaction(@NonNull ReactNativeAdView reactViewGroup) {
|
|
146
140
|
super.onAfterUpdateTransaction(reactViewGroup);
|
|
147
|
-
if (
|
|
141
|
+
if (reactViewGroup.getPropsChanged()) {
|
|
148
142
|
requestAd(reactViewGroup);
|
|
149
143
|
}
|
|
150
|
-
|
|
144
|
+
reactViewGroup.setPropsChanged(false);
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
private BaseAdView initAdView(
|
|
147
|
+
private BaseAdView initAdView(ReactNativeAdView reactViewGroup) {
|
|
154
148
|
BaseAdView oldAdView = getAdView(reactViewGroup);
|
|
155
149
|
if (oldAdView != null) {
|
|
150
|
+
oldAdView.setAdListener(null);
|
|
151
|
+
if (oldAdView instanceof AdManagerAdView) {
|
|
152
|
+
((AdManagerAdView) oldAdView).setAppEventListener(null);
|
|
153
|
+
}
|
|
156
154
|
oldAdView.destroy();
|
|
157
155
|
reactViewGroup.removeView(oldAdView);
|
|
158
156
|
}
|
|
159
157
|
BaseAdView adView;
|
|
160
|
-
if (ReactNativeGoogleMobileAdsCommon.isAdManagerUnit(
|
|
158
|
+
if (ReactNativeGoogleMobileAdsCommon.isAdManagerUnit(reactViewGroup.getUnitId())) {
|
|
161
159
|
adView = new AdManagerAdView(reactViewGroup.getContext());
|
|
162
160
|
} else {
|
|
163
161
|
adView = new AdView(reactViewGroup.getContext());
|
|
@@ -169,7 +167,7 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
169
167
|
public void onAdLoaded() {
|
|
170
168
|
AdSize adSize = adView.getAdSize();
|
|
171
169
|
int left, top, width, height;
|
|
172
|
-
if (
|
|
170
|
+
if (reactViewGroup.getIsFluid()) {
|
|
173
171
|
// TODO size=FLUID is still not working
|
|
174
172
|
left = 0;
|
|
175
173
|
top = 0;
|
|
@@ -230,7 +228,12 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
230
228
|
return (BaseAdView) reactViewGroup.getChildAt(0);
|
|
231
229
|
}
|
|
232
230
|
|
|
233
|
-
private void requestAd(
|
|
231
|
+
private void requestAd(ReactNativeAdView reactViewGroup) {
|
|
232
|
+
String unitId = reactViewGroup.getUnitId();
|
|
233
|
+
List<AdSize> sizes = reactViewGroup.getSizes();
|
|
234
|
+
AdRequest request = reactViewGroup.getRequest();
|
|
235
|
+
Boolean manualImpressionsEnabled = reactViewGroup.getManualImpressionsEnabled();
|
|
236
|
+
|
|
234
237
|
if (sizes == null || unitId == null || request == null || manualImpressionsEnabled == null) {
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
@@ -238,10 +241,10 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
238
241
|
BaseAdView adView = initAdView(reactViewGroup);
|
|
239
242
|
adView.setAdUnitId(unitId);
|
|
240
243
|
|
|
241
|
-
|
|
244
|
+
reactViewGroup.setIsFluid(false);
|
|
242
245
|
if (adView instanceof AdManagerAdView) {
|
|
243
246
|
if (sizes.contains(AdSize.FLUID)) {
|
|
244
|
-
|
|
247
|
+
reactViewGroup.setIsFluid(true);
|
|
245
248
|
((AdManagerAdView) adView).setAdSizes(AdSize.FLUID);
|
|
246
249
|
} else {
|
|
247
250
|
((AdManagerAdView) adView).setAdSizes(sizes.toArray(new AdSize[0]));
|
|
@@ -256,7 +259,7 @@ public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
|
256
259
|
adView.loadAd(request);
|
|
257
260
|
}
|
|
258
261
|
|
|
259
|
-
private void sendEvent(
|
|
262
|
+
private void sendEvent(ReactNativeAdView reactViewGroup, String type, WritableMap payload) {
|
|
260
263
|
WritableMap event = Arguments.createMap();
|
|
261
264
|
event.putString("type", type);
|
|
262
265
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
package io.invertase.googlemobileads.common;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
5
|
+
import com.google.android.gms.ads.AdRequest;
|
|
6
|
+
import com.google.android.gms.ads.AdSize;
|
|
7
|
+
import java.util.List;
|
|
8
|
+
|
|
9
|
+
public class ReactNativeAdView extends ReactViewGroup {
|
|
10
|
+
private AdRequest request;
|
|
11
|
+
private List<AdSize> sizes;
|
|
12
|
+
private String unitId;
|
|
13
|
+
private boolean manualImpressionsEnabled;
|
|
14
|
+
private boolean propsChanged;
|
|
15
|
+
private boolean isFluid;
|
|
16
|
+
|
|
17
|
+
public ReactNativeAdView(final Context context) {
|
|
18
|
+
super(context);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public void setRequest(AdRequest request) {
|
|
22
|
+
this.request = request;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public AdRequest getRequest() {
|
|
26
|
+
return this.request;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public void setSizes(List<AdSize> sizes) {
|
|
30
|
+
this.sizes = sizes;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public List<AdSize> getSizes() {
|
|
34
|
+
return this.sizes;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void setUnitId(String unitId) {
|
|
38
|
+
this.unitId = unitId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public String getUnitId() {
|
|
42
|
+
return this.unitId;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public void setManualImpressionsEnabled(boolean manualImpressionsEnabled) {
|
|
46
|
+
this.manualImpressionsEnabled = manualImpressionsEnabled;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public boolean getManualImpressionsEnabled() {
|
|
50
|
+
return this.manualImpressionsEnabled;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public void setPropsChanged(boolean propsChanged) {
|
|
54
|
+
this.propsChanged = propsChanged;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public boolean getPropsChanged() {
|
|
58
|
+
return this.propsChanged;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public void setIsFluid(boolean isFluid) {
|
|
62
|
+
this.isFluid = isFluid;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public boolean getIsFluid() {
|
|
66
|
+
return this.isFluid;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -86,6 +86,7 @@ Return values of the hook are:
|
|
|
86
86
|
| :------------- | :--------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
87
87
|
| isLoaded | boolean | Whether the ad is loaded and ready to to be shown to the user. Automatically set to false when the ad was shown. |
|
|
88
88
|
| isOpened | boolean | Whether the ad is opened. The value is remained `true` even after the ad is closed unless **new ad is requested**. |
|
|
89
|
+
| isClicked | boolean | Whether the ad is clicked. |
|
|
89
90
|
| isClosed | boolean | Whether your ad is dismissed. |
|
|
90
91
|
| isShowing | boolean | Whether your ad is showing. The value is equal with `isOpened && !isClosed`. |
|
|
91
92
|
| error | Error \| undefined | `Error` object throwed during ad load. |
|
package/lib/commonjs/version.js
CHANGED
package/lib/module/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "9.1.
|
|
1
|
+
export declare const SDK_VERSION = "9.1.2";
|
|
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 = "9.1.
|
|
1
|
+
export declare const version = "9.1.2";
|
|
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": "9.1.
|
|
3
|
+
"version": "9.1.2",
|
|
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",
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '9.1.
|
|
2
|
+
export const version = '9.1.2';
|