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";
6
7export function PdfPreview(props: { readonly uri: string }) {
8 const [error, setError] = useState<string | null>(null);
9 return (
10 <View className="flex-1 bg-card">
11 {error ? <FilePreviewNotice title="Could not load PDF">{error}</FilePreviewNotice> : null}
12 <WebView
13 source={{ uri: props.uri }}
14 originWhitelist={["*"]}
15 automaticallyAdjustContentInsets={false}
16 contentInsetAdjustmentBehavior="never"
17 startInLoadingState
18 onError={(event) =>
19 setError(event.nativeEvent.description || "The PDF could not be loaded.")
20 }
21 onHttpError={(event) =>
22 setError(`The server returned HTTP ${event.nativeEvent.statusCode}.`)
23 }
24 renderLoading={() => <FilePreviewLoading message="Loading PDF..." background="card" />}
25 style={{ flex: 1, backgroundColor: "transparent" }}
26 />
27 </View>
28 );
29}