react-native-admob icon indicating copy to clipboard operation
react-native-admob copied to clipboard

Set size

Open EpicNem opened this issue 6 years ago • 6 comments

Is it possible to manually set the size of Ad? For example, I need to get a banner with 280x80. When I use SmartBanner, it not work because my banner is too big I think. Has it anyway to change the default size banner? Thanks

EpicNem avatar Dec 03 '17 21:12 EpicNem

Currently you only use one of the predefined constants, as can be seen here: https://github.com/sbugert/react-native-admob/blob/a6d1909f54fdf53d0912bc56c21ca77ae40a70cf/ios/RCTConvert%2BGADAdSize.m#L5-L29

I'll label this as an enhancement, because I can see how a value like "280x80" should be possible as well.

koenpunt avatar Dec 13 '17 12:12 koenpunt

Would be great to have this for Dfp / PublisherBanner as well, they also support custom ad sizes:

https://developers.google.com/mobile-ads-sdk/docs/dfp/android/banner#custom_ad_size https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/banner#custom_ad_size

engvik avatar Dec 18 '17 12:12 engvik

Looking to help PR this, any advice on where to start? Here's my best guess so far: https://github.com/nfl/react-native-admob/blob/master/ios/RNDFPBannerView.m#L65-L77

Currently this only allows an enumerable adSize.

- (void)setValidAdSizes:(NSArray *)adSizes
{
    NSMutableArray *validAdSizes = [[NSMutableArray alloc] initWithCapacity:adSizes.count];
    [adSizes enumerateObjectsUsingBlock:^(id jsonValue, NSUInteger idx, __unused BOOL *stop) {
        GADAdSize adSize = [RCTConvert GADAdSize:jsonValue];
        if (GADAdSizeEqualToSize(adSize, kGADAdSizeInvalid)) {
            RCTLogWarn(@"Invalid adSize %@", jsonValue);
        } else {
            [validAdSizes addObject:NSValueFromGADAdSize(adSize)];
        }
    }];
    _bannerView.validAdSizes = validAdSizes;
}

Can we extend this to allow custom ad sizes? (Here's an example: https://github.com/googleads/googleads-mobile-ios-examples/blob/master/Swift/advanced/APIDemo/APIDemo/DFPMultipleAdSizesViewController.swift#L56-L82)

Maybe an else if when a [[width],[height]] is provided?

let customGADAdSize = GADAdSizeFromCGSize(CGSize(width: 120, height: 20))
validAdSizes.append(NSValueFromGADAdSize(customGADAdSize))

potench avatar Mar 23 '18 19:03 potench

@potench hey.. so this should help: https://github.com/nfl/react-native-admob/blob/fd483b8f0de0c0fdc8556da446aed7346178529d/ios/RCTConvert%2BGADAdSize.m#L27-L28

This extra else should support any custom size now. Instead of passing "banner" you need to pass the size on this format: "{width,height}", e.g.: "{220,30}"

DulMephistos avatar Mar 23 '18 23:03 DulMephistos

Admob provide sizes-> https://support.google.com/adsense/answer/6002621?hl=en#top

In file RNAdMobBannerViewManager.java private AdSize getAdSizeFromString(String adSize) {

     AdSize square= new AdSize(125,125);

switch (adSize) { case "square": return square; }

use===== <AdMobBanner adSize="square" adUnitID="ca-app-pub-3940256099942544/6300978111" onAdFailedToLoad={error => console.error(error)} />

DilipLohar123 avatar Apr 24 '19 11:04 DilipLohar123

@fabio-cerdeiral-ck updating your answer...Now we can give admob banner size this '320x50' ( 320 is width and 50 is height) for custom banner size instead of BannerAdSize.LARGE_BANNER etc. example:

<BannerAd unitId={TestIds.BANNER} size= '320x50' requestOptions={{ requestNonPersonalizedAdsOnly: true, }} onAdLoaded={() => { console.log('Advert loaded'); }} onAdFailedToLoad={(error) => { console.error('Advert failed to load: ', error); }} />

faizantariq1 avatar May 16 '20 10:05 faizantariq1