Skip to content

Commit 69a7a54

Browse files
committed
fix #1 for mobility tab
1 parent 2d7fa8f commit 69a7a54

File tree

2 files changed

+48
-136
lines changed

2 files changed

+48
-136
lines changed

src/Layouts/Mobility.tsx

+44-135
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { groupBy } from 'lodash';
2222
import { wait } from '../utils';
2323
import { colors } from '../Theme';
2424
import H1 from '../Components/H1';
25+
import WebViewModal from '../Components/Webview';
2526

2627
const { height } = Dimensions.get('window');
2728

@@ -52,65 +53,6 @@ type EntryPropsType = {
5253
fromName: string;
5354
};
5455

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-
11456
const typeMap = {
11557
1: { label: '飞机' },
11658
2: { label: '火车' },
@@ -155,53 +97,58 @@ type EntryType = {
15597
updated_at: string;
15698
};
15799

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+
158142
function MobilityScreen() {
159143
const { data, loading, refresh } = useContext(MobilityDataContext);
160-
const [selection, setSelection] = useState(null);
161-
const [loadingWebview, setLoading] = useState(true);
162144
const [refreshing, setRefreshing] = useState(false);
163145

164146
function keyExtractor(item: EntryType) {
165147
return String(item.id);
166148
}
167149

168150
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} />;
205152
}
206153

207154
const onRefresh = useCallback(() => {
@@ -239,44 +186,6 @@ function MobilityScreen() {
239186
}
240187
/>
241188
</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-
)}
280189
</StatusBarSafeLayout>
281190
);
282191
}

src/Layouts/Timeline.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ function Entry(props: EntryPropsType) {
7070
animationType="fade"
7171
presentationStyle="pageSheet"
7272
visible={visible}
73+
onDismiss={() => {
74+
setVisible(false);
75+
}}
7376
onRequestClose={() => {
74-
Alert.alert('Modal has been closed.');
77+
setVisible(false);
7578
}}>
7679
<View style={{ padding: 16, justifyContent: 'space-between' }}>
7780
<View style={{ height: height - 150 }}>

0 commit comments

Comments
 (0)