react-native-google-mobile-ads 9.1.0 → 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/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h +39 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m +156 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +4 -161
- 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. |
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#import <GoogleMobileAds/GADAppEventDelegate.h>
|
|
19
|
+
#import <GoogleMobileAds/GADBannerView.h>
|
|
20
|
+
#import <GoogleMobileAds/GADBannerViewDelegate.h>
|
|
21
|
+
#import <React/RCTView.h>
|
|
22
|
+
|
|
23
|
+
@interface RNGoogleMobileAdsBannerComponent : RCTView <GADBannerViewDelegate, GADAppEventDelegate>
|
|
24
|
+
|
|
25
|
+
@property GADBannerView *banner;
|
|
26
|
+
@property(nonatomic, assign) BOOL requested;
|
|
27
|
+
|
|
28
|
+
@property(nonatomic, copy) NSArray *sizes;
|
|
29
|
+
@property(nonatomic, copy) NSString *unitId;
|
|
30
|
+
@property(nonatomic, copy) NSDictionary *request;
|
|
31
|
+
@property(nonatomic, copy) NSNumber *manualImpressionsEnabled;
|
|
32
|
+
@property(nonatomic, assign) BOOL propsChanged;
|
|
33
|
+
|
|
34
|
+
@property(nonatomic, copy) RCTBubblingEventBlock onNativeEvent;
|
|
35
|
+
|
|
36
|
+
- (void)requestAd;
|
|
37
|
+
- (void)recordManualImpression;
|
|
38
|
+
|
|
39
|
+
@end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#import "RNGoogleMobileAdsBannerComponent.h"
|
|
19
|
+
#import <React/RCTLog.h>
|
|
20
|
+
#import "RNGoogleMobileAdsCommon.h"
|
|
21
|
+
|
|
22
|
+
@implementation RNGoogleMobileAdsBannerComponent
|
|
23
|
+
|
|
24
|
+
- (void)didSetProps:(NSArray<NSString *> *)changedProps {
|
|
25
|
+
if (_propsChanged) {
|
|
26
|
+
[self requestAd];
|
|
27
|
+
}
|
|
28
|
+
_propsChanged = false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (void)initBanner:(GADAdSize)adSize {
|
|
32
|
+
if (_requested) {
|
|
33
|
+
[_banner removeFromSuperview];
|
|
34
|
+
}
|
|
35
|
+
if ([RNGoogleMobileAdsCommon isAdManagerUnit:_unitId]) {
|
|
36
|
+
_banner = [[GAMBannerView alloc] initWithAdSize:adSize];
|
|
37
|
+
|
|
38
|
+
((GAMBannerView *)_banner).validAdSizes = _sizes;
|
|
39
|
+
((GAMBannerView *)_banner).appEventDelegate = self;
|
|
40
|
+
((GAMBannerView *)_banner).enableManualImpressions = [_manualImpressionsEnabled boolValue];
|
|
41
|
+
} else {
|
|
42
|
+
_banner = [[GADBannerView alloc] initWithAdSize:adSize];
|
|
43
|
+
}
|
|
44
|
+
_banner.rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
45
|
+
_banner.delegate = self;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
- (void)setUnitId:(NSString *)unitId {
|
|
49
|
+
_unitId = unitId;
|
|
50
|
+
_propsChanged = true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)setSizes:(NSArray *)sizes {
|
|
54
|
+
__block NSMutableArray *adSizes = [[NSMutableArray alloc] initWithCapacity:sizes.count];
|
|
55
|
+
[sizes enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
|
|
56
|
+
GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue];
|
|
57
|
+
if (GADAdSizeEqualToSize(adSize, GADAdSizeInvalid)) {
|
|
58
|
+
RCTLogWarn(@"Invalid adSize %@", jsonValue);
|
|
59
|
+
} else {
|
|
60
|
+
[adSizes addObject:NSValueFromGADAdSize(adSize)];
|
|
61
|
+
}
|
|
62
|
+
}];
|
|
63
|
+
_sizes = adSizes;
|
|
64
|
+
_propsChanged = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)setRequest:(NSDictionary *)request {
|
|
68
|
+
_request = request;
|
|
69
|
+
_propsChanged = true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
- (void)setManualImpressionsEnabled:(BOOL *)manualImpressionsEnabled {
|
|
73
|
+
_manualImpressionsEnabled = [NSNumber numberWithBool:manualImpressionsEnabled];
|
|
74
|
+
_propsChanged = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- (void)requestAd {
|
|
78
|
+
#ifndef __LP64__
|
|
79
|
+
return; // prevent crash on 32bit
|
|
80
|
+
#endif
|
|
81
|
+
|
|
82
|
+
if (_unitId == nil || _sizes == nil || _request == nil || _manualImpressionsEnabled == nil) {
|
|
83
|
+
[self setRequested:NO];
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[self initBanner:GADAdSizeFromNSValue(_sizes[0])];
|
|
88
|
+
[self addSubview:_banner];
|
|
89
|
+
_banner.adUnitID = _unitId;
|
|
90
|
+
[self setRequested:YES];
|
|
91
|
+
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
|
|
92
|
+
[self sendEvent:@"onSizeChange"
|
|
93
|
+
payload:@{
|
|
94
|
+
@"width" : @(_banner.bounds.size.width),
|
|
95
|
+
@"height" : @(_banner.bounds.size.height),
|
|
96
|
+
}];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
- (void)sendEvent:(NSString *)type payload:(NSDictionary *_Nullable)payload {
|
|
100
|
+
if (!self.onNativeEvent) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
NSMutableDictionary *event = [@{
|
|
105
|
+
@"type" : type,
|
|
106
|
+
} mutableCopy];
|
|
107
|
+
|
|
108
|
+
if (payload != nil) {
|
|
109
|
+
[event addEntriesFromDictionary:payload];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
self.onNativeEvent(event);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
|
|
116
|
+
[self sendEvent:@"onAdLoaded"
|
|
117
|
+
payload:@{
|
|
118
|
+
@"width" : @(bannerView.bounds.size.width),
|
|
119
|
+
@"height" : @(bannerView.bounds.size.height),
|
|
120
|
+
}];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
|
|
124
|
+
NSDictionary *errorAndMessage = [RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
|
|
125
|
+
[self sendEvent:@"onAdFailedToLoad" payload:errorAndMessage];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
|
|
129
|
+
[self sendEvent:@"onAdOpened" payload:nil];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
|
|
133
|
+
// not in use
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
|
|
137
|
+
[self sendEvent:@"onAdClosed" payload:nil];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
- (void)adView:(nonnull GADBannerView *)banner
|
|
141
|
+
didReceiveAppEvent:(nonnull NSString *)name
|
|
142
|
+
withInfo:(nullable NSString *)info {
|
|
143
|
+
[self sendEvent:@"onAppEvent"
|
|
144
|
+
payload:@{
|
|
145
|
+
@"name" : name,
|
|
146
|
+
@"data" : info,
|
|
147
|
+
}];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
- (void)recordManualImpression {
|
|
151
|
+
if ([_banner class] == [GAMBannerView class]) {
|
|
152
|
+
[((GAMBannerView *)_banner) recordImpression];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@end
|
|
@@ -17,165 +17,8 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
#import "RNGoogleMobileAdsBannerViewManager.h"
|
|
20
|
-
#import <GoogleMobileAds/GADAppEventDelegate.h>
|
|
21
|
-
#import <GoogleMobileAds/GADBannerView.h>
|
|
22
|
-
#import <GoogleMobileAds/GADBannerViewDelegate.h>
|
|
23
20
|
#import <React/RCTUIManager.h>
|
|
24
|
-
#import
|
|
25
|
-
#import "RNGoogleMobileAdsCommon.h"
|
|
26
|
-
|
|
27
|
-
@interface BannerComponent : RCTView <GADBannerViewDelegate, GADAppEventDelegate>
|
|
28
|
-
|
|
29
|
-
@property GADBannerView *banner;
|
|
30
|
-
@property(nonatomic, assign) BOOL requested;
|
|
31
|
-
|
|
32
|
-
@property(nonatomic, copy) NSArray *sizes;
|
|
33
|
-
@property(nonatomic, copy) NSString *unitId;
|
|
34
|
-
@property(nonatomic, copy) NSDictionary *request;
|
|
35
|
-
@property(nonatomic, copy) NSNumber *manualImpressionsEnabled;
|
|
36
|
-
@property(nonatomic, assign) BOOL propsChanged;
|
|
37
|
-
|
|
38
|
-
@property(nonatomic, copy) RCTBubblingEventBlock onNativeEvent;
|
|
39
|
-
|
|
40
|
-
- (void)requestAd;
|
|
41
|
-
|
|
42
|
-
@end
|
|
43
|
-
|
|
44
|
-
@implementation BannerComponent
|
|
45
|
-
|
|
46
|
-
- (void)didSetProps:(NSArray<NSString *> *)changedProps {
|
|
47
|
-
if (_propsChanged) {
|
|
48
|
-
[self requestAd];
|
|
49
|
-
}
|
|
50
|
-
_propsChanged = false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
- (void)initBanner:(GADAdSize)adSize {
|
|
54
|
-
if (_requested) {
|
|
55
|
-
[_banner removeFromSuperview];
|
|
56
|
-
}
|
|
57
|
-
if ([RNGoogleMobileAdsCommon isAdManagerUnit:_unitId]) {
|
|
58
|
-
_banner = [[GAMBannerView alloc] initWithAdSize:adSize];
|
|
59
|
-
|
|
60
|
-
((GAMBannerView *)_banner).validAdSizes = _sizes;
|
|
61
|
-
((GAMBannerView *)_banner).appEventDelegate = self;
|
|
62
|
-
((GAMBannerView *)_banner).enableManualImpressions = [_manualImpressionsEnabled boolValue];
|
|
63
|
-
} else {
|
|
64
|
-
_banner = [[GADBannerView alloc] initWithAdSize:adSize];
|
|
65
|
-
}
|
|
66
|
-
_banner.rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
|
67
|
-
_banner.delegate = self;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
- (void)setUnitId:(NSString *)unitId {
|
|
71
|
-
_unitId = unitId;
|
|
72
|
-
_propsChanged = true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
- (void)setSizes:(NSArray *)sizes {
|
|
76
|
-
__block NSMutableArray *adSizes = [[NSMutableArray alloc] initWithCapacity:sizes.count];
|
|
77
|
-
[sizes enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
|
|
78
|
-
GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue];
|
|
79
|
-
if (GADAdSizeEqualToSize(adSize, GADAdSizeInvalid)) {
|
|
80
|
-
RCTLogWarn(@"Invalid adSize %@", jsonValue);
|
|
81
|
-
} else {
|
|
82
|
-
[adSizes addObject:NSValueFromGADAdSize(adSize)];
|
|
83
|
-
}
|
|
84
|
-
}];
|
|
85
|
-
_sizes = adSizes;
|
|
86
|
-
_propsChanged = true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
- (void)setRequest:(NSDictionary *)request {
|
|
90
|
-
_request = request;
|
|
91
|
-
_propsChanged = true;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
- (void)setManualImpressionsEnabled:(BOOL *)manualImpressionsEnabled {
|
|
95
|
-
_manualImpressionsEnabled = [NSNumber numberWithBool:manualImpressionsEnabled];
|
|
96
|
-
_propsChanged = true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
- (void)requestAd {
|
|
100
|
-
#ifndef __LP64__
|
|
101
|
-
return; // prevent crash on 32bit
|
|
102
|
-
#endif
|
|
103
|
-
|
|
104
|
-
if (_unitId == nil || _sizes == nil || _request == nil || _manualImpressionsEnabled == nil) {
|
|
105
|
-
[self setRequested:NO];
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
[self initBanner:GADAdSizeFromNSValue(_sizes[0])];
|
|
110
|
-
[self addSubview:_banner];
|
|
111
|
-
_banner.adUnitID = _unitId;
|
|
112
|
-
[self setRequested:YES];
|
|
113
|
-
[_banner loadRequest:[RNGoogleMobileAdsCommon buildAdRequest:_request]];
|
|
114
|
-
[self sendEvent:@"onSizeChange"
|
|
115
|
-
payload:@{
|
|
116
|
-
@"width" : @(_banner.bounds.size.width),
|
|
117
|
-
@"height" : @(_banner.bounds.size.height),
|
|
118
|
-
}];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
- (void)sendEvent:(NSString *)type payload:(NSDictionary *_Nullable)payload {
|
|
122
|
-
if (!self.onNativeEvent) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
NSMutableDictionary *event = [@{
|
|
127
|
-
@"type" : type,
|
|
128
|
-
} mutableCopy];
|
|
129
|
-
|
|
130
|
-
if (payload != nil) {
|
|
131
|
-
[event addEntriesFromDictionary:payload];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
self.onNativeEvent(event);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
|
|
138
|
-
[self sendEvent:@"onAdLoaded"
|
|
139
|
-
payload:@{
|
|
140
|
-
@"width" : @(bannerView.bounds.size.width),
|
|
141
|
-
@"height" : @(bannerView.bounds.size.height),
|
|
142
|
-
}];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
- (void)bannerView:(GADBannerView *)bannerView didFailToReceiveAdWithError:(NSError *)error {
|
|
146
|
-
NSDictionary *errorAndMessage = [RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
|
|
147
|
-
[self sendEvent:@"onAdFailedToLoad" payload:errorAndMessage];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
- (void)bannerViewWillPresentScreen:(GADBannerView *)bannerView {
|
|
151
|
-
[self sendEvent:@"onAdOpened" payload:nil];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
- (void)bannerViewWillDismissScreen:(GADBannerView *)bannerView {
|
|
155
|
-
// not in use
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
- (void)bannerViewDidDismissScreen:(GADBannerView *)bannerView {
|
|
159
|
-
[self sendEvent:@"onAdClosed" payload:nil];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
- (void)bannerView:(GAMBannerView *)bannerView
|
|
163
|
-
didReceiveAppEvent:(NSString *)name
|
|
164
|
-
withInfo:(nullable NSString *)info {
|
|
165
|
-
[self sendEvent:@"onAppEvent"
|
|
166
|
-
payload:@{
|
|
167
|
-
@"name" : name,
|
|
168
|
-
@"data" : info,
|
|
169
|
-
}];
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
- (void)recordManualImpression {
|
|
173
|
-
if ([_banner class] == [GAMBannerView class]) {
|
|
174
|
-
[((GAMBannerView *)_banner) recordImpression];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
@end
|
|
21
|
+
#import "RNGoogleMobileAdsBannerComponent.h"
|
|
179
22
|
|
|
180
23
|
@implementation RNGoogleMobileAdsBannerViewManager
|
|
181
24
|
|
|
@@ -194,8 +37,8 @@ RCT_EXPORT_VIEW_PROPERTY(onNativeEvent, RCTBubblingEventBlock);
|
|
|
194
37
|
RCT_EXPORT_METHOD(recordManualImpression : (nonnull NSNumber *)reactTag) {
|
|
195
38
|
[self.bridge.uiManager
|
|
196
39
|
addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
197
|
-
|
|
198
|
-
if (!banner || ![banner isKindOfClass:[
|
|
40
|
+
RNGoogleMobileAdsBannerComponent *banner = viewRegistry[reactTag];
|
|
41
|
+
if (!banner || ![banner isKindOfClass:[RNGoogleMobileAdsBannerComponent class]]) {
|
|
199
42
|
RCTLogError(@"Cannot find NativeView with tag #%@", reactTag);
|
|
200
43
|
return;
|
|
201
44
|
}
|
|
@@ -206,7 +49,7 @@ RCT_EXPORT_METHOD(recordManualImpression : (nonnull NSNumber *)reactTag) {
|
|
|
206
49
|
@synthesize bridge = _bridge;
|
|
207
50
|
|
|
208
51
|
- (UIView *)view {
|
|
209
|
-
|
|
52
|
+
RNGoogleMobileAdsBannerComponent *banner = [RNGoogleMobileAdsBannerComponent new];
|
|
210
53
|
return banner;
|
|
211
54
|
}
|
|
212
55
|
|
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';
|