agoldis / react-native-mlkit-ocr

Google on-device MLKit Text Recognition for React Native
MIT License
176 stars 41 forks source link

Possible unhandled promise rejection #26

Open karthiarjun opened 2 years ago

karthiarjun commented 2 years ago

Hi, We can pick up the image from local. However, a promise rejection warning has popped up with an empty screen.

Code: / eslint-disable react-native/no-inline-styles / import React, { useState, useEffect } from "react"; import { StyleSheet, View, Button, SafeAreaView, ScrollView, Text, Dimensions, ActivityIndicator, } from 'react-native'; import { ImagePickerResponse, launchImageLibrary, } from 'react-native-image-picker'; import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';

export default function App() { const [loading, setLoading] = useState(false); const [result, setResult] = useState(MlkitOcrResult); const [image, setImage] = useState(ImagePickerResponse);

if (loading) { return (

);

} return (

{!!result?.length && ( {result?.map((block) => { return block.lines.map((line) => { return ( {line.text} ); }); })} )}
karthiarjun commented 2 years ago

Fixes: In ios the response returns "{"assets": [{"fileName": "E13E8B4A-D760-4604-BEB1-2432B276635E.png",......

Below code can fix the error: let jsonRes = response.assets[0].uri; console.log("Image Picker Response: ", jsonRes); if (jsonRes == null) { throw new Error('oh!'); } ......