|
| 1 | +import * as FileSystem from 'expo-file-system'; |
1 | 2 | import * as React from 'react'; |
2 | | -import { Dimensions, StyleSheet } from 'react-native'; |
| 3 | +import { |
| 4 | + ActivityIndicator, |
| 5 | + Dimensions, |
| 6 | + Platform, |
| 7 | + StyleSheet, |
| 8 | +} from 'react-native'; |
| 9 | +import PdfRendererView from 'react-native-pdf-renderer'; |
3 | 10 | import { WebView } from 'react-native-webview'; |
4 | 11 |
|
| 12 | +import Text from '@/components/text'; |
| 13 | +import View from '@/components/view'; |
| 14 | + |
| 15 | +// 这个链接去本科生院的华大校历找:https://jwc.ccnu.edu.cn/index/hdxl.htm |
5 | 16 | const pdfUrl = |
6 | | - 'https://xxb.ccnu.edu.cn/virtual_attach_file.vsb?afc=Uoz9n8U462Lln7LSmAVM7-sozUZMNQzRM8WfM8MVM4UYUNl0gihFp2hmCIa0M1h2USysnkhRnmlYoRGYUzMkolMRUmrfMlU4LRC8nzVRoz6FL4QfU4nkMmnFozAfMl-Jqjfjo4OeosAZC1hXptQ0g47aM4C0LmUZokbw62l8c&oid=1258546771&tid=1076&nid=2488&e=.pdf'; |
| 17 | + 'https://jwc.ccnu.edu.cn/virtual_attach_file.vsb?afc=dLm--8M8-bM47YLWzviLNMRnRQ2LzCHYLm6fnRv8ozLbUmU0gihFp2hmCIa0Mky4oSyYMYh7nlUiMz6VL7-YM7UDU87sM4NaLlUbLllYLmVFUmC8o7UZUlQFLzN8UNr7gjfNQmOeo4xmCDbigDTJQty0Lz74L1yYMmUsLSbw62g8c&oid=1203777467&tid=1132&nid=26471&e=.pdf'; |
7 | 18 |
|
8 | 19 | export default function Calendar() { |
9 | | - // return Platform.select({ |
10 | | - // ios: ( |
11 | | - // <WebView |
12 | | - // style={styles.container} |
13 | | - // source={{ |
14 | | - // uri: pdfUrl, |
15 | | - // cache: true, |
16 | | - // }} |
17 | | - // scalesPageToFit={true} |
18 | | - // javaScriptEnabled={true} |
19 | | - // domStorageEnabled={true} |
20 | | - // injectedJavaScript={` |
21 | | - // document.body.style.overflowX = 'hidden'; |
22 | | - // `} |
23 | | - // /> |
24 | | - // ), |
25 | | - // android: <AndroidCalendar />, |
26 | | - // }); |
27 | | - return ( |
28 | | - <WebView |
29 | | - style={styles.container} |
30 | | - source={{ |
31 | | - uri: pdfUrl, |
32 | | - cache: true, |
33 | | - }} |
34 | | - scalesPageToFit={true} |
35 | | - javaScriptEnabled={true} |
36 | | - domStorageEnabled={true} |
37 | | - injectedJavaScript={` |
| 20 | + return Platform.select({ |
| 21 | + ios: ( |
| 22 | + <WebView |
| 23 | + style={styles.container} |
| 24 | + source={{ |
| 25 | + uri: pdfUrl, |
| 26 | + cache: true, |
| 27 | + }} |
| 28 | + scalesPageToFit={true} |
| 29 | + javaScriptEnabled={true} |
| 30 | + domStorageEnabled={true} |
| 31 | + injectedJavaScript={` |
38 | 32 | document.body.style.overflowX = 'hidden'; |
39 | 33 | `} |
40 | | - /> |
41 | | - ); |
| 34 | + /> |
| 35 | + ), |
| 36 | + android: <AndroidCalendar />, |
| 37 | + }); |
42 | 38 | } |
43 | 39 |
|
44 | | -// const AndroidCalendar: React.FC = () => { |
45 | | -// const [downloading, setDownloading] = React.useState<boolean>(false); |
46 | | -// const [source, setSource] = React.useState<string>(); |
| 40 | +const AndroidCalendar: React.FC = () => { |
| 41 | + const [downloading, setDownloading] = React.useState<boolean>(false); |
| 42 | + const [source, setSource] = React.useState<string>(); |
47 | 43 |
|
48 | | -// const downloadWithExpoFileSystem = React.useCallback(async () => { |
49 | | -// try { |
50 | | -// setDownloading(true); |
51 | | -// const response = await FileSystem.downloadAsync( |
52 | | -// pdfUrl, |
53 | | -// FileSystem.documentDirectory + 'file.pdf' |
54 | | -// ); |
55 | | -// setSource(response.uri); |
56 | | -// } catch (err) { |
57 | | -// //console.warn(err); |
58 | | -// } finally { |
59 | | -// setDownloading(false); |
60 | | -// } |
61 | | -// }, []); |
| 44 | + const downloadWithExpoFileSystem = React.useCallback(async () => { |
| 45 | + try { |
| 46 | + setDownloading(true); |
| 47 | + const response = await FileSystem.downloadAsync( |
| 48 | + pdfUrl, |
| 49 | + FileSystem.documentDirectory + 'file.pdf' |
| 50 | + ); |
| 51 | + setSource(response.uri); |
| 52 | + } catch (err) { |
| 53 | + //console.warn(err); |
| 54 | + } finally { |
| 55 | + setDownloading(false); |
| 56 | + } |
| 57 | + }, []); |
62 | 58 |
|
63 | | -// React.useEffect(() => { |
64 | | -// downloadWithExpoFileSystem(); |
65 | | -// // downloadWithBlobUtil(); |
66 | | -// }, [downloadWithExpoFileSystem]); |
| 59 | + React.useEffect(() => { |
| 60 | + downloadWithExpoFileSystem(); |
| 61 | + // downloadWithBlobUtil(); |
| 62 | + }, [downloadWithExpoFileSystem]); |
67 | 63 |
|
68 | | -// if (downloading) { |
69 | | -// return ( |
70 | | -// <View style={styles.loadingContainer}> |
71 | | -// <ActivityIndicator size="large" color="#7878F8" /> |
72 | | -// <Text style={styles.loadingText}>加载中...</Text> |
73 | | -// </View> |
74 | | -// ); |
75 | | -// } |
| 64 | + if (downloading) { |
| 65 | + return ( |
| 66 | + <View style={styles.loadingContainer}> |
| 67 | + <ActivityIndicator size="large" color="#7878F8" /> |
| 68 | + <Text style={styles.loadingText}>加载中...</Text> |
| 69 | + </View> |
| 70 | + ); |
| 71 | + } |
76 | 72 |
|
77 | | -// return <PdfRendererView source={source}></PdfRendererView>; |
78 | | -// }; |
| 73 | + return <PdfRendererView source={source}></PdfRendererView>; |
| 74 | +}; |
79 | 75 |
|
80 | 76 | const styles = StyleSheet.create({ |
81 | 77 | container: { |
|
0 commit comments