@@ -22,6 +22,7 @@ import { groupBy } from 'lodash';
22
22
import { wait } from '../utils' ;
23
23
import { colors } from '../Theme' ;
24
24
import H1 from '../Components/H1' ;
25
+ import WebViewModal from '../Components/Webview' ;
25
26
26
27
const { height } = Dimensions . get ( 'window' ) ;
27
28
@@ -52,65 +53,6 @@ type EntryPropsType = {
52
53
fromName : string ;
53
54
} ;
54
55
55
- function Entry ( props : EntryPropsType ) {
56
- const [ visible , setVisible ] = useState ( false ) ;
57
- const [ loadingWebview , setLoading ] = useState ( true ) ;
58
- return (
59
- < View >
60
- < ListItem
61
- onPress = { ( ) => setVisible ( true ) }
62
- Component = { TouchableOpacity }
63
- title = {
64
- < Text style = { { fontWeight : '800' } } >
65
- { props . content . slice ( 0 , 50 ) }
66
- </ Text >
67
- }
68
- subtitle = {
69
- < View
70
- style = { {
71
- paddingTop : 4 ,
72
- flexDirection : 'row' ,
73
- justifyContent : 'space-between' ,
74
- } } >
75
- < Text style = { { fontSize : 12 } } > 时间: { props . sendTime } </ Text >
76
- < Text style = { { fontSize : 12 } } > 来源: { props . fromName } </ Text >
77
- </ View >
78
- }
79
- rightIcon = { { name : 'unfold-more' } }
80
- />
81
- < Modal
82
- animationType = "fade"
83
- presentationStyle = "pageSheet"
84
- visible = { visible }
85
- onRequestClose = { ( ) => {
86
- Alert . alert ( 'Modal has been closed.' ) ;
87
- } } >
88
- < View style = { { padding : 16 , justifyContent : 'space-between' } } >
89
- < View style = { { height : height - 150 } } >
90
- { loadingWebview ? (
91
- < ActivityIndicator size = "large" color = "red" />
92
- ) : null }
93
- < WebView
94
- onLoad = { ( ) => setLoading ( true ) }
95
- onLoadEnd = { ( ) => setLoading ( false ) }
96
- source = { { uri : props . url } }
97
- />
98
- </ View >
99
- < View >
100
- < Button
101
- buttonStyle = { styles . button }
102
- title = "关闭预览"
103
- onPress = { ( ) => {
104
- setVisible ( false ) ;
105
- } }
106
- />
107
- </ View >
108
- </ View >
109
- </ Modal >
110
- </ View >
111
- ) ;
112
- }
113
-
114
56
const typeMap = {
115
57
1 : { label : '飞机' } ,
116
58
2 : { label : '火车' } ,
@@ -155,53 +97,58 @@ type EntryType = {
155
97
updated_at : string ;
156
98
} ;
157
99
100
+ function Mobility ( { item } : { item : EntryType } ) {
101
+ const [ visible , setVisible ] = useState ( false ) ;
102
+
103
+ return (
104
+ < View >
105
+ < ListItem
106
+ onPress = { ( ) => setVisible ( true ) }
107
+ title = {
108
+ < Text
109
+ style = { {
110
+ fontWeight : '800' ,
111
+ } } > { `${ item . t_pos_start } - ${ item . t_pos_end } ` } </ Text >
112
+ }
113
+ subtitle = {
114
+ < View >
115
+ < View
116
+ style = { {
117
+ flexDirection : 'row' ,
118
+ justifyContent : 'space-between' ,
119
+ } } >
120
+ < Text style = { { fontSize : 12 } } > { item . t_no } </ Text >
121
+ < Text style = { { fontSize : 12 } } > { item . who } </ Text >
122
+ </ View >
123
+ { Boolean ( item . t_memo ) && (
124
+ < Text style = { { color : '#717171' } } > ({ item . t_memo } )</ Text >
125
+ ) }
126
+ </ View >
127
+ }
128
+ leftAvatar = {
129
+ < View style = { { width : 50 } } >
130
+ < Text style = { { fontSize : 13 , fontWeight : 'bold' } } >
131
+ { typeMap [ item . t_type ] . label }
132
+ </ Text >
133
+ </ View >
134
+ }
135
+ rightIcon = { { name : 'unfold-more' } }
136
+ />
137
+ < WebViewModal title = { `${ item . t_pos_start } - ${ item . t_pos_end } ` } uri = { item . source } visible = { visible } onClose = { ( ) => setVisible ( false ) } />
138
+ </ View >
139
+ ) ;
140
+ }
141
+
158
142
function MobilityScreen ( ) {
159
143
const { data, loading, refresh } = useContext ( MobilityDataContext ) ;
160
- const [ selection , setSelection ] = useState ( null ) ;
161
- const [ loadingWebview , setLoading ] = useState ( true ) ;
162
144
const [ refreshing , setRefreshing ] = useState ( false ) ;
163
145
164
146
function keyExtractor ( item : EntryType ) {
165
147
return String ( item . id ) ;
166
148
}
167
149
168
150
function renderItem ( { item } : { item : EntryType } ) {
169
- return (
170
- < View >
171
- < ListItem
172
- onPress = { ( ) => setSelection ( item ) }
173
- title = {
174
- < Text
175
- style = { {
176
- fontWeight : '800' ,
177
- } } > { `${ item . t_pos_start } - ${ item . t_pos_end } ` } </ Text >
178
- }
179
- subtitle = {
180
- < View >
181
- < View
182
- style = { {
183
- flexDirection : 'row' ,
184
- justifyContent : 'space-between' ,
185
- } } >
186
- < Text style = { { fontSize : 12 } } > { item . t_no } </ Text >
187
- < Text style = { { fontSize : 12 } } > { item . who } </ Text >
188
- </ View >
189
- { Boolean ( item . t_memo ) && (
190
- < Text style = { { color : '#717171' } } > ({ item . t_memo } )</ Text >
191
- ) }
192
- </ View >
193
- }
194
- leftAvatar = {
195
- < View style = { { width : 50 } } >
196
- < Text style = { { fontSize : 13 , fontWeight : 'bold' } } >
197
- { typeMap [ item . t_type ] . label }
198
- </ Text >
199
- </ View >
200
- }
201
- rightIcon = { { name : 'unfold-more' } }
202
- />
203
- </ View >
204
- ) ;
151
+ return < Mobility item = { item } /> ;
205
152
}
206
153
207
154
const onRefresh = useCallback ( ( ) => {
@@ -239,44 +186,6 @@ function MobilityScreen() {
239
186
}
240
187
/>
241
188
</ View >
242
-
243
- { selection && (
244
- < Modal
245
- animationType = "fade"
246
- presentationStyle = "pageSheet"
247
- visible = { selection !== null }
248
- onRequestClose = { ( ) => {
249
- Alert . alert ( 'Modal has been closed.' ) ;
250
- } } >
251
- < View style = { { padding : 16 , justifyContent : 'space-between' } } >
252
- < View style = { { height : height - 150 } } >
253
- < Text
254
- style = { { fontSize : 20 , fontWeight : 'bold' , paddingBottom : 20 } } >
255
- { `${ selection . t_pos_start } - ${ selection . t_pos_end } ` }
256
- </ Text >
257
- { loadingWebview ? (
258
- < ActivityIndicator size = "large" color = "red" />
259
- ) : null }
260
- < WebView
261
- onLoad = { ( ) => setLoading ( true ) }
262
- onLoadEnd = { ( ) => setLoading ( false ) }
263
- source = { { uri : selection . source } }
264
- />
265
- </ View >
266
-
267
- < View >
268
- < Button
269
- buttonStyle = { styles . button }
270
- title = "关闭预览"
271
- onPress = { ( ) => {
272
- setSelection ( null ) ;
273
- setLoading ( true ) ;
274
- } }
275
- />
276
- </ View >
277
- </ View >
278
- </ Modal >
279
- ) }
280
189
</ StatusBarSafeLayout >
281
190
) ;
282
191
}
0 commit comments