From fb0a18d61c43b17b0427eea5ca8fb94797798a6a Mon Sep 17 00:00:00 2001
From: peng-xiaohua <68681502+peng-xiaohua@users.noreply.github.com>
Date: Mon, 12 Aug 2024 14:02:11 +0800
Subject: [PATCH] =?UTF-8?q?test:=20=E6=96=B0=E5=A2=9Ern=5Fmlkit=5Focr?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95demo=EF=BC=8C=E6=96=B0=E5=A2=9Ern=5Fmlkit=5Fo?=
=?UTF-8?q?cr=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B(#801)=20(#802)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: pWX1342412 <18292915636@163.com>
---
react-native-mlkit-ocr/Test/OcrTest.tsx | 160 ++++++++++++++++++++++
react-native-mlkit-ocr/TestOcrExample.tsx | 95 +++++++++++++
2 files changed, 255 insertions(+)
create mode 100644 react-native-mlkit-ocr/Test/OcrTest.tsx
create mode 100644 react-native-mlkit-ocr/TestOcrExample.tsx
diff --git a/react-native-mlkit-ocr/Test/OcrTest.tsx b/react-native-mlkit-ocr/Test/OcrTest.tsx
new file mode 100644
index 00000000..d376a180
--- /dev/null
+++ b/react-native-mlkit-ocr/Test/OcrTest.tsx
@@ -0,0 +1,160 @@
+import React from 'react';
+import { TestSuite, TestCase, Tester } from '@rnoh/testerino';
+import {
+ StyleSheet,
+ View,
+ TouchableHighlight,
+ SafeAreaView,
+ Text,
+ ActivityIndicator,
+} from 'react-native';
+import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';
+
+const PALETTE = {
+ REACT_CYAN_LIGHT: 'hsl(193, 95%, 68%)',
+ REACT_CYAN_DARK: 'hsl(193, 95%, 30%)',
+}
+
+function Button({ label, onPress }: { onPress: () => void; label: string }) {
+ return (
+
+
+ {label}
+
+
+ );
+}
+
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ },
+ scroll: {
+ flex: 1,
+ width: '100%',
+ borderColor: '#ccc',
+ borderWidth: 2,
+ height: '70%',
+ },
+});
+
+export const OcrTest = () => {
+ const [loading, setLoading] = React.useState(false);
+ const [result, setResult] = React.useState();
+
+ if (loading) {
+ return (
+
+
+
+ );
+ }
+ return (
+
+
+
+ {Array.isArray(result) && result?.length && (
+
+ {result?.map((block) => {
+ console.log("=================result>", JSON.stringify(result));
+ console.log("=================block>", JSON.stringify(block));
+
+ return block.lines.map((line) => {
+ return (
+
+ {line.text}
+
+ );
+ });
+ })}
+
+ )}
+
+
+ {
+ return (
+
+
+ );
+ }}
+ assert={async ({ expect, state }) => {
+ expect(state).to.be.true;
+ }}
+ />
+ {
+ return (
+
+
+ );
+ }}
+ assert={async ({ expect, state }) => {
+ expect(state).to.be.true;
+ }}
+ />
+
+
+
+
+
+ );
+
+};
+
diff --git a/react-native-mlkit-ocr/TestOcrExample.tsx b/react-native-mlkit-ocr/TestOcrExample.tsx
new file mode 100644
index 00000000..2fafac80
--- /dev/null
+++ b/react-native-mlkit-ocr/TestOcrExample.tsx
@@ -0,0 +1,95 @@
+/* eslint-disable react-native/no-inline-styles */
+import * as React from 'react';
+import {
+ StyleSheet,
+ View,
+ Button,
+ SafeAreaView,
+ ScrollView,
+ Text,
+ Dimensions,
+ ActivityIndicator,
+} from 'react-native';
+import MlkitOcr, { MlkitOcrResult } from 'react-native-mlkit-ocr';
+const styles = StyleSheet.create({
+ container: {
+ flex: 1,
+ justifyContent: 'center',
+ },
+ scroll: {
+ flex: 1,
+ width: '100%',
+ borderColor: '#ccc',
+ borderWidth: 2,
+ },
+});
+export const OcrTest = () => {
+ const [loading, setLoading] = React.useState(false);
+ const [result, setResult] = React.useState();
+
+ if (loading) {
+ return (
+
+
+
+ );
+ }
+ return (
+
+ {Array.isArray(result) && result?.length && (
+
+ {result?.map((block) => {
+ return block.lines.map((line) => {
+ return (
+
+ {line.text}
+
+ );
+ });
+ })}
+
+ )}
+
+
+ );
+}
+