cordova-plugin-admob-nextgen 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-admob-nextgen",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Google Mobile Ads Next Gen SDK for Cordova. High performance and modular architecture. ",
5
5
  "cordova": {
6
6
  "id": "cordova-plugin-admob-nextgen",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
2
  <plugin id="cordova-plugin-admob-nextgen"
3
- version="1.0.7"
3
+ version="1.0.8"
4
4
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
5
5
  xmlns:android="http://schemas.android.com/apk/res/android">
6
6
 
@@ -33,6 +33,7 @@
33
33
  self.plugin = plugin;
34
34
  self.lastAdUnitId = @"";
35
35
  self.lastSizeStr = @"";
36
+
36
37
  self.currentPosition = @"bottom";
37
38
  self.lastPosition = @"bottom";
38
39
 
@@ -58,6 +59,29 @@
58
59
  [[NSNotificationCenter defaultCenter] removeObserver:self];
59
60
  }
60
61
 
62
+ #pragma mark - Smart Window Helper (Diadopsi dari EmiBanner)
63
+
64
+ - (UIWindow *)getKeyWindow {
65
+ UIWindow *window = nil;
66
+ if (@available(iOS 13.0, *)) {
67
+ for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
68
+ if (windowScene.activationState == UISceneActivationStateForegroundActive) {
69
+ for (UIWindow *w in windowScene.windows) {
70
+ if (w.isKeyWindow) { window = w; break; }
71
+ }
72
+ }
73
+ if (window) break;
74
+ }
75
+ }
76
+ if (!window) {
77
+ #pragma clang diagnostic push
78
+ #pragma clang diagnostic ignored "-Wdeprecated-declarations"
79
+ window = [UIApplication sharedApplication].keyWindow;
80
+ #pragma clang diagnostic pop
81
+ }
82
+ return window;
83
+ }
84
+
61
85
  #pragma mark - Main Methods
62
86
 
