$ npm install react-native-teads --save
$ react-native link react-native-teads
NOTE:
Android:
You need to add maven { url "http://dl.bintray.com/teads/TeadsSDK-android" }
to your android/build.gradle as follows:
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-teads
and addRNTeads.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNTeads.a
to your project'sBuild Phases
➜Link Binary With Libraries
- link the
TeadsSDK.framework
to your project by drag and drop and make sureTeadsSDK.framework
appears in application's target > General > Linked Framework and Libraries - Add
TeadsSDK.framework
to application target > General > Embedded Binaries - Run your project (
Cmd+R
)
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.TeadsPackage;
to the imports at the top of the file - Add
new TeadsPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-teads' project(':react-native-teads').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-teads/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-teads')
- You need to add
maven { url "http://dl.bintray.com/teads/TeadsSDK-android" }
to your android/build.gradle as follows:allprojects { repositories { // ... maven { url 'http://dl.bintray.com/teads/TeadsSDK-android' } } // ... }
Ad view usage
import React, { Component } from "react";
import { Dimensions } from "react-native";
import TeadsNativeAdView from "react-native-teads";
const { width } = Dimensions.get("window");
class AdView extends Component<Props, State> {
constructor(props) {
super(props);
this.state = {
height: 0,
};
}
onDidReceiveAd = (info) => {
this.setState({
height: width / info.nativeEvent.adRatio,
});
};
render() {
const { style } = this.props;
return (
<TeadsNativeAdView
style={[
{
width,
height: this.state.height,
},
style,
]}
pid={84242}
onDidReceiveAd={this.onDidReceiveAd}
/>
);
}
}