Skip to content

Commit 797939f

Browse files
committed
Merge branch 'master' into chore/circleci-config
2 parents 192f4e9 + fef9462 commit 797939f

3 files changed

Lines changed: 113 additions & 115 deletions

File tree

AdChoicesManager.js

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,41 @@
11
// @flow
22
import React from 'react';
33
import { requireNativeComponent, StyleSheet, Platform } from 'react-native';
4+
import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
5+
6+
import { AdChoicesViewContext } from './withNativeAd';
7+
import type { AdChoicesViewContextValueType } from './withNativeAd';
48

59
const NativeAdChoicesView = requireNativeComponent('AdChoicesView', null);
610

7-
type AdChoicePosition = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
11+
type AdChoiceLocation = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight';
812

913
type Props = {
10-
placementId: string | null,
11-
position: AdChoicePosition,
14+
location: AdChoiceLocation,
1215
expandable: boolean,
16+
style?: ViewStyleProp,
1317
};
1418

1519
export default class AdChoicesView extends React.Component<Props> {
1620
static defaultProps: Props = {
17-
position: 'topLeft',
18-
placementId: null,
21+
location: 'topLeft',
1922
expandable: false,
2023
};
2124

2225
render() {
23-
if (!this.props.placementId) {
24-
return null;
25-
}
26-
2726
return (
28-
<NativeAdChoicesView
29-
style={[styles.adChoice, this.getPositionStyle(this.props.position)]}
30-
placementId={this.props.placementId}
31-
location={this.props.position}
32-
expandable={this.props.expandable}
33-
/>
27+
<AdChoicesViewContext.Consumer>
28+
{(placementId: AdChoicesViewContextValueType) => (
29+
<NativeAdChoicesView
30+
style={[styles.adChoice, this.props.style]}
31+
placementId={placementId}
32+
location={this.props.location}
33+
expandable={this.props.expandable}
34+
/>
35+
)}
36+
</AdChoicesViewContext.Consumer>
3437
);
3538
}
36-
37-
getPositionStyle = (position: AdChoicePosition) => {
38-
switch (position) {
39-
case 'topLeft':
40-
return styles.topLeft;
41-
case 'topRight':
42-
return styles.topRight;
43-
case 'bottomLeft':
44-
return styles.bottomLeft;
45-
case 'bottomRight':
46-
return styles.bottomRight;
47-
default:
48-
throw new Error(`Unsupported position ${position}`);
49-
}
50-
};
5139
}
5240

5341
let styles = StyleSheet.create({
@@ -63,22 +51,5 @@ let styles = StyleSheet.create({
6351
height: 22,
6452
},
6553
}),
66-
position: 'absolute',
67-
},
68-
topLeft: {
69-
left: 0,
70-
top: 0,
71-
},
72-
topRight: {
73-
top: 0,
74-
right: 0,
75-
},
76-
bottomLeft: {
77-
left: 0,
78-
bottom: 0,
79-
},
80-
bottomRight: {
81-
bottom: 0,
82-
right: 0,
8354
},
8455
});

README.md

Lines changed: 78 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
react-native-fbads [![npm version][version-badge]][package]
2-
============
1+
# react-native-fbads [![npm version][version-badge]][package]
32

43
[![chat][chat-badge]][chat]
54

@@ -15,47 +14,51 @@ react-native-fbads [![npm version][version-badge]][package]
1514
- [iOS](#21-ios)
1615
- [Android](#22-android)
1716
- [Usage](#usage)
18-
- [Interstitial Ads](#interstitial-ads)
19-
- [1. Showing ad](#1-showing-ad)
20-
- [Native Ads](#native-ads)
21-
- [1. Creating AdsManager](#1-creating-adsmanager)
22-
- [2. Making ad component](#2-making-ad-component)
23-
- [3. Rendering an ad](#3-rendering-an-ad)
24-
- [Banner View](#bannerview)
25-
- [1. Showing ad](#1-showing-ad-1)
17+
- [Interstitial Ads](#interstitial-ads)
18+
- [1. Showing ad](#1-showing-ad)
19+
- [Native Ads](#native-ads)
20+
- [1. Creating AdsManager](#1-creating-adsmanager)
21+
- [2. Making ad component](#2-making-ad-component)
22+
- [3. Rendering an ad](#3-rendering-an-ad)
23+
- [Banner View](#bannerview)
24+
- [1. Showing ad](#1-showing-ad-1)
2625
- [API](#api)
27-
- [NativeAdsManager](#nativeadsmanager)
28-
- [disableAutoRefresh](#disableautorefresh)
29-
- [setMediaCachePolicy](#setmediacachepolicy)
30-
- [InterstitialAdManager](#interstitialadmanager)
31-
- [showAd](#showad)
32-
- [RewardedVideoAdManager](#rewardedvideoadmanager)
33-
- [loadAd](#loadAd)
34-
- [showAd](#showAd)
35-
- [AdSettings](#adsettings)
36-
- [currentDeviceHash](#currentdevicehash)
37-
- [addTestDevice](#addtestdevice)
38-
- [clearTestDevices](#cleartestdevices)
39-
- [setLogLevel](#setloglevel)
40-
- [setIsChildDirected](#setischilddirected)
41-
- [setMediationService](#setmediationservice)
42-
- [setUrlPrefix](#seturlprefix)
26+
- [NativeAdsManager](#nativeadsmanager)
27+
- [disableAutoRefresh](#disableautorefresh)
28+
- [setMediaCachePolicy](#setmediacachepolicy)
29+
- [InterstitialAdManager](#interstitialadmanager)
30+
- [showAd](#showad)
31+
- [RewardedVideoAdManager](#rewardedvideoadmanager)
32+
- [loadAd](#loadAd)
33+
- [showAd](#showAd)
34+
- [AdSettings](#adsettings)
35+
- [currentDeviceHash](#currentdevicehash)
36+
- [addTestDevice](#addtestdevice)
37+
- [clearTestDevices](#cleartestdevices)
38+
- [setLogLevel](#setloglevel)
39+
- [setIsChildDirected](#setischilddirected)
40+
- [setMediationService](#setmediationservice)
41+
- [setUrlPrefix](#seturlprefix)
4342
- [Running example](#running-example)
44-
- [Install dependencies](#1-install-dependencies)
45-
- [Start packager](#2-start-packager)
46-
- [Run it on iOS / Android](#3-run-it-on-ios--android)
43+
- [Install dependencies](#1-install-dependencies)
44+
- [Start packager](#2-start-packager)
45+
- [Run it on iOS / Android](#3-run-it-on-ios--android)
4746
- [Credits](#credits)
4847

4948
## Installation
5049

5150
### 1. Install Javascript packages
51+
5252
##### RN >= 0.40
53+
5354
Install JavaScript packages:
5455

5556
```bash
5657
$ react-native install react-native-fbads
5758
```
59+
5860
##### RN < 0.40
61+
5962
Install JavaScript packages:
6063

6164
```bash
@@ -73,7 +76,6 @@ react-native link react-native-fbads
7376
7477
//IOS NOTICE
7578
Use pod to install fbAudience framework
76-
7779
```
7880

7981
### 2. Configure native projects
@@ -111,7 +113,7 @@ import { InterstitialAdManager } from 'react-native-fbads';
111113

112114
InterstitialAdManager.showAd(placementId)
113115
.then(didClick => {})
114-
.catch(error => {})
116+
.catch(error => {});
115117
```
116118

117119
Method returns a promise that will be rejected when an error occurs during a call (e.g. no fill from ad server or network error) and resolve when user either dimisses or interacts with the displayed ad.
@@ -134,12 +136,12 @@ const adsManager = new NativeAdsManager(placementId, numberOfAdsToRequest);
134136
```
135137

136138
The constructor accepts two parameters:
139+
137140
- `placementId` - which is an unique identifier describing your ad units,
138141
- `numberOfAdsToRequest` - which is a number of ads to request by ads manager at a time
139142

140143
#### 2. Making ad component
141144

142-
143145
After creating `adsManager` instance, next step is to wrap an arbitrary component that you want to
144146
use for rendering your custom advertises with a `withNativeAd` wrapper.
145147

@@ -158,22 +160,26 @@ The `nativeAd` object can contain the following properties:
158160
- `callToActionText` - Call to action phrase, e.g. - "Install Now"
159161
- `socialContext` - social context for the Ad, for example "Over half a million users"
160162

161-
162163
** Note: ** Don't use more than one MediaView/AdIconView component within one native ad.
163164

164165
** Note: ** To make any text `Triggerable` wrap it in <TriggerableView></TriggerableView> use only <Text /> component
165166

166-
167167
```js
168-
import { AdIconView,MediaView,TriggerableView } from 'react-native-ads-facebook';
168+
import {
169+
AdIconView,
170+
MediaView,
171+
AdChoicesView,
172+
TriggerableView
173+
} from 'react-native-fbads';
169174
class AdComponent extends React.Component {
170175
render() {
171176
return (
172177
<View>
178+
<AdChoicesView style={{ position: 'absolute', left: 0, top: 0 }} />
173179
<AdIconView />
174180
<MediaView />
175181
<TriggerableView>
176-
<Text>{this.props.nativeAd.description}</Text>
182+
<Text>{this.props.nativeAd.description}</Text>
177183
</TriggerableView>
178184
</View>
179185
);
@@ -183,25 +189,44 @@ class AdComponent extends React.Component {
183189
export default withNativeAd(AdComponent);
184190
```
185191

192+
#### 4. Displaying Facebook Ad Choices Icon
193+
194+
Facebook's guidelines require every native ad to include the Ad Choices component, which contains a small clickable icon.
195+
You can use the included `AdChoicesView` component and style it to your liking.
196+
197+
#### Example usage
198+
199+
```js
200+
import { AdChoicesView } from 'react-native-fbads'
201+
202+
<AdChoicesView style={{position:'absolute', left:0, top:0}}/>
203+
```
204+
205+
#### Props
206+
207+
| prop | default | required | description |
208+
| ---------- | --------- | -------- | ------------------------------------------------------ |
209+
| style | undefined | false | Standard Style prop |
210+
| expandable | false | false | (iOS only) makes the native AdChoices expandable |
211+
| location | topLeft | false | (iOS only) controls the location of the AdChoices icon |
212+
186213
#### 3. Rendering an ad
187214

188215
Finally, you can render your wrapped component from previous step and pass it `adsManager`
189216
of your choice.
190217

191-
##### Adchoice position props
218+
##### Native Ad Props
192219

193-
| prop | default | required | params | description |
194-
|------------------|----------|----------|-----------------------------------------------------------------------------|----------------------------------|
195-
| adsManager | null | true | `const adsManager = new NativeAdsManager(placementId, numberOfAdsToRequest)` | Set Placement id for native ad |
196-
| adChoicePosition | topRight | false | `topLeft , topRight , bottomLeft , bottomRight` | Set Ad choice position |
197-
| expandable | true | false | BOOLEAN | IOS only set Adchoice expandable |
220+
| prop | default | required | params | description |
221+
| ---------- | ------- | -------- | ---------------------------------------------------------------------------- | --------------------------- |
222+
| adsManager | null | true | `const adsManager = new NativeAdsManager(placementId, numberOfAdsToRequest)` | The ad manager to work with |
198223

199224
```js
200225
class MainApp extends React.Component {
201226
render() {
202227
return (
203228
<View>
204-
<AdComponent adsManager={adsManager} adChoicePosition="topLeft" expandable={false} />
229+
<AdComponent adsManager={adsManager} />
205230
</View>
206231
);
207232
}
@@ -210,9 +235,10 @@ class MainApp extends React.Component {
210235

211236
### BannerView
212237

213-
BannerView is a component that allows you to display native banners (know as *AdView*).
238+
BannerView is a component that allows you to display native banners (know as _AdView_).
214239

215240
Banners are available in 3 sizes:
241+
216242
- `standard` (BANNER_HEIGHT_50)
217243
- `large` (BANNER_HEIGHT_90)
218244
- `rectangle` (RECTANGLE_HEIGHT_250)
@@ -235,7 +261,7 @@ function ViewWithBanner(props) {
235261
placementId="YOUR_BANNER_PLACEMENT_ID"
236262
type="standard"
237263
onPress={() => console.log('click')}
238-
onError={(err) => console.log('error', err)}
264+
onError={err => console.log('error', err)}
239265
/>
240266
</View>
241267
);
@@ -288,7 +314,8 @@ InterstitialAdManager.showAd('placementId')
288314
Promise will be rejected when there's an error loading ads from Facebook Audience network. It will resolve with a
289315
`boolean` indicating whether user didClick an ad or not.
290316

291-
On Android you have to add following activity to *AndroidManifest.xml*
317+
On Android you have to add following activity to _AndroidManifest.xml_
318+
292319
```xml
293320
<activity
294321
android:name="com.facebook.ads.InterstitialAdActivity"
@@ -300,7 +327,7 @@ On Android you have to add following activity to *AndroidManifest.xml*
300327
### RewardedVideoAdManager
301328

302329
```js
303-
import { RewardedVideoAdManager } from "react-native-fbads";
330+
import { RewardedVideoAdManager } from 'react-native-fbads';
304331
```
305332

306333
RewardedVideoAdManager is a manager that allows you to load a rewarded video, then show the video once the video is loaded, in that order.
@@ -365,7 +392,9 @@ AdSettings.clearTestDevices();
365392
Sets current SDK log level.
366393

367394
```js
368-
AdSettings.setLogLevel('none' | 'debug' | 'verbose' | 'warning' | 'error' | 'notification');
395+
AdSettings.setLogLevel(
396+
'none' | 'debug' | 'verbose' | 'warning' | 'error' | 'notification'
397+
);
369398
```
370399

371400
**Note:** This method is a noop on Android.
@@ -427,6 +456,7 @@ $ cd ./example && npm run android
427456
Some of the API explanations were borrowed from Facebook SDK documentation.
428457

429458
<!-- badges -->
459+
430460
[version-badge]: https://img.shields.io/npm/v/react-native-fbads.svg?style=flat-square
431461
[package]: https://www.npmjs.com/package/react-native-fbads
432462
[chat-badge]: https://img.shields.io/discord/426714625279524876.svg?style=flat-square&colorB=758ED3

0 commit comments

Comments
 (0)