UNPKG

3.64 kBJavaScriptView Raw
1var __rest = (this && this.__rest) || function (s, e) {
2 var t = {};
3 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4 t[p] = s[p];
5 if (s != null && typeof Object.getOwnPropertySymbols === "function")
6 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8 t[p[i]] = s[p[i]];
9 }
10 return t;
11};
12import React from 'react';
13import { TouchableOpacity, View, StyleSheet, Dimensions, } from 'react-native';
14import { BackgroundImage, withTheme } from '../config';
15import { renderNode } from '../helpers';
16import Text from '../text/Text';
17import Icon from '../icons/Icon';
18const renderText = (content, defaultProps, style) => renderNode(Text, content, Object.assign(Object.assign({}, defaultProps), { style: StyleSheet.flatten([style, defaultProps && defaultProps.style]) }));
19const FeaturedTile = (props) => {
20 const { title, icon, caption, imageSrc, containerStyle, imageContainerStyle, overlayContainerStyle, iconContainerStyle, titleStyle, captionStyle, ImageComponent = BackgroundImage, imageProps = {} } = props, attributes = __rest(props, ["title", "icon", "caption", "imageSrc", "containerStyle", "imageContainerStyle", "overlayContainerStyle", "iconContainerStyle", "titleStyle", "captionStyle", "ImageComponent", "imageProps"]);
21 const { width = Dimensions.get('window').width, height = width * 0.8, } = props;
22 const styles = StyleSheet.create({
23 container: {
24 width,
25 height,
26 },
27 imageContainer: {
28 alignItems: 'center',
29 justifyContent: 'center',
30 width,
31 height,
32 },
33 overlayContainer: {
34 flex: 1,
35 alignItems: 'center',
36 alignSelf: 'stretch',
37 justifyContent: 'center',
38 paddingLeft: 25,
39 paddingRight: 25,
40 paddingTop: 45,
41 paddingBottom: 40,
42 position: 'absolute',
43 top: 0,
44 left: 0,
45 right: 0,
46 bottom: 0,
47 },
48 text: {
49 color: '#ffffff',
50 backgroundColor: 'rgba(0,0,0,0)',
51 marginBottom: 15,
52 textAlign: 'center',
53 },
54 iconContainer: {
55 justifyContent: 'center',
56 alignItems: 'center',
57 alignSelf: 'center',
58 },
59 });
60 return (<TouchableOpacity {...attributes} style={StyleSheet.flatten([
61 styles.container,
62 containerStyle && containerStyle,
63 ])}>
64 <ImageComponent resizeMode="cover" {...imageProps} source={imageSrc} style={StyleSheet.flatten([
65 styles.imageContainer,
66 imageContainerStyle && imageContainerStyle,
67 ])}>
68 <View style={StyleSheet.flatten([
69 styles.overlayContainer,
70 overlayContainerStyle && overlayContainerStyle,
71 ])}>
72 <View style={StyleSheet.flatten([
73 styles.iconContainer,
74 iconContainerStyle && iconContainerStyle,
75 ])}>
76 {icon && <Icon {...icon}/>}
77 </View>
78 <Text testID="featuredTileTitle" h4={!titleStyle || !('fontSize' in titleStyle)} style={StyleSheet.flatten([styles.text, titleStyle && titleStyle])}>
79 {title}
80 </Text>
81 {renderText(caption, { style: captionStyle }, styles.text)}
82 </View>
83 </ImageComponent>
84 </TouchableOpacity>);
85};
86export { FeaturedTile };
87export default withTheme(FeaturedTile, 'FeaturedTile');
88
\No newline at end of file