The following sections show you how to load and then show and hide a banner or MREC ad.
Loading a Banner or MREC
The following code shows you how to load a banner or MREC ad by using your Ad Unit ID, desired position, and (for banners) desired background color.
MAX sizes the ad for you automatically:
As of React Native plugin version 7.0.0, you can preload ads for native UI components before you mount AdView.
When you mount AdView with the Ad Unit ID you preloaded, AdView is constructed with a preloaded native UI component.
This allows the ads to display quickly.
React Native plugin version 8.1.0 updates this preloading feature to support multiple AdView instances.
The preloadNativeUIComponentAdView() method returns an AdViewId, which you can use to specify the preloaded ad when you mount an AdView.
When you unmount an AdView, the preloaded native UI component is not destroyed.
Instead, it is cached and reused for the next mount.
To release its resources, you must manually destroy it when you no longer need it:
If you omit an AdViewId when you mount an AdView, the component dynamically loads an ad.
In such a case, when you unmount the AdView, it is automatically destroyed and cannot be reused.
Adaptive banners are responsive banners with heights that derive from the device type and the width of the banner.
Banners from ad networks that support adaptive banners are adaptive by default, starting in plugin version 2.3.0.
To disable adaptive banners, set an extra flag as in the following examples:
If you need to adjust your UI based on the adaptive banner size, you can retrieve the width and height of the loaded ad, in dp.
The following code demonstrates how to do this:
You may want to stop auto-refresh for an ad.
You may want to do this, for instance, when you hide an ad or you want to manually refresh.
Stop auto-refresh for a banner or MREC ad with the following code: