1.0.5 • Published 5 years ago
react-native-gdt-ad v1.0.5
react-native-gdt
Getting started
$ npm install react-native-gdt-ad --save
Mostly automatic installation
$ react-native link react-native-gdt-ad
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import cn.cnlee.commons.CommonPackage;
to the imports at the top of the file - Add
new CommonPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-gdt' project(':react-native-gdt').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gdt/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:implementation project(':react-native-gdt')
Usage
- Splash 广告示例
import GDT from 'react-native-gdt-ad';
<GDT.Splash style={{flex: 1}}
onFailToReceived={(error) => {
console.log(error);
}}
onNextAction={() => {
//下一步路由动作
}}
showLogo={true}
appInfo={{appId: '1101152570', posId: '8863364436303842593'}}
fetchDelay={4000}
/>
- Banner 广告示例
<GDT.Banner style={{height: 64}}
onReceived={() => {
}}
onViewWillExposure={() => {
}}
onFailToReceived={(err) => console.log(err)}
showCloseBtn={false}
appInfo={{appId: '1101152570', posId: '9079537218417626401'}}
/>
- Banner2.0 广告示例
<GDT.UnifiedBanner style={{height: 66}}
onReceived={() => {
}}
onViewWillExposure={() => {
}}
onFailToReceived={(err) => console.log(err)}
interval={50}
appInfo={{appId: '1101152570', posId: '4080052898050840'}}
/>
- 插屏 广告示例
<TouchableOpacity
activeOpacity={0.9}
onPress={() => {
GDT.Module.showInterstitialAD('1101152570', '8575134060152130849', true);
}}>
<Text style={{color: 'black', fontSize: 12,}}>插屏广告</Text>
</TouchableOpacity>
- 插屏2.0 广告示例
<TouchableOpacity
activeOpacity={0.9}
onPress={() => {
GDT.Module.showUnifiedInterstitialAD('1101152570', '3040652898151811', true);
}}>
<Text style={{color: 'black', fontSize: 12,}}>插屏2.0广告</Text>
</TouchableOpacity>
- HYBRID广告示例
<TouchableOpacity
activeOpacity={0.9}
onPress={() => {
GDT.Module.openWeb('1101152570', 'http://m.baidu.com', {title: '测试标题', titleBarHeight: 45, titleSize: 20, titleColor: '#ff0000ff'});
}}>
<Text style={{color: 'black', fontSize: 12,}}>HYBRID广告</Text>
</TouchableOpacity>
License
MIT