From da4cbdb61b0cfe6b71393ee9ede5b7dd3c4d6592 Mon Sep 17 00:00:00 2001 From: Mazen Chami Date: Thu, 4 Apr 2024 12:05:05 -0400 Subject: [PATCH] iOS Document Scanner fix (#132) --- .changeset/old-pugs-brake.md | 5 + .../screens/DocumentScannerScreen.android.tsx | 171 ++++++++++++++++++ .../app/screens/DocumentScannerScreen.tsx | 141 +-------------- apps/InfiniteRedAI/package.json | 2 +- 4 files changed, 182 insertions(+), 137 deletions(-) create mode 100644 .changeset/old-pugs-brake.md create mode 100644 apps/InfiniteRedAI/app/screens/DocumentScannerScreen.android.tsx diff --git a/.changeset/old-pugs-brake.md b/.changeset/old-pugs-brake.md new file mode 100644 index 00000000..412d1e29 --- /dev/null +++ b/.changeset/old-pugs-brake.md @@ -0,0 +1,5 @@ +--- +"@infinitered/infinite-red-ai": patch +--- + +isolating document scanner to only android (fixes iOS crash) diff --git a/apps/InfiniteRedAI/app/screens/DocumentScannerScreen.android.tsx b/apps/InfiniteRedAI/app/screens/DocumentScannerScreen.android.tsx new file mode 100644 index 00000000..0a89b4e3 --- /dev/null +++ b/apps/InfiniteRedAI/app/screens/DocumentScannerScreen.android.tsx @@ -0,0 +1,171 @@ +import React, { FC } from "react" +import { observer } from "mobx-react-lite" +import { ViewStyle, View, ImageStyle, TextStyle } from "react-native" +import { NativeStackScreenProps } from "@react-navigation/native-stack" +import { AppStackScreenProps } from "../navigators" +import { Screen, Text, Icon, Button, ListItem, TextField, Toggle } from "../components" +import { useTypedNavigation } from "../navigators/useTypedNavigation" +import { + ResultFormatOptions, + ScannerModeOptions, + launchDocumentScannerAsync, +} from "@infinitered/react-native-mlkit-document-scanner" +import { spacing } from "app/theme" + +interface DocumentScannerScreenProps + extends NativeStackScreenProps> {} + +export const DocumentScannerScreen: FC = observer( + function DocumentScannerScreen() { + const navigation = useTypedNavigation<"DocumentScanner">() + const [result, setResult] = React.useState("") + const [allowGallery, setAllowGallery] = React.useState(false) + const [mode, setMode] = React.useState(ScannerModeOptions.FULL) + const [resultFormat, setResultFormat] = React.useState( + ResultFormatOptions.ALL, + ) + const [pageLimit, setPageLimit] = React.useState(1) + + return ( + + + navigation.navigate("Home")} style={$backIcon} /> + + + Configure scanner options and tap `Scan Document` to launch the modal + + + + { + // parse string to int and make sure if not or less than 1, set to 1 + const num = parseInt(text) + setPageLimit(isNaN(num) || num < 1 ? 1 : num) + }} + containerStyle={$pageLimit} + textAlign="right" + /> + } + /> + setAllowGallery(!allowGallery)} + containerStyle={$centerSwitch} + /> + } + /> + + setMode(ScannerModeOptions.BASE)} + /> + setMode(ScannerModeOptions.BASE_WITH_FILTER)} + /> + setMode(ScannerModeOptions.FULL)} + /> + + } + /> + + setResultFormat(ResultFormatOptions.ALL)} + /> + setResultFormat(ResultFormatOptions.PDF)} + /> + setResultFormat(ResultFormatOptions.JPEG)} + /> + + } + /> + +