Skip to main content

Banner ads

<BannerAd> is a NitroUI view. It loads an ad once adUnitId is set and lays itself out at the ad size.

import { Admob, BannerAd } from 'nitro-ui-admob'

function Footer() {
return (
<BannerAd
adUnitId={Admob.testAdUnitId('banner')}
layout={{ marginTop: 24 }}
onAdLoaded={({ width, height }) => console.log(width, height)}
onAdFailedToLoad={(error) => console.warn(error.code, error.message)}
/>
)
}

Sizes​

sizeWidth × height (pt on iOS, dp on Android)
anchoredAdaptive (default)Laid-out width × height chosen by the SDK
banner320 × 50
largeBanner320 × 100
mediumRectangle300 × 250
fullBanner468 × 60
leaderboard728 × 90

Fixed sizes​

A fixed-size banner lays out at its ad size, so you do not need to reserve space:

<BannerAd adUnitId={adUnitId} size="mediumRectangle" />

Anchored adaptive​

anchoredAdaptive uses the width the view is laid out with, and asks the SDK for a large anchored adaptive banner of that width. The view starts at height 0, then takes the height reported through onSizeChange before the request. Its width comes from its container or from layout.

Nothing loads until the view has a width greater than 0. A new width loads a new ad.

Overriding the size​

layout props override the size-derived width and height. The banner stays centered in the view at its ad size.

When a new ad loads​

The view requests a new ad when any of these change:

  • adUnitId (an empty string loads nothing),
  • size,
  • the contents of requestOptions,
  • for anchoredAdaptive, the laid-out width.

Passing a new requestOptions object with the same contents does not reload.

Events​

PropCalled when
onSizeChangeBefore each request, with the ad size, so the layout can reserve it.
onAdLoadedAn ad loaded, with its size.
onAdFailedToLoadAn ad request failed, with an AdmobError.
onAdImpressionThe SDK recorded an impression.
onAdClickedThe SDK recorded a click.
onAdPaidThe SDK estimated the impression's revenue.
onAdOpenedThe ad opened an overlay over the app.
onAdClosedThe overlay opened by the ad was dismissed.

Unmounting​

On unmount the component calls the native view's destroy(): ad requests stop, callbacks are dropped and the native banner is released.