Open History to see the last commit
1import { useState } from "react";
2import { View } from "react-native";
3import { WebView } from "react-native-webview";
4
5import { FilePreviewLoading, FilePreviewNotice } from "../features/files/FilePreviewFeedback";
6import { webViewDecelerationRate } from "../lib/webViewDecelerationRate";
7
8export function PdfPreview(props: { readonly uri: string }) {
9 const [error, setError] = useState<string | null>(null);
10 return (
11 <View className="flex-1 bg-card">
12 {error ? <FilePreviewNotice title="Could not load PDF">{error}</FilePreviewNotice> : null}
13 <WebView
14 source={{ uri: props.uri }}
15 originWhitelist={["*"]}
16 automaticallyAdjustContentInsets={false}
17 decelerationRate={webViewDecelerationRate}
18 contentInsetAdjustmentBehavior="never"
19 startInLoadingState
20 onError={(event) =>
21 setError(event.nativeEvent.description || "The PDF could not be loaded.")
22 }
23 onHttpError={(event) =>
24 setError(`The server returned HTTP ${event.nativeEvent.statusCode}.`)
25 }
26 renderLoading={() => <FilePreviewLoading message="Loading PDF..." background="card" />}
27 style={{ flex: 1, backgroundColor: "transparent" }}
28 />
29 </View>
30 );
31}