1
+ import React from 'react' ;
2
+ import {
3
+ View ,
4
+ Text ,
5
+ StyleSheet ,
6
+ StyleProp ,
7
+ ViewStyle ,
8
+ TextStyle ,
9
+ Dimensions ,
10
+ TouchableOpacity ,
11
+ TouchableOpacityProps ,
12
+ TouchableNativeFeedbackProps ,
13
+ ImageProps ,
14
+ ImageSourcePropType
15
+ } from 'react-native' ;
16
+ import Icon , { IconsProps } from '../Icon' ;
17
+ import TransitionImage from '../TransitionImage' ;
18
+
19
+ export type TileProps = TouchableOpacityProps &
20
+ TouchableNativeFeedbackProps & {
21
+ /** 标题内容(可选)*/
22
+ title ?: string ;
23
+ /** 标题样式 */
24
+ titleStyle ?: StyleProp < TextStyle > ;
25
+ /** 图标(可选)*/
26
+ icon ?: IconsProps ;
27
+ /** 图标样式(可选) */
28
+ iconContainerStyle ?: StyleProp < ViewStyle > ;
29
+ /** 文本内容(可选) */
30
+ caption ?: React . ReactNode ;
31
+ /** 文本内容样式(可选) */
32
+ captionStyle ?: StyleProp < TextStyle > ;
33
+ /** 底部容器样式(可选) */
34
+ contentContainerStyle ?: StyleProp < ViewStyle > ;
35
+ /** 图片链接(可选) */
36
+ imageSrc ?: ImageSourcePropType | string | number ;
37
+ /** 图片容器样式(可选) */
38
+ imageContainerStyle ?: StyleProp < ViewStyle > ;
39
+ /** 文字行数(可选) */
40
+ titleNumberOfLines ?: number ;
41
+ /** Tile样式(可选) */
42
+ containerStyle ?: StyleProp < ViewStyle > ;
43
+ /** Tile宽度(可选) */
44
+ width ?: number ;
45
+ /** Tile高度(可选)*/
46
+ height ?: number ;
47
+ /** Tile透明度(可选)*/
48
+ activeOpacity ?: number ;
49
+ /** 继承image的api */
50
+ imageProps ?: Partial < ImageProps > ;
51
+ /** Custom ImageComponent for Tile. */
52
+ ImageComponent ?: typeof React . Component ;
53
+ }
54
+
55
+ const Tile = ( {
56
+ imageSrc,
57
+ icon,
58
+ title,
59
+ onPress,
60
+ caption,
61
+ activeOpacity,
62
+ captionStyle,
63
+ containerStyle,
64
+ titleStyle,
65
+ iconContainerStyle,
66
+ contentContainerStyle,
67
+ imageContainerStyle,
68
+ titleNumberOfLines,
69
+ imageProps = { } ,
70
+ width = Dimensions . get ( 'window' ) . width ,
71
+ height = width * 0.8 ,
72
+ ImageComponent = TransitionImage ,
73
+ ...attributes
74
+ } : TileProps ) => {
75
+ return (
76
+ < TouchableOpacity
77
+ { ...attributes }
78
+ onPress = { onPress }
79
+ activeOpacity = { activeOpacity }
80
+ style = { StyleSheet . flatten ( [
81
+ {
82
+ width : width ,
83
+ height : height ,
84
+ } ,
85
+ containerStyle && containerStyle ,
86
+ ] ) }
87
+ >
88
+ < ImageComponent
89
+ source = { imageSrc }
90
+ containerStyle = { StyleSheet . flatten ( [
91
+ styles . imageContainer ,
92
+ imageContainerStyle && imageContainerStyle ,
93
+ ] ) }
94
+ style = { {
95
+ // ...StyleSheet.absoluteFillObject,
96
+ alignItems : 'center' ,
97
+ justifyContent : 'center' ,
98
+ width,
99
+ height : 200
100
+ } }
101
+ { ...( imageProps as Partial < ImageProps > ) }
102
+ >
103
+ < View
104
+ style = { StyleSheet . flatten ( [
105
+ iconContainerStyle && iconContainerStyle ,
106
+ ] ) }
107
+ >
108
+ { icon && < Icon { ...icon } /> }
109
+ </ View >
110
+ </ ImageComponent >
111
+
112
+ < View
113
+ style = { [ StyleSheet . flatten ( [
114
+ styles . contentContainer ,
115
+ contentContainerStyle && contentContainerStyle ,
116
+ ] ) ,
117
+ { ...StyleSheet . absoluteFillObject }
118
+ ] }
119
+ >
120
+ < Text
121
+ testID = "tileTitle"
122
+ style = { StyleSheet . flatten ( [ styles . text , titleStyle && titleStyle ] ) }
123
+ numberOfLines = { titleNumberOfLines }
124
+ >
125
+ { title }
126
+ </ Text >
127
+ < Text
128
+ testID = "tileText"
129
+ style = { StyleSheet . flatten ( [ styles . text , captionStyle && captionStyle ] ) }
130
+ numberOfLines = { titleNumberOfLines }
131
+ >
132
+ { caption }
133
+ </ Text >
134
+ </ View >
135
+ </ TouchableOpacity >
136
+ ) ;
137
+ } ;
138
+
139
+ const styles = StyleSheet . create ( {
140
+ imageContainer : { } ,
141
+ text : {
142
+ backgroundColor : 'rgba(0,0,0,0)' ,
143
+ marginBottom : 5 ,
144
+ } ,
145
+ contentContainer : {
146
+ paddingTop : 15 ,
147
+ paddingBottom : 5 ,
148
+ paddingLeft : 15 ,
149
+ paddingRight : 15 ,
150
+ } ,
151
+ iconContainer : {
152
+ justifyContent : 'center' ,
153
+ alignItems : 'center' ,
154
+ alignSelf : 'center' ,
155
+ } ,
156
+ } ) ;
157
+
158
+ export default Tile
0 commit comments