UNPKG

972 BJavaScriptView Raw
1/* @flow */
2
3import React, { PropTypes } from 'react';
4import { requireNativeComponent, View } from 'react-native';
5
6type AdType = 'large' | 'rectangle' | 'standard';
7
8const CTKBannerView = requireNativeComponent('CTKBannerView', null, {
9 onAdPress: true,
10 onAdError: true,
11});
12
13const sizeForType = {
14 large: 90,
15 rectangle: 250,
16 standard: 50,
17};
18
19/**
20 * Gets size for a type (any value of `AdType` is allowed)
21 */
22const getSizeForType = (type: AdType) => sizeForType[type] || sizeForType.standard;
23
24type BannerViewProps = {
25 type: AdType,
26 placementId: string,
27 onPress: Function,
28 onError: Function,
29};
30
31const 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
46export default BannerView;