import React, { FC, useState } from 'react'; import { View, Text } from 'react-native'; import { OcrPicture, Button, Space } from '@xrnjs/ui'; import Card from '_global/Card'; import styles from './style'; const StaticUsage: FC = () => { const [loading, setLoading] = useState(false); const [result, setResult] = useState(''); const [error, setError] = useState(''); const handleStaticCall = (type: 'success' | 'error' | 'timeout') => { setLoading(true); setResult(''); setError(''); const config = { tip: '请将证件放置在框内', direction: OcrPicture.OcrPictureDirection.Horizontal, timeout: type === 'timeout' ? 1000 : 10000, onScan: (option: any) => { console.log('静态调用扫描:', option); return new Promise((resolve, reject) => { setTimeout( () => { if (type === 'success') { resolve('静态调用成功: 123456789012345678'); } else { reject(new Error('静态调用失败')); } }, type === 'timeout' ? 2000 : 1500 ); }); }, }; OcrPicture.open(config) .then((result) => { console.log('静态调用结果:', result); setResult(JSON.stringify(result)); }) .catch((error) => { console.log('静态调用错误:', error); setError(error.message); }) .finally(() => { setLoading(false); }); }; return ( 通过 OcrPicture.open() 方法可以直接调用 OCR 识别功能,无需渲染输入框组件。 {result ? ( 识别成功 {result} ) : null} {error ? ( 识别失败 {error} ) : null} ); }; export default StaticUsage;