Skip to content

Commit a28d0ca

Browse files
committed
update README
1 parent 3776a3c commit a28d0ca

File tree

1 file changed

+61
-69
lines changed

1 file changed

+61
-69
lines changed

README.md

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,32 @@ The banner is implemented as a component while the interstitial has an imperativ
2626
1. `npm i react-native-admob -S`
2727
2. Make the following additions to the given files:
2828

29-
**android/settings.gradle**
29+
**`android/settings.gradle`**
3030

31-
```
32-
include ':RNAdMob', ':app'
33-
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')
31+
```groovy
32+
include ':react-native-admob'
33+
project(':react-native-admob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')
3434
```
3535

36-
**android/app/build.gradle**
36+
**`android/app/build.gradle`**
3737

38-
```
38+
```groovy
3939
dependencies {
40-
...
41-
compile project(':RNAdMob')
40+
// ...
41+
compile project(':react-native-admob')
4242
}
4343
```
4444

45-
**MainApplication.java**
45+
**`MainApplication.java`**
4646

47-
#### RN < 0.29
47+
In **MainAplication.java** on top, where imports are:
4848

49-
In **MainActivity.java** on top, where imports are:
5049
```java
5150
import com.sbugert.rnadmob.RNAdMobPackage;
5251
```
5352

54-
Under `protected List<ReactPackage> getPackages() {`:
55-
```java
56-
return Arrays.<ReactPackage>asList(
57-
new MainReactPackage(),
58-
new RNAdMobPackage()
59-
);
60-
```
53+
Under `protected List<ReactPackage> getPackages() {`:
6154

