Skip to content

xing-zheng/react-native-admob

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version

react-native-admob

A react-native module for Google AdMob GADBanner and GADInterstitial (react-native v0.19.0 or newer required).

The banner is implemented as a component while the interstitial has an imperative API.

Installation

With rnpm (recommended)

  1. npm i react-native-admob -S
  2. rnpm link
  3. Add Google AdMob Framework to your Xcode project. This is only needed for iOS and guarantees your app is using the newest admob version.

Manual Installation

iOS
  1. npm i react-native-admob -S
  2. Add Google AdMob Framework to your Xcode project.
  3. Add react-native-admob static library to your Xcode project like explained here. (Step 3 of this guide is not needed)
Android
  1. npm i react-native-admob -S
  2. Make the following additions to the given files:

android/settings.gradle

include ':RNAdMob', ':app'
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')

android/app/build.gradle

dependencies {
   ...
   compile project(':RNAdMob')
}

MainActivity.java

On top, where imports are:

import com.sbugert.rnadmob.RNAdMobPackage;

Under protected List<ReactPackage> getPackages() {:

  return Arrays.<ReactPackage>asList(
    new MainReactPackage(),
    new RNAdMobPackage()
  );

Usage

import { AdMobBanner, AdMobInterstitial } from 'react-native-admob'

// Display a banner
<AdMobBanner
  bannerSize={"fullBanner"}
  adUnitID={"your-admob-unit-id"}
  didFailToReceiveAdWithError={this.bannerError} />

// Display an intersticial
// if in DEV mode, display a test interstitial, otherwise display a real ad
AdMobInterstitial.setAdUnitId('your-admob-unit-id');
AdMobInterstitial.tryShowNewInterstitial(__DEV__ ? "your-device-id" : null);

For a full example reference to the example project.

Reference

AdMobBanner

bannerSize property

Corresponding to iOS framework banner size constants

Prop value Description Size
banner Standard Banner for Phones and Tablets 320x50
largeBanner Large Banner for Phones and Tablets 320x100
mediumRectangle IAB Medium Rectangle for Phones and Tablets 300x250
fullBanner IAB Full-Size Banner for Tablet 468x60
leaderboard IAB Leaderboard for Tablets 728x90
smartBannerPortrait Smart Banner for Phones and Tablets (default) `Screen width x 32
smartBannerLandscape Smart Banner for Phones and Tablets `Screen width x 32
Events as function props

Corresponding to Ad lifecycle event callbacks

Prop
adViewDidReceiveAd()
didFailToReceiveAdWithError(errorDescription)
adViewWillPresentScreen()
adViewWillDismissScreen()
adViewDidDismissScreen()
adViewWillLeaveApplication()

TODO

About

A react-native component for Google AdMob banners

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 39.6%
  • Java 37.3%
  • JavaScript 23.1%