react-native-google-mobile-ads 9.0.0 → 9.1.1

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.
@@ -74,7 +74,6 @@ class RNGoogleMobileAdsAppOpenModule: NSObject {
74
74
  GADAppOpenAd.load(
75
75
  withAdUnitID: adUnitId,
76
76
  request: adRequest,
77
- orientation: UIInterfaceOrientation.portrait,
78
77
  completionHandler: completionHandler
79
78
  )
80
79
  }
@@ -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 <React/RCTView.h>
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
- BannerComponent *banner = viewRegistry[reactTag];
198
- if (!banner || ![banner isKindOfClass:[BannerComponent class]]) {
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
- BannerComponent *banner = [BannerComponent new];
52
+ RNGoogleMobileAdsBannerComponent *banner = [RNGoogleMobileAdsBannerComponent new];
210
53
  return banner;
211
54
  }
212
55
 
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = void 0;
7
7
  // Generated by genversion.
8
- const version = '9.0.0';
8
+ const version = '9.1.1';
9
9
  exports.version = version;
10
10
  //# sourceMappingURL=version.js.map
@@ -1,3 +1,3 @@
1
1
  // Generated by genversion.
2
- export const version = '9.0.0';
2
+ export const version = '9.1.1';
3
3
  //# sourceMappingURL=version.js.map
@@ -1,4 +1,4 @@
1
- export declare const SDK_VERSION = "9.0.0";
1
+ export declare const SDK_VERSION = "9.1.1";
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.0.0";
1
+ export declare const version = "9.1.1";
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.0.0",
3
+ "version": "9.1.1",
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",
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "sdkVersions": {
43
43
  "ios": {
44
- "googleMobileAds": "9.12.0",
44
+ "googleMobileAds": "9.14.0",
45
45
  "googleUmp": "2.0.0"
46
46
  },
47
47
  "android": {
@@ -49,7 +49,7 @@
49
49
  "targetSdk": 30,
50
50
  "compileSdk": 31,
51
51
  "buildTools": "31.0.0",
52
- "googleMobileAds": "21.3.0",
52
+ "googleMobileAds": "21.4.0",
53
53
  "googleUmp": "2.0.0"
54
54
  }
55
55
  },
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Generated by genversion.
2
- export const version = '9.0.0';
2
+ export const version = '9.1.1';