diff --git a/RNGoogleMobileAdsExample/App.tsx b/RNGoogleMobileAdsExample/App.tsx
index de6ab97d..678a4d8d 100644
--- a/RNGoogleMobileAdsExample/App.tsx
+++ b/RNGoogleMobileAdsExample/App.tsx
@@ -184,10 +184,12 @@ class InterstitialTest implements Test {
class BannerTest implements Test {
bannerAdSize: BannerAdSize | string;
-
- constructor(bannerAdSize) {
+ maxHeight?: number;
+
+ constructor(bannerAdSize, maxHeight?: number) {
this.bannerAdSize = bannerAdSize;
this.bannerRef = React.createRef();
+ this.maxHeight = maxHeight;
}
getPath(): string {
@@ -196,7 +198,7 @@ class BannerTest implements Test {
.map(
s => s.toLowerCase().charAt(0).toUpperCase() + s.toLowerCase().slice(1),
)
- .join('');
+ .join('').concat(this.maxHeight ? `MaxHeight${this.maxHeight}` : '');
}
getTestType(): TestType {
@@ -214,6 +216,7 @@ class BannerTest implements Test {
: TestIds.BANNER
}
size={this.bannerAdSize}
+ maxHeight={this.maxHeight}
onPaid={(event: PaidEvent) => {
console.log(
`Paid: ${event.value} ${event.currency} (precision ${
@@ -994,6 +997,9 @@ class DebugMenuTest implements Test {
// All tests must be registered - a future feature will allow auto-bundling of tests via configured path or regex
Object.keys(BannerAdSize).forEach(bannerAdSize => {
+ if (bannerAdSize === "INLINE_ADAPTIVE_BANNER") {
+ TestRegistry.registerTest(new BannerTest(bannerAdSize, 100))
+ }
TestRegistry.registerTest(new BannerTest(bannerAdSize));
});
TestRegistry.registerTest(new CollapsibleBannerTest());
@@ -1025,7 +1031,7 @@ TestRegistry.registerTest(new DebugMenuTest());
const App = () => {
return (
-
+
diff --git a/RNGoogleMobileAdsExample/ios/Podfile.lock b/RNGoogleMobileAdsExample/ios/Podfile.lock
index 3d488af5..98a25b2c 100644
--- a/RNGoogleMobileAdsExample/ios/Podfile.lock
+++ b/RNGoogleMobileAdsExample/ios/Podfile.lock
@@ -1514,7 +1514,7 @@ PODS:
- React-logger (= 0.76.2)
- React-perflogger (= 0.76.2)
- React-utils (= 0.76.2)
- - RNGoogleMobileAds (14.4.0):
+ - RNGoogleMobileAds (14.4.2):
- DoubleConversion
- glog
- Google-Mobile-Ads-SDK (= 11.10.0)
@@ -1814,10 +1814,10 @@ SPEC CHECKSUMS:
React-utils: ed6cb7ba089ac0856aa104df12691e99abbf14e1
ReactCodegen: 93b271af49774429f34d7fd561197020d86436e2
ReactCommon: 208cb02e3c0bb8a727b3e1a1782202bcfa5d9631
- RNGoogleMobileAds: e9c8c98e7748e612c4669951336785d2f5ae1937
+ RNGoogleMobileAds: 9c58ba24a74d300ac88f64363276f33acd1a521a
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 96872ee462cfc43866ad013c8160d4ff6b85709b
PODFILE CHECKSUM: f699c82614f0340e3985855a1efdaa77a260037e
-COCOAPODS: 1.16.1
+COCOAPODS: 1.15.2
diff --git a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java
index 07ea925d..e5dacb53 100644
--- a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java
+++ b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java
@@ -135,11 +135,21 @@ public void setSizes(ReactNativeAdView reactViewGroup, ReadableArray value) {
payload.putDouble("height", adSize.getHeight());
sendEvent(reactViewGroup, EVENT_SIZE_CHANGE, payload);
}
-
+ reactViewGroup.setSizesArray(value);
reactViewGroup.setSizes(sizeList);
reactViewGroup.setPropsChanged(true);
}
+ @ReactProp(name = "maxAdHeight")
+ public void setMaxAdHeight(ReactNativeAdView reactViewGroup, float value) {
+ reactViewGroup.setMaxAdHeight(value);
+ ReadableArray adSizes = reactViewGroup.getSizesArray();
+ if (adSizes != null) {
+ this.setSizes(reactViewGroup, adSizes);
+ }
+ reactViewGroup.setPropsChanged(true);
+ }
+
@ReactProp(name = "manualImpressionsEnabled")
public void setManualImpressionsEnabled(ReactNativeAdView reactViewGroup, boolean value) {
reactViewGroup.setManualImpressionsEnabled(value);
diff --git a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java
index 3d24b7e1..96ccba3a 100644
--- a/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java
+++ b/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java
@@ -30,6 +30,7 @@
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.admanager.AdManagerAdRequest;
+import io.invertase.googlemobileads.common.ReactNativeAdView;
import io.invertase.googlemobileads.common.ReactNativeEventEmitter;
import java.util.ArrayList;
import java.util.Map;
@@ -51,8 +52,12 @@ static AdSize getAdSizeForAdaptiveBanner(String preDefinedAdSize, ViewGroup reac
DisplayMetrics outMetrics = new DisplayMetrics();
display.getMetrics(outMetrics);
int adWidth = (int) (outMetrics.widthPixels / outMetrics.density);
+ float maxAdHeight = ((ReactNativeAdView)reactViewGroup).getMaxAdHeight();
if ("INLINE_ADAPTIVE_BANNER".equals(preDefinedAdSize)) {
+ if (maxAdHeight > 0) {
+ return AdSize.getInlineAdaptiveBannerAdSize(adWidth, Math.round(Math.max(maxAdHeight, 32)));
+ }
return AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
reactViewGroup.getContext(), adWidth);
}
diff --git a/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeAdView.java b/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeAdView.java
index f021aa0b..a7481ce7 100644
--- a/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeAdView.java
+++ b/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeAdView.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.widget.FrameLayout;
+import com.facebook.react.bridge.ReadableArray;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import java.util.List;
@@ -18,6 +19,8 @@
public class ReactNativeAdView extends FrameLayout {
private AdRequest request;
private List sizes;
+ private ReadableArray sizesArray;
+ private float maxAdHeight;
private String unitId;
private boolean manualImpressionsEnabled;
private boolean propsChanged;
@@ -74,6 +77,22 @@ public List getSizes() {
return this.sizes;
}
+ public void setSizesArray(ReadableArray sizesArray) {
+ this.sizesArray = sizesArray;
+ }
+
+ public ReadableArray getSizesArray() {
+ return this.sizesArray;
+ }
+
+ public void setMaxAdHeight(float maxAdHeight) {
+ this.maxAdHeight = maxAdHeight;
+ }
+
+ public float getMaxAdHeight() {
+ return this.maxAdHeight;
+ }
+
public void setUnitId(String unitId) {
this.unitId = unitId;
}
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h
index f341abcc..f7bfb0ea 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.h
@@ -27,7 +27,9 @@
@property GADBannerView *banner;
@property(nonatomic, assign) BOOL requested;
+@property(nonatomic, copy) NSArray *sizeStrings;
@property(nonatomic, copy) NSArray *sizes;
+@property(nonatomic, assign) CGFloat maxAdHeight;
@property(nonatomic, copy) NSString *unitId;
@property(nonatomic, copy) NSDictionary *request;
@property(nonatomic, copy) NSNumber *manualImpressionsEnabled;
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
index 15901dd8..000b80b4 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
@@ -66,8 +66,13 @@ - (void)setUnitId:(NSString *)unitId {
- (void)setSizes:(NSArray *)sizes {
__block NSMutableArray *adSizes = [[NSMutableArray alloc] initWithCapacity:sizes.count];
+ _sizeStrings = sizes;
+ CGFloat maxAdHeight = -1;
+ if (_maxAdHeight > 0) {
+ maxAdHeight = _maxAdHeight;
+ }
[sizes enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
- GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue];
+ GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue withMaxHeight: maxAdHeight];
if (GADAdSizeEqualToSize(adSize, GADAdSizeInvalid)) {
RCTLogWarn(@"Invalid adSize %@", jsonValue);
} else {
@@ -78,6 +83,14 @@ - (void)setSizes:(NSArray *)sizes {
_propsChanged = true;
}
+- (void)setMaxAdHeight:(CGFloat)maxAdHeight {
+ _maxAdHeight = maxAdHeight;
+ if (_sizeStrings != nil) {
+ [self setSizes: _sizeStrings];
+ }
+ _propsChanged = true;
+}
+
- (void)setRequest:(NSString *)request {
NSData *jsonData = [request dataUsingEncoding:NSUTF8StringEncoding];
NSError *error = nil;
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.h b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.h
index a8c55b8c..8dfef861 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.h
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.h
@@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, assign) BOOL requested;
@property(nonatomic, copy) NSArray *sizes;
+@property(nonatomic, assign) CGFloat maxAdHeight;
@property(nonatomic, copy) NSString *unitId;
@property(nonatomic, copy) NSDictionary *request;
@property(nonatomic, copy) NSNumber *manualImpressionsEnabled;
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm
index 13ad4b48..ea5e05a7 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm
@@ -55,11 +55,15 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
propsChanged = true;
}
- if (oldViewProps.sizes != newViewProps.sizes) {
+ if (oldViewProps.sizes != newViewProps.sizes || oldViewProps.maxAdHeight != newViewProps.maxAdHeight) {
NSMutableArray *adSizes = [NSMutableArray arrayWithCapacity:newViewProps.sizes.size()];
+ CGFloat maxAdHeight = -1;
+ if (newViewProps.maxAdHeight > 0) {
+ maxAdHeight = newViewProps.maxAdHeight;
+ }
for (auto i = 0; i < newViewProps.sizes.size(); i++) {
NSString *jsonValue = [[NSString alloc] initWithUTF8String:newViewProps.sizes[i].c_str()];
- GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue];
+ GADAdSize adSize = [RNGoogleMobileAdsCommon stringToAdSize:jsonValue withMaxHeight: maxAdHeight];
if (GADAdSizeEqualToSize(adSize, GADAdSizeInvalid)) {
RCTLogWarn(@"Invalid adSize %@", jsonValue);
} else {
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.mm b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.mm
index 1e7b0102..2bf7dd48 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.mm
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.mm
@@ -33,6 +33,8 @@ @implementation RNGoogleMobileAdsBannerViewManager
RCT_EXPORT_VIEW_PROPERTY(sizes, NSArray);
+RCT_EXPORT_VIEW_PROPERTY(maxAdHeight, CGFloat);
+
RCT_EXPORT_VIEW_PROPERTY(unitId, NSString);
RCT_EXPORT_VIEW_PROPERTY(request, NSString);
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h b/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h
index 2ee019aa..70472963 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h
@@ -34,7 +34,7 @@
error:(nullable NSDictionary *)error
data:(nullable NSDictionary *)data;
-+ (GADAdSize)stringToAdSize:(NSString *)value;
++ (GADAdSize)stringToAdSize:(NSString *)value withMaxHeight:(CGFloat)maxHeight;
+ (BOOL)isAdManagerUnit:(NSString *)unitId;
diff --git a/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.mm b/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.mm
index 4d5d6b7c..97321bc5 100644
--- a/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.mm
+++ b/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.mm
@@ -162,7 +162,7 @@ + (void)sendAdEvent:(NSString *)event
[[RNRCTEventEmitter shared] sendEventWithName:event body:payload];
}
-+ (GADAdSize)stringToAdSize:(NSString *)value {
++ (GADAdSize)stringToAdSize:(NSString *)value withMaxHeight:(CGFloat)maxHeight {
NSError *error = nil;
NSRegularExpression *regex =
[NSRegularExpression regularExpressionWithPattern:@"([0-9]+)x([0-9]+)"
@@ -206,6 +206,9 @@ + (GADAdSize)stringToAdSize:(NSString *)value {
}
CGFloat viewWidth = frame.size.width;
if ([value isEqualToString:@"INLINE_ADAPTIVE_BANNER"]) {
+ if (maxHeight > 0) {
+ return GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(viewWidth, MAX(maxHeight, 32.0));
+ }
return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(viewWidth);
}
return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth);
diff --git a/src/ads/BaseAd.tsx b/src/ads/BaseAd.tsx
index 1a32ba0b..1847545b 100644
--- a/src/ads/BaseAd.tsx
+++ b/src/ads/BaseAd.tsx
@@ -33,7 +33,7 @@ const sizeRegex = /([0-9]+)x([0-9]+)/;
export const BaseAd = React.forwardRef<
React.ElementRef,
GAMBannerAdProps
->(({ unitId, sizes, requestOptions, manualImpressionsEnabled, ...props }, ref) => {
+>(({ unitId, sizes, maxHeight, requestOptions, manualImpressionsEnabled, ...props }, ref) => {
const [dimensions, setDimensions] = useState<(number | DimensionValue)[]>([0, 0]);
const debouncedSetDimensions = debounce(setDimensions, 100);
@@ -168,6 +168,7 @@ export const BaseAd = React.forwardRef<