forked from NZME/react-native-ad-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
/
NativeAdView.js
84 lines (80 loc) · 2.79 KB
/
NativeAdView.js
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
import React, { Component } from 'react';
import { Text, View, Image } from 'react-native';
import {
withNativeAd,
TriggerableView,
} from 'react-native-ad-manager';
export class NativeAdView extends Component {
render() {
const { nativeAd } = this.props;
if (!['native', 'template'].includes(nativeAd?.type)) {
return null;
}
let data = {};
if (nativeAd?.type == 'native') {
data.headline = nativeAd?.headline;
data.bodyText = nativeAd?.bodyText;
data.advertiserName = nativeAd?.advertiserName;
data.starRating = nativeAd?.starRating;
data.storeName = nativeAd?.storeName;
data.price = nativeAd?.price;
data.icon = nativeAd?.icon;
data.callToActionText = nativeAd?.callToActionText;
data.images = nativeAd?.images;
} else if (nativeAd?.type == 'template') {
data.headline = nativeAd?.title;
data.bodyText = nativeAd?.text;
data.advertiserName = nativeAd?.label;
data.starRating = nativeAd?.imptrk;
data.storeName = nativeAd?.headline;
data.price = null;
data.icon = nativeAd?.image;
data.callToActionText = null;
data.images = [];
}
return (
<View style={{ flexDirection: 'column', borderWidth: 1, position: 'relative' }}>
<TriggerableView style={{backgroundColor: 'rgba(52, 52, 52, 0.5)', position: 'absolute', zIndex:99, top:0, left:0, width: '100%', height: '100%'}} />
<View style={{ flexDirection: 'row', padding: 10 }}>
<View
style={{ flexDirection: 'column', flex: 1 }}
>
{data?.headline && (<Text style={{ fontSize: 18 }}>
{data.headline}
</Text>)}
{data?.bodyText && (<Text style={{ fontSize: 10 }}>
{data.bodyText}
</Text>)}
<View style={{ flexDirection: 'row' }}>
<Text>{data?.advertiserName}</Text>
<Text>{data?.starRating}</Text>
<Text>{data?.storeName}</Text>
<Text>{data?.price}</Text>
</View>
</View>
{data?.icon?.uri && (<Image style={{ width: 80, height: 80 }} source={{uri: data.icon.uri}} />)}
</View>
{data?.callToActionText && (<View style={{ alignItems: 'center' }}>
<View
ref={el => (this._triggerView = el)}>
<Text
style={{
fontSize: 15,
color: '#a70f0a',
paddingVertical: 10,
paddingHorizontal: 30,
elevation: 3,
borderTopWidth: 0,
margin: 10,
borderRadius: 6,
}}
>
{data.callToActionText}
</Text>
</View>
</View>)}
</View>
);
}
}
export default withNativeAd(NativeAdView);