diff --git a/.changeset/sour-wombats-invite.md b/.changeset/sour-wombats-invite.md new file mode 100644 index 00000000..741091d7 --- /dev/null +++ b/.changeset/sour-wombats-invite.md @@ -0,0 +1,6 @@ +--- +"@infinitered/react-native-mlkit-barcode-scanning": minor +"example-app": minor +--- + +add react native mlkit barcode scanning module diff --git a/apps/ExampleApp/app.json b/apps/ExampleApp/app.json index ad770a10..8f4eb6ea 100644 --- a/apps/ExampleApp/app.json +++ b/apps/ExampleApp/app.json @@ -74,7 +74,8 @@ { "photosPermission": "This app uses the photo library to select images for Machine Learning purposes. i.e. Object and Image detection." } - ] + ], + "expo-asset" ], "experiments": { "tsconfigPaths": true diff --git a/apps/ExampleApp/app/components/CameraModal.tsx b/apps/ExampleApp/app/components/CameraModal.tsx new file mode 100644 index 00000000..a77c02b6 --- /dev/null +++ b/apps/ExampleApp/app/components/CameraModal.tsx @@ -0,0 +1,223 @@ +import React, { useRef, useState } from "react" +import { + Modal, + View, + TouchableOpacity, + ActivityIndicator, + ViewStyle, + TextStyle, +} from "react-native" +import { useSafeAreaInsets } from "react-native-safe-area-context" +import { CameraView, useCameraPermissions, CameraType } from "expo-camera" +import { Text } from "./Text" +import { Button } from "./Button" +import { colors, spacing } from "../theme" + +interface CameraModalProps { + visible: boolean + onCapture: (uri: string) => void + onClose: () => void +} + +export function CameraModal({ visible, onCapture, onClose }: CameraModalProps) { + const cameraRef = useRef(null) + const [permission, requestPermission] = useCameraPermissions() + const [isCapturing, setIsCapturing] = useState(false) + const [facing, setFacing] = useState("back") + const insets = useSafeAreaInsets() + + const toggleFacing = () => { + setFacing((current) => (current === "back" ? "front" : "back")) + } + + const handleCapture = async () => { + if (!cameraRef.current || isCapturing) return + + setIsCapturing(true) + try { + const photo = await cameraRef.current.takePictureAsync({ + quality: 0.5, + }) + if (photo?.uri) { + onCapture(photo.uri) + } + } catch (error) { + console.error("Error capturing photo:", error) + } finally { + setIsCapturing(false) + } + } + + if (!permission) { + return null + } + + if (!permission.granted) { + return ( + + + + Camera permission is required to take photos. +