63
87
  - (void)createBanner:(NSDictionary *)options command:(CDVInvokedUrlCommand *)command {
@@ -96,7 +120,6 @@
96
120
 
97
121
  if (self.bannerView != nil && isSameId && isSameSize) {
98
122
  if (self.isAutoShow) {
99
-
100
123
  [self showBannerInternal];
101
124
  CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:@"Banner Updated (Cached)"];
102
125
  [self.plugin.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
@@ -179,84 +202,63 @@
179
202
  return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(frame.size.width);
180
203
  }
181
204
 
182
- #pragma mark - NATIVE FRAME MANIPULATION (THE DEFINITIVE WAY)
183
-
184
205
  - (void)layoutViews {
185
206
  dispatch_async(dispatch_get_main_queue(), ^{
207
+ UIViewController *rootVC = self.plugin.viewController;
186
208
  UIView *webView = self.plugin.webView;
187
- UIView *superView = webView.superview;
188
-
189
- if (!webView || !superView) return;
190
-
191
- CGRect superBounds = superView.bounds;
192
- CGRect webFrame = superBounds;
193
-
194
- if (self.bannerView && self.activeBannerHeight > 0) {
195
-
196
- CGFloat safeTop = 0;
197
- if (@available(iOS 11.0, *)) {
198
-
199
- UIWindow *window = webView.window;
200
-
201
- if (!window) {
202
- if (@available(iOS 13.0, *)) {
203
- for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
204
- if (windowScene.activationState == UISceneActivationStateForegroundActive) {
205
- for (UIWindow *w in windowScene.windows) {
206
- if (w.isKeyWindow) {
207
- window = w;
208
- break;
209
- }
210
- }
211
- }
212
- if (window) break;
213
- }
214
- }
215
- }
209
+ if (!rootVC || !webView) return;
216
210
 
217
- if (!window) {
218
- #pragma clang diagnostic push
219
- #pragma clang diagnostic ignored "-Wdeprecated-declarations"
220
- window = UIApplication.sharedApplication.keyWindow;
221
- #pragma clang diagnostic pop
222
- }
211
+ UIWindow *window = [self getKeyWindow];
212
+ UIEdgeInsets safeArea = (window) ? window.safeAreaInsets : UIEdgeInsetsZero;
223
213
 
224
- if (window) {
225
- safeTop = window.safeAreaInsets.top;
226
- }
227
- }
214
+ CGFloat screenH = UIScreen.mainScreen.bounds.size.height;
215
+ CGFloat screenW = UIScreen.mainScreen.bounds.size.width;
228
216
 
229
- CGRect bannerFrame = CGRectMake(0, 0, superBounds.size.width, self.activeBannerHeight);
230
- if ([self.currentPosition isEqualToString:@"top"]) {
217
+ if (safeArea.bottom == 0 && screenH >= 812.0) safeArea.bottom = 34.0;
218
+ if (safeArea.top == 0 && screenH >= 812.0) safeArea.top = 44.0;
231
219
 
232
- bannerFrame.origin.y = self.isOverlapping ? 0 : safeTop;
233
- } else {
220
+ rootVC.view.backgroundColor = [UIColor blackColor];
221
+ webView.superview.backgroundColor = [UIColor blackColor];
222
+
223
+ CGRect fullScreenRect = CGRectMake(0, 0, screenW, screenH);
224
+
225
+ if (self.isBannerVisible && self.bannerView && self.activeBannerHeight > 0) {
234
226
 
235
- bannerFrame.origin.y = superBounds.size.height - self.activeBannerHeight;
227
+ CGSize adSize = self.bannerView.intrinsicContentSize;
228
+ CGFloat bH = adSize.height > 0 ? adSize.height : self.activeBannerHeight;
229
+ CGFloat bW = adSize.width > 0 ? adSize.width : self.bannerView.bounds.size.width;
230
+ CGFloat bX = (screenW - bW) / 2.0;
231
+ CGFloat bY = 0;
232
+
233
+ if ([self.currentPosition isEqualToString:@"top"]) {
234
+ bY = safeArea.top;
235
+ } else {
236
+ bY = screenH - safeArea.bottom - bH;
236
237
  }
237
- self.bannerView.frame = bannerFrame;
238
238
 
239
- self.bannerView.hidden = !self.isBannerVisible;
239
+ self.bannerView.frame = CGRectMake(bX, bY, bW, bH);
240
+ self.bannerView.hidden = NO;
240
241
 
241
- if (self.isBannerVisible && !self.isOverlapping) {
242
+ if (!self.isOverlapping) {
243
+ CGRect newWebFrame = fullScreenRect;
242
244
  if ([self.currentPosition isEqualToString:@"top"]) {
243
-
244
- webFrame.origin.y = bannerFrame.origin.y + self.activeBannerHeight;
245
- webFrame.size.height = superBounds.size.height - webFrame.origin.y;
245
+ newWebFrame.origin.y = bY + bH;
246
+ newWebFrame.size.height = screenH - newWebFrame.origin.y;
246
247
  } else {
247
-
248
- webFrame.origin.y = 0;
249
- webFrame.size.height = bannerFrame.origin.y;
248
+ newWebFrame.origin.y = 0;
249
+ newWebFrame.size.height = bY;
250
250
  }
251
+ webView.frame = newWebFrame;
252
+ } else {
253
+ webView.frame = fullScreenRect;
251
254
  }
252
255
  } else {
253
256
  if (self.bannerView) self.bannerView.hidden = YES;
257
+ webView.frame = fullScreenRect;
254
258
  }
255
259
 
256
- webView.frame = webFrame;
257
-
258
- if (self.bannerView) {
259
- [superView bringSubviewToFront:self.bannerView];
260
+ if (self.bannerView && self.isBannerVisible) {
261
+ [webView.superview bringSubviewToFront:self.bannerView];
260
262
  }
261
263
  });
262
264
  }
@@ -266,14 +268,14 @@
266
268
  - (void)showBannerInternal {
267
269
  if (self.bannerView) {
268
270
  self.isBannerVisible = YES;
269
- [self layoutViews];
271
+ [self layoutViews];
270
272
  }
271
273
  }
272
274
 
273
275
  - (void)hideBannerInternal {
274
276
  if (self.bannerView) {
275
277
  self.isBannerVisible = NO;
276
- [self layoutViews];
278
+ [self layoutViews];
277
279
  }
278
280
  }
279
281
 
@@ -282,7 +284,7 @@
282
284
  self.isBannerVisible = NO;
283
285
  self.activeBannerHeight = 0;
284
286
 
285
- [self layoutViews];
287
+ [self layoutViews];
286
288
 
287
289
  [self.bannerView removeFromSuperview];
288
290
  self.bannerView.delegate = nil;