From 9e20bcaac50d99f8b746bf84d9114dd4399a4c0e Mon Sep 17 00:00:00 2001 From: Dylan Companjen Date: Tue, 17 Nov 2020 19:55:28 +0100 Subject: [PATCH 1/3] feat: adaptive banner support --- .../admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m | 9 ++++++++- packages/admob/lib/BannerAdSize.js | 1 + packages/admob/lib/index.d.ts | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m b/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m index 636193a2f8..781e6470dc 100644 --- a/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m +++ b/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m @@ -73,7 +73,14 @@ - (void)requestAd { return; } - [self initBanner:[RNFBAdMobCommon stringToAdSize:_size]]; + GADAdSize adSize; + if ([value isEqualToString:@"ADAPTIVE_BANNER"]) { + CGFloat viewWidth = [[UIScreen mainScreen]bounds].size.width; + GADAdSize adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth); + } else { + adSize = [RNFBAdMobCommon stringToAdSize:_size]; + } + [self initBanner:adSize]; [self addSubview:_banner]; _banner.adUnitID = _unitId; [self setRequested:YES]; diff --git a/packages/admob/lib/BannerAdSize.js b/packages/admob/lib/BannerAdSize.js index 274725342a..ead444103e 100644 --- a/packages/admob/lib/BannerAdSize.js +++ b/packages/admob/lib/BannerAdSize.js @@ -18,6 +18,7 @@ export default { BANNER: 'BANNER', + ADAPTIVE_BANNER: 'ADAPTIVE_BANNER', FULL_BANNER: 'FULL_BANNER', LARGE_BANNER: 'LARGE_BANNER', LEADERBOARD: 'LEADERBOARD', diff --git a/packages/admob/lib/index.d.ts b/packages/admob/lib/index.d.ts index 921d2db4e6..042fc332e4 100644 --- a/packages/admob/lib/index.d.ts +++ b/packages/admob/lib/index.d.ts @@ -237,6 +237,11 @@ export namespace FirebaseAdMobTypes { */ SMART_BANNER: 'SMART_BANNER'; + /** + * A (next generation) dynamically sized banner that is full-width and auto-height. + */ + APAPTIVE_BANNER: 'APAPTIVE_BANNER'; + /** * A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes. */ From 9b47d82621f0cbe52ec6dea2a7bfddc2f33f08c4 Mon Sep 17 00:00:00 2001 From: Dylan Companjen Date: Tue, 17 Nov 2020 20:19:03 +0100 Subject: [PATCH 2/3] refactor: move size determination to stringToAdSize --- .../admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m | 9 +-------- packages/admob/ios/RNFBAdMob/RNFBAdMobCommon.m | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m b/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m index 781e6470dc..636193a2f8 100644 --- a/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m +++ b/packages/admob/ios/RNFBAdMob/RNFBAdMobBannerViewManager.m @@ -73,14 +73,7 @@ - (void)requestAd { return; } - GADAdSize adSize; - if ([value isEqualToString:@"ADAPTIVE_BANNER"]) { - CGFloat viewWidth = [[UIScreen mainScreen]bounds].size.width; - GADAdSize adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth); - } else { - adSize = [RNFBAdMobCommon stringToAdSize:_size]; - } - [self initBanner:adSize]; + [self initBanner:[RNFBAdMobCommon stringToAdSize:_size]]; [self addSubview:_banner]; _banner.adUnitID = _unitId; [self setRequested:YES]; diff --git a/packages/admob/ios/RNFBAdMob/RNFBAdMobCommon.m b/packages/admob/ios/RNFBAdMob/RNFBAdMobCommon.m index 23d514a04e..fbb74d7d80 100644 --- a/packages/admob/ios/RNFBAdMob/RNFBAdMobCommon.m +++ b/packages/admob/ios/RNFBAdMob/RNFBAdMobCommon.m @@ -181,6 +181,9 @@ + (GADAdSize)stringToAdSize:(NSString *)value { return kGADAdSizeLeaderboard; } else if ([value isEqualToString:@"SMART_BANNER"]) { return kGADAdSizeSmartBannerPortrait; + } else if ([value isEqualToString:@"ADAPTIVE_BANNER"]) { + CGFloat viewWidth = [[UIScreen mainScreen]bounds].size.width; + return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth); } else { return kGADAdSizeBanner; } From ac1aba62e3c1a70d5a03b887cc60e2fe5bfd3b37 Mon Sep 17 00:00:00 2001 From: Dylan Companjen Date: Tue, 17 Nov 2020 20:32:13 +0100 Subject: [PATCH 3/3] fix: typo and ios only note --- packages/admob/lib/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/admob/lib/index.d.ts b/packages/admob/lib/index.d.ts index 042fc332e4..50583170ea 100644 --- a/packages/admob/lib/index.d.ts +++ b/packages/admob/lib/index.d.ts @@ -239,8 +239,10 @@ export namespace FirebaseAdMobTypes { /** * A (next generation) dynamically sized banner that is full-width and auto-height. + * + * iOS only */ - APAPTIVE_BANNER: 'APAPTIVE_BANNER'; + ADAPTIVE_BANNER: 'ADAPTIVE_BANNER'; /** * A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.