/
App.tsx
126 lines (120 loc) · 2.69 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import * as React from 'react';
import {
StyleSheet,
View,
TouchableOpacity,
Platform,
Text,
GestureResponderEvent,
} from 'react-native';
import TencentYlhAd, { Splash } from 'react-native-tencent-ylh-ad';
import config from '../config.json';
import { showBanner, showNativeExpress } from './ExampleBuilder';
const platformConfig = config[Platform.OS as 'android' | 'ios'];
function Button({
title,
onPress,
}: {
title: string;
onPress: (event: GestureResponderEvent) => void;
}) {
return (
<TouchableOpacity
style={{
height: 50,
width: '100%',
borderRadius: 8,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#888',
marginTop: 10,
}}
onPress={onPress}
>
<Text
style={{
color: 'white',
}}
>
{title}
</Text>
</TouchableOpacity>
);
}
export default function App() {
React.useEffect(() => {
TencentYlhAd.registerAppId(config.appId)
.then(() => {
console.log('init success');
})
.catch(() => {
console.log('init fail');
});
});
return (
<View style={styles.container}>
<Button
title="开屏广告"
onPress={() => {
Splash.show({
posId: platformConfig.splashPosId,
onPresent: () => {
console.log('Splash.onPresent()');
},
onFailToReceived: (err: any) => {
console.log('Splash.onFailToReceived()', err);
},
onNextAction: () => {
console.log('Splash.onNextAction()');
},
});
}}
/>
<Button
title="banner广告"
onPress={() => {
showBanner({
posId: platformConfig.bannerPosId,
});
}}
/>
<Button
title="信息流广告"
onPress={() => {
showNativeExpress({
posId: platformConfig.flowAdPosId,
});
}}
/>
<Button
title="插屏半屏"
onPress={() => {
TencentYlhAd.showInterstitialAD(
platformConfig.interstitialPosId,
false
);
}}
/>
<Button
title="插屏全屏"
onPress={() => {
TencentYlhAd.showFullScreenAD(platformConfig.fullScreenAdPosId);
}}
/>
<Button
title="H5激励视频广告"
onPress={() => {
TencentYlhAd.openWeb('https://www.baidu.com', {});
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: 15,
},
});