The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useGT } from "gt-react-native"; |
| 2 | import { useState } from "react"; |
| 3 | import { View } from "react-native"; |
| 4 | import { WebView } from "react-native-webview"; |
| 5 | |
| 6 | import { FilePreviewLoading, FilePreviewNotice } from "../features/files/FilePreviewFeedback"; |
| 7 | import { webViewDecelerationRate } from "../lib/webViewDecelerationRate"; |
| 8 | |
| 9 | export 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 ? ( |
| 15 | <FilePreviewNotice title={gt("Could not load PDF")}>{error}</FilePreviewNotice> |
| 16 | ) : null} |
| 17 | <WebView |
| 18 | source={{ uri: props.uri }} |
| 19 | originWhitelist={["*"]} |
| 20 | automaticallyAdjustContentInsets={false} |
| 21 | decelerationRate={webViewDecelerationRate} |
| 22 | contentInsetAdjustmentBehavior="never" |
| 23 | startInLoadingState |
| 24 | onError={(event) => |
| 25 | setError(event.nativeEvent.description || gt("The PDF could not be loaded.")) |
| 26 | } |
| 27 | onHttpError={(event) => |
| 28 | setError( |
| 29 | gt("The server returned HTTP {statusCode}.", { |
| 30 | statusCode: event.nativeEvent.statusCode, |
| 31 | }), |
| 32 | ) |
| 33 | } |
| 34 | renderLoading={() => ( |
| 35 | <FilePreviewLoading message={gt("Loading PDF...")} background="card" /> |
| 36 | )} |
| 37 | style={{ flex: 1, backgroundColor: "transparent" }} |
| 38 | /> |
| 39 | </View> |
| 40 | ); |
| 41 | } |