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