1 |
|
2 |
|
3 | import React, { PropTypes } from 'react';
|
4 | import { requireNativeComponent, View } from 'react-native';
|
5 |
|
6 | type AdType = 'large' | 'rectangle' | 'standard';
|
7 |
|
8 | const CTKBannerView = requireNativeComponent('CTKBannerView', null, {
|
9 | onAdPress: true,
|
10 | onAdError: true,
|
11 | });
|
12 |
|
13 | const sizeForType = {
|
14 | large: 90,
|
15 | rectangle: 250,
|
16 | standard: 50,
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | const getSizeForType = (type: AdType) => sizeForType[type] || sizeForType.standard;
|
23 |
|
24 | type BannerViewProps = {
|
25 | type: AdType,
|
26 | placementId: string,
|
27 | onPress: Function,
|
28 | onError: Function,
|
29 | };
|
30 |
|
31 | const BannerView = (props: BannerViewProps) => {
|
32 | const { type, onPress, onError, style, ...restProps } = props;
|
33 | const size = getSizeForType(type);
|
34 |
|
35 | return (
|
36 | <CTKBannerView
|
37 | size={size}
|
38 | onAdPress={onPress}
|
39 | onAdError={onError}
|
40 | style={[style, { height: size }]}
|
41 | {...restProps}
|
42 | />
|
43 | );
|
44 | };
|
45 |
|
46 | export default BannerView;
|