62-
#### RN >= 0.29
63-
64-
In **MainAplication.java** on top, where imports are:
65-
```java
66-
import com.sbugert.rnadmob.RNAdMobPackage;
67-
```
68-
69-
Under `protected List<ReactPackage> getPackages() {`:
7055
```java
7156
return Arrays.<ReactPackage>asList(
7257
new MainReactPackage(),
@@ -77,36 +62,38 @@ Under `protected List<ReactPackage> getPackages() {`:
7762
### Usage
7863

7964
```javascript
80-
import {
81-
AdMobBanner,
82-
AdMobInterstitial,
65+
import {
66+
AdMobBanner,
67+
AdMobInterstitial,
8368
PublisherBanner,
84-
AdMobRewarded
69+
AdMobRewarded,
8570
} from 'react-native-admob'
8671

8772
// Display a banner
8873
<AdMobBanner
89-
bannerSize="fullBanner"
74+
adSize="fullBanner"
9075
adUnitID="your-admob-unit-id"
91-
testDeviceID="EMULATOR"
92-
didFailToReceiveAdWithError={this.bannerError} />
76+
testDevices={[AdMobBanner.simulatorId]}
77+
onDidFailToReceiveAdWithError={error => console.error(error)}
78+
/>
9379

9480
// Display a DFP Publisher banner
9581
<PublisherBanner
96-
bannerSize="fullBanner"
82+
adSize="fullBanner"
9783
adUnitID="your-admob-unit-id"
98-
testDeviceID="EMULATOR"
99-
didFailToReceiveAdWithError={this.bannerError}
100-
admobDispatchAppEvent={this.adMobEvent} />
84+
testDevices={[PublisherBanner.simulatorId]}
85+
onDidFailToReceiveAdWithError={error => console.error(error)}
86+
onAdmobDispatchAppEvent={event => console.log(event.name, event.info)}
87+
/>
10188

10289
// Display an interstitial
10390
AdMobInterstitial.setAdUnitID('your-admob-unit-id');
104-
AdMobInterstitial.setTestDeviceID('EMULATOR');
105-
AdMobInterstitial.requestAd(AdMobInterstitial.showAd);
91+
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
92+
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
10693

10794
// Display a rewarded ad
10895
AdMobRewarded.setAdUnitID('your-admob-unit-id');
109-
AdMobRewarded.requestAd(AdMobRewarded.showAd);
96+
AdMobRewarded.requestAd().then(() => AdMobRewarded.showAd());
11097
```
11198

11299
For a full example reference to the [example project](Example).
@@ -115,7 +102,8 @@ For a full example reference to the [example project](Example).
115102

116103
#### AdMobBanner
117104

118-
##### bannerSize property
105+
##### adSize property
106+
119107
*Corresponding to [iOS framework banner size constants](https://developers.google.com/admob/ios/banner)*
120108

121109
| Prop value | Description | Size |
@@ -125,51 +113,53 @@ For a full example reference to the [example project](Example).
125113
|`mediumRectangle` |IAB Medium Rectangle for Phones and Tablets |300x250 |
126114
|`fullBanner` |IAB Full-Size Banner for Tablet |468x60 |
127115
|`leaderboard` |IAB Leaderboard for Tablets |728x90 |
128-
|**`smartBannerPortrait`**|Smart Banner for Phones and Tablets (default)|Screen width x 32|50|90|
116+
|`smartBannerPortrait` |Smart Banner for Phones and Tablets (default)|Screen width x 32|50|90|
129117
|`smartBannerLandscape` |Smart Banner for Phones and Tablets |Screen width x 32|50|90|
130118

131119
*Note: There is no `smartBannerPortrait` and `smartBannerLandscape` on Android. Both prop values will map to `smartBanner`*
132120

133-
134121
##### Events as function props
122+
135123
*Corresponding to [Ad lifecycle event callbacks](https://developers.google.com/admob/ios/banner)*
136124

137125
| Prop |
138126
|------------------------------------------------|
139-
|`adViewDidReceiveAd()` |
140-
|`didFailToReceiveAdWithError(errorDescription)` |
141-
|`adViewWillPresentScreen()` |
142-
|`adViewWillDismissScreen()` |
143-
|`adViewDidDismissScreen()` |
144-
|`adViewWillLeaveApplication()` |
127+
|`onAdViewDidReceiveAd()` |
128+
|`onDidFailToReceiveAdWithError(error)` |
129+
|`onAdViewWillPresentScreen()` |
130+
|`onAdViewWillDismissScreen()` |
131+
|`onAdViewDidDismissScreen()` |
132+
|`onAdViewWillLeaveApplication()` |
145133

146134

147135
#### PublisherBanner
148136

149137
Same as AdMobBanner, except it has an extra event prop:
150138

151-
|'admobDispatchAppEvent()' |
139+
| Prop | |
140+
|`onAdmobDispatchAppEvent(event)` | Event has a `name` and `info` property |
152141

153-
This handles App events that Admob/DFP can send back to the app.
154-
More info here: https://developers.google.com/mobile-ads-sdk/docs/dfp/android/banner#ios_app-events
142+
This handles App events that AdMob/DFP can send back to the app.
143+
More info here: https://developers.google.com/mobile-ads-sdk/docs/dfp/ios/banner#app_events
155144

145+
And also has an additional `validAdSizes` property, which accepts an array of ad sizes which may be eligible to be served.
156146

157-
#### AdMobInterstitials
147+
#### AdMobInterstitial
158148

159149
##### Methods
160150

161-
| Name | Description |
162-
|---------------------------|-----------------------------------------------------------------------------------------------------------------|
163-
|`setAdUnitID(adUnitID)` | sets the AdUnit ID for all future ad requests. |
164-
|`setTestDeviceID(deviceID)`| sets the test device ID |
165-
|`requestAd(callback)` | requests an interstitial and calls callback when `interstitialDidLoad` or`interstitialDidFailToLoad` event fires|
166-
|`showAd(callback)` | shows an interstitial if it is ready and calls callback when `interstitialDidOpen` event fires |
167-
|`isReady(callback)` | calls callback with boolean whether interstitial is ready to be shown |
151+
| Name | Description |
152+
|---------------------------|------------------------------------------------------------------------------------------------|
153+
|`setAdUnitID(adUnitID)` | sets the AdUnit ID for all future ad requests. |
154+
|`setTestDevices(devices)` | sets the devices which are served test ads |
155+
|`requestAd()` | requests an interstitial and returns a promise, which resolves on load and rejects on error |
156+
|`showAd()` | shows an interstitial and returns a promise, which resolves when ready and otherwise rejects |
157+
|`isReady(callback)` | calls callback with boolean whether interstitial is ready to be shown |
168158

169-
*For simulators/emulators you can use `'EMULATOR'` for the test device ID.*
170-
*Note: `tryShowNewInterstitial()` is deprecated as of v1.1.0 and can be replaced by calling `requestAd` with `showAd` as callback.*
159+
*For simulators/emulators you can use `AdMobInterstitial.simulatorId` for the test device ID.*
171160

172161
##### Events
162+
173163
Unfortunately, events are not consistent across iOS and Android. To have one unified API, new event names are introduced for pairs that are roughly equivalent.
174164

175165
| iOS | *this library* | Android |
@@ -190,12 +180,14 @@ Unfortunately, events are not consistent across iOS and Android. To have one uni
190180
Opens a rewarded AdMob ad.
191181

192182
##### Methods
193-
| Name | Description |
194-
|---------------------------|-----------------------------------------------------------------------------------------------------------------|
195-
|`setAdUnitID(adUnitID)` | sets the AdUnit ID for all future ad requests. |
196-
|`setTestDeviceID(deviceID)`| sets the test device ID |
197-
|`requestAd(callback)` | requests a rewarded ad|
198-
|`showAd(callback)` | shows a rewarded if it is ready |
183+
184+
| Name | Description |
185+
|---------------------------|------------------------------------------------------------------------------------------------|
186+
|`setAdUnitID(adUnitID)` | sets the AdUnit ID for all future ad requests |
187+
|`setTestDevices(devices)` | sets the devices which are served test ads |
188+
|`requestAd()` | requests an rewarded ad and returns a promise, which resolves on load and rejects on error |
189+
|`showAd()` | shows an rewarded ad and returns a promise, which resolves when ready and otherwise rejects |
190+
|`isReady(callback)` | calls callback with boolean whether interstitial is ready to be shown |
199191

200192
##### Events
201193

@@ -212,6 +204,6 @@ Opens a rewarded AdMob ad.
212204
---
213205

214206
### TODO
207+
215208
- [ ] Support [Ad Targeting](https://developers.google.com/admob/ios/targeting)
216209
- [ ] Also use interstitial event names for banner
217-
- [ ] PublisherBanner [DFPBanner/PublisherAdView should be able to accept multiple adSizes. Currently only caters for a single size]

0 commit comments

Comments
 (0)