|
1 | 1 | import { useFocusEffect } from '@react-navigation/native' |
2 | | -import * as Clipboard from 'expo-clipboard' |
3 | 2 | import React, { useCallback, useEffect } from 'react' |
4 | 3 | import { |
5 | 4 | ActivityIndicator, |
6 | 5 | BackHandler, |
7 | 6 | Image, |
8 | 7 | Linking, |
9 | | - Modal, |
10 | 8 | Platform, |
11 | | - ScrollView, |
12 | 9 | Share, |
13 | | - StyleSheet, |
14 | 10 | Text, |
15 | 11 | ToastAndroid, |
16 | | - TouchableOpacity, |
17 | 12 | View, |
18 | 13 | } from 'react-native' |
19 | 14 | import { WebView as RNWebView } from 'react-native-webview' |
20 | 15 |
|
21 | | -import { useColorScheme } from '@/hooks/useColorScheme' |
22 | 16 | import { useStore } from '@/store' |
23 | 17 | import { getPageIcon } from '@/utils' |
24 | 18 |
|
25 | | -// import { FloatingButton } from '../FloatingButton' |
26 | 19 | import { ThemedButton } from '../ThemedButton' |
27 | | -import { ThemedText } from '../ThemedText' |
28 | 20 | import { ThemedView } from '../ThemedView' |
| 21 | +import InfoModal from './InfoModal' |
29 | 22 | import { beforeLoadedInject } from './inject' |
30 | 23 |
|
31 | | -function InfoModal(props: { |
32 | | - visible: boolean |
33 | | - title: string |
34 | | - url: string |
35 | | - closeModal: () => void |
36 | | -}) { |
37 | | - const colorScheme = useColorScheme() |
38 | | - return ( |
39 | | - <Modal |
40 | | - animationType="fade" |
41 | | - transparent={true} |
42 | | - visible={props.visible} |
43 | | - statusBarTranslucent={true} |
44 | | - onRequestClose={() => { |
45 | | - props.closeModal() |
46 | | - }} |
47 | | - > |
48 | | - <View style={styles.centeredView}> |
49 | | - <ThemedView |
50 | | - style={[styles.modalView, { shadowColor: colorScheme === 'dark' ? 'white' : 'black' }]} |
51 | | - > |
52 | | - <ThemedText style={{ fontWeight: 'bold', fontSize: 18 }} selectable> |
53 | | - {props.title || '当前页面'} |
54 | | - </ThemedText> |
55 | | - <ScrollView style={{ maxHeight: 120 }}> |
56 | | - <ThemedText selectable style={{ opacity: 0.7 }}> |
57 | | - {props.url} |
58 | | - </ThemedText> |
59 | | - </ScrollView> |
60 | | - |
61 | | - <View |
62 | | - style={{ |
63 | | - flexDirection: 'row', |
64 | | - gap: 10, |
65 | | - marginTop: 20, |
66 | | - justifyContent: 'flex-end', |
67 | | - flexWrap: 'wrap', |
68 | | - }} |
69 | | - > |
70 | | - <ThemedButton |
71 | | - title="浏览器打开" |
72 | | - onPress={() => { |
73 | | - Linking.openURL(props.url) |
74 | | - props.closeModal() |
75 | | - }} |
76 | | - /> |
77 | | - <ThemedButton |
78 | | - title="分享" |
79 | | - type="primary" |
80 | | - onPress={() => { |
81 | | - Share.share({ |
82 | | - title: props.title, |
83 | | - message: props.title + '\n' + props.url, |
84 | | - url: props.url, |
85 | | - }) |
86 | | - props.closeModal() |
87 | | - }} |
88 | | - /> |
89 | | - <ThemedButton |
90 | | - title="复制链接" |
91 | | - type="secondary" |
92 | | - onPress={() => { |
93 | | - Clipboard.setStringAsync(props.url).then(() => { |
94 | | - ToastAndroid.show('已复制', ToastAndroid.SHORT) |
95 | | - }) |
96 | | - props.closeModal() |
97 | | - }} |
98 | | - /> |
99 | | - </View> |
100 | | - <TouchableOpacity |
101 | | - onPress={props.closeModal} |
102 | | - style={{ position: 'absolute', top: 10, right: 10, padding: 5 }} |
103 | | - hitSlop={10} |
104 | | - > |
105 | | - <ThemedText style={{ fontSize: 20, color: '#999' }}>✕</ThemedText> |
106 | | - </TouchableOpacity> |
107 | | - </ThemedView> |
108 | | - </View> |
109 | | - </Modal> |
110 | | - ) |
111 | | -} |
112 | | - |
113 | 24 | export default function WebView(props: { |
114 | 25 | name: string |
115 | 26 | url: string |
@@ -403,28 +314,3 @@ export default function WebView(props: { |
403 | 314 | </> |
404 | 315 | ) |
405 | 316 | } |
406 | | - |
407 | | -const styles = StyleSheet.create({ |
408 | | - centeredView: { |
409 | | - flex: 1, |
410 | | - justifyContent: 'center', |
411 | | - alignItems: 'center', |
412 | | - backgroundColor: 'rgba(0,0,0,0.5)', |
413 | | - }, |
414 | | - modalView: { |
415 | | - margin: 20, |
416 | | - borderRadius: 10, |
417 | | - paddingVertical: 25, |
418 | | - paddingHorizontal: 20, |
419 | | - width: '80%', |
420 | | - shadowOffset: { |
421 | | - width: 0, |
422 | | - height: 2, |
423 | | - }, |
424 | | - shadowOpacity: 0.25, |
425 | | - shadowRadius: 4, |
426 | | - elevation: 5, |
427 | | - flexDirection: 'column', |
428 | | - gap: 20, |
429 | | - }, |
430 | | -}) |
0 commit comments