dynamsoft / capture-vision-react-native-samples Goto Github PK
View Code? Open in Web Editor NEWDynamsoft Capture Vision React-Native SDK Samples
Home Page: https://www.dynamsoft.com/capture-vision/docs/introduction/
License: Other
Dynamsoft Capture Vision React-Native SDK Samples
Home Page: https://www.dynamsoft.com/capture-vision/docs/introduction/
License: Other
The app getting freezing on unmounting, any solution?
I am getting this error ...
Please Help me..
Package.json
"@react-native-community/masked-view": "^0.1.11",
"@react-navigation/native": "^6.0.2",
"@react-navigation/native-stack": "^6.0.5",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-gesture-handler": "^1.10.3",
"react-native-reanimated": "^2.2.0",
"react-native-safe-area-context": "^3.3.0",
"react-native-screens": "^3.5.0",
"rn-mobile-barcode-scanner": "^8.6.0"
Hello,
Most recent version of [email protected]
currently experiences typescript conflicts that have been raised during our tsc
step.
Is it possible to request the team to have a look in to the typing definitions to solve these conflicts? For now, I'm patching the package and skipping ts
compiler from checking this file dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx
by adding // @ts-nocheck
at the top of the problematic file. This way our CI
won't raise the exception. Ideally I should drop this patch as soon as the issue is resolved in the package directly.
Details of the typings errors:
$ tsc
Error: node_modules/dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx(46,7): error TS2322: Type 'ComponentType<any>' is not assignable to type 'HostComponent<any>'.
Type 'ComponentClass<any, any>' is not assignable to type 'HostComponent<any>'.
Type 'Component<any, any, any>' is not assignable to type 'Component<any, {}, any> & Readonly<NativeMethods>'.
Type 'Component<any, any, any>' is missing the following properties from type 'Readonly<NativeMethods>': measure, measureInWindow, measureLayout, setNativeProps, and 2 more.
Error: node_modules/dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx(51,[9](...)): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
Error: node_modules/dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx([10](...): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ torchState: any; }'.
No index signature with a parameter of type 'string' was found on type '{ torchState: any; }'.
Error: node_modules/dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx(102,20): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ torchState: any; }'.
No index signature with a parameter of type 'string' was found on type '{ torchState: any; }'.
Error: node_modules/dynamsoft-capture-vision-react-native/js/DynamsoftCameraView.tsx([14](...): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UIManagerStatic'.
No index signature with a parameter of type 'string' was found on type 'UIManagerStatic'.
error Command failed with exit code 2.
Note: forgot to mentioned that some of those typing conflicts present on [email protected]
Hi @Dynamsoft-Henry can we scan documents using this sdk on ios and android, if not, do you guys have any plan to support this feature.
It only happens on iOS(I use RN: iOS-13.0, device: 16.4)
Using package version
"dynamsoft-capture-vision-react-native": "^1.1.7",
"react": "18.2.0",
"react-native": "0.71.7",
import React, { useRef, useState, useEffect } from 'react';
import { RouteProp, useNavigation, useNavigationState, useRoute } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { AppStackParamList } from '../../route/routeDef';
import { IFile } from '../../constants/IFile';
import { imgUploadCall } from '../../helper/s3Upload';
import useCustomHeader from '../../hooks/useCustomHeader';
import styled from 'styled-components/native';
import LMText from '../../components/atoms/LMText';
import {
DCVBarcodeReader,
DCVCameraView,
EnumBarcodeFormat,
EnumTorchState,
} from 'dynamsoft-capture-vision-react-native';
import { BarcodeResult } from '../../node_modules/dynamsoft-capture-vision-react-native/js/BarcodeResult';
import codeMasterStore from '../../stores/codeMasterStore';
import loaderStore from '../../stores/loaderStore';
import Button from '../../components/atoms/button';
import { captureScreen } from 'react-native-view-shot';
import { Platform } from 'react-native';
import { observer } from 'mobx-react';
const Layout = styled.View`
flex: 1;
justify-content: space-between;
`;
const NotificationView = styled.View`
align-items: center;
`;
const NotificationBox = styled.View`
margin-top: 19px;
background-color: ${({theme}) => theme.colors.white.base};
border-radius: ${({theme}) => theme.base.borderRadius}px;
width: 258px;
padding: 12px 20px;
align-items: center;
justify-content: center;
`;
const NotificationText = styled(LMText)`
font-size: ${({theme}) => theme.typography.size.s1}px;
color: ${({theme}) => theme.colors.gray.base};
text-align: center;
line-height: 19.56px;
`;
const BottomView = styled.View`
margin-bottom: 24px;
padding: 0 ${({theme}) => theme.base.templatePadding}px;
`;
const LicenseText = styled.Text`
position: absolute;
top: 25%;
right: 25%;
font-size: ${({theme}) => theme.typography.size.l3}px;
color: ${({theme}) => theme.colors.gray[300]};
`;
const ScanRegion = {
regionTop: 40,
regionLeft: 15,
regionBottom: 60,
regionRight: 85,
regionMeasuredByPercentage: true,
};
const Scan = observer(() => {
const navigation = useNavigation<NativeStackNavigationProp<AppStackParamList>>();
const router = useRoute<RouteProp<AppStackParamList, '_Scan'>>();
const routes = useNavigationState(state => state.routes);
const prevRoute = routes[routes.length - 2];
const [reader, setReader] = useState<DCVBarcodeReader>();
// Ref
const DCVRef = useRef<DCVCameraView>(null);
const clear = async () => {
console.log(router.params.key, 'clear start');
if (reader) {
reader.removeAllResultListeners();
await reader.stopScanning();
setReader(undefined);
}
console.log(router.params.key, 'clear end');
};
const createReader = async () => {
console.log(router.params.key, 'createReader start');
try {
const _reader = await DCVBarcodeReader.createInstance();
setReader(_reader);
} catch (error: any) {
console.log('create reader error =>', error);
}
console.log(router.params.key, 'createReader end');
};
const startScanning = async () => {
console.log(router.params.key, 'const startScanning start');
try {
if (!reader) {
console.log('no reader');
return;
}
await reader.resetRuntimeSettings();
// Set the expected barcode count to 0 when you are not sure how many barcodes you are scanning.
// Set the expected barcode count to 1 can maximize the barcode decoding speed.
let setting = await reader.getRuntimeSettings();
setting.expectedBarcodesCount = 1;
// Set the barcode format to read.
setting.barcodeFormatIds = EnumBarcodeFormat.BF_ALL;
// Apply the new runtime settings to the barcode reader.
await reader.updateRuntimeSettings(setting);
// await reader.startScanning();
} catch (e) {
console.log('startScanning');
console.log(e);
}
console.log(router.params.key, 'const startScanning end');
};
const regularizeResults = (results: Array<BarcodeResult>) => {
const resultList = results.map((result) => result.barcodeText);
const resultBarcodes = removeUnExpectWord(resultList);
return resultBarcodes;
};
const removeUnExpectWord = (barcodes: Array<string>) => {
const reg = /[\{\}\[\]\/?.,;:|\)*~`!^\-_+<>@\#$%&\\\=\(\'\"]/gi;
const editedBarcodes = barcodes.map((barcode) => {
let _barcode = barcode.trim();
if (_barcode.startsWith('{GS}')) {
_barcode = _barcode.replace('{GS}', '');
}
if (_barcode.endsWith('{GS}')) {
_barcode = _barcode.replace('{GS}', '');
}
return _barcode;
});
return editedBarcodes;
};
// 사진을 촬영하여 이미지 주소를 생성합니다.
const handleMakePhotoUrl = async (fileUri: string) => {
try {
const file: IFile = {
uri: fileUri,
name: codeMasterStore.currentTime.toString(),
type: 'image/jpeg',
};
const url = await imgUploadCall(file);
return url;
} catch (e) {
console.log(e);
console.log('handleMakePhotoUrl');
}
};
// 화면을 캡쳐하고, 이와 별개로 바코드를 스캔합니다.
const takeScreenShotAndBarcode = async () => {
console.log(router.params.key, 'takeScreenShotAndBarcode start');
try {
if (!reader) {
console.log('reader 없음');
return;
}
const capture = await captureScreen({format: 'jpg', quality: 0.3});
if (!capture) {
return;
}
const url = await handleMakePhotoUrl(capture);
reader.addResultListener(async (data) => {
if (data) {
const regularize = regularizeResults(data);
if (regularize.length > 0) {
reader.removeAllResultListeners();
if (router.params.withImage) {
await clear();
// NOTE: react-native-view-shot
// 해당 라이브러리는 ios 환경을 캡쳐할 수 없는 이슈
if (Platform.OS === 'ios') {
goPrevRoute(regularize[0].trim(), false);
} else {
goPrevRoute(regularize[0].trim(), true, url);
}
} else {
await clear();
goPrevRoute(regularize[0].trim(), false);
}
}
}
});
} catch (e) {
console.log('takeScreenShotAndBarcode');
console.log(e);
}
console.log(router.params.key, 'takeScreenShotAndBarcode end');
};
const goPrevRoute = (barcode: string, withImage: boolean, imageUrl?: string | null) => {
console.log(router.params.key, 'goPrevRoute start');
if (!withImage) {
// @ts-ignore
navigation.navigate({
name: prevRoute.name,
params: {
barcode: barcode,
// @ts-ignore
key: router.params.key,
},
merge: true,
});
console.log(router.params.key, 'goPrevRoute end');
return;
}
// @ts-ignore
navigation.navigate({
name: prevRoute.name,
params: {
barcode: barcode,
scannedImage: imageUrl,
// @ts-ignore
key: router.params.key,
},
merge: true,
});
console.log(router.params.key, 'goPrevRoute end');
};
useCustomHeader({
title: '바코드 스캔',
});
useEffect(() => {
if (reader) {
// @ts-ignore
console.log(router.params.key, 'Scan');
console.log(reader, 'Scan');
(async () => {
try {
loaderStore.setLoading(true);
console.log(router.params.key, 'reader.startScanning start');
await reader.startScanning();
console.log(router.params.key, 'reader.startScanning end');
loaderStore.setLoading(false);
} catch (e) {
console.log(e);
}
})();
} else {
(async () => {
loaderStore.setLoading(true);
await createReader();
loaderStore.setLoading(false);
})();
}
}, [reader]);
return (
<Layout collapsable={false}>
<DCVCameraView
style={{flex: 1, justifyContent: 'space-between'}}
ref={DCVRef}
overlayVisible={true}
// @ts-ignore
torchButton={{visible: true}}
torchState={EnumTorchState.OFF}
scanRegionVisible={true}
scanRegion={ScanRegion}
>
<LicenseText>Powered by Dynamsoft</LicenseText>
<NotificationView>
<NotificationBox>
<NotificationText>{`바코드를 사각형에 위치시키고\n바코드 스캔 버튼을 눌러주세요`}</NotificationText>
</NotificationBox>
</NotificationView>
<BottomView>
{loaderStore.loading ? null :
<Button
title="바코드 스캔"
size="large"
onPress={async () => {
loaderStore.setLoading(true);
await startScanning();
await takeScreenShotAndBarcode();
loaderStore.setLoading(false);
}}
/>}
</BottomView>
</DCVCameraView>
</Layout>
);
});
export default Scan;
Unfortunately, this is not my code, so I don't know the reason for writing etc. in detail.
So if there is a problem, I think it needs to be fixed.
I would like to know the cause of Severe Hang additionally. Is there a logic that intentionally triggers Hang?
Hello,
Please label this query accordingly, as I could only submit an issue.
I was wondering if there is way (maybe not documented yet) to style the scanRegion and overlay look. Currently I could not find any info in the documentation.
From the (web demo) I can see the reader has a different look, so bearing in mind the differences between the APIs, theoretically this could possible, but not supported yet?
So I am wondering if there is any chance to support this functionality? I would like to make scan region with a border radius, different border colour and a darker masking background.
I'm trying to add this barcode scanner to an existing React Native project. After running yarn && npx pod-install ios
here is the error I get:
[!] CocoaPods could not find compatible versions for pod "DynamsoftBarcodeReader":
In Podfile:
dynamsoft-capture-vision-react-native (from `../node_modules/dynamsoft-capture-vision-react-native`) was resolved to 1.1.7, which depends on
DynamsoftBarcodeReader (= 9.2.13)
vision-camera-dynamsoft-barcode-reader (from `../node_modules/vision-camera-dynamsoft-barcode-reader`) was resolved to 0.6.0, which depends on
DynamsoftBarcodeReader (= 9.4.0)
###Packages
"react-native": "0.67.1",
"dynamsoft-capture-vision-react-native": "^1.1.7",
Any ideas on how to handle this?
Our team relies on separate package for app permissions workflow. We noticed that the app in ios
is not following the implemented workflow (android
does).
Basically the app in ios
requests the camera permission during the app first launch, but in android
it only occurs on user demand when the camera is opened for the first time. The ladder is the better user experience.
This behaviour also occurs in the sample app.
Would it be possible to have a unified workflow more similar to what currently happens in android
?
Hello Dynamsoft team,
We noticed that from version 1.1.8
(also present in latest 1.1.9
), the app gets stuck in the SplashScreen when the running the ios
simulator. Inspecting logs and runtime activity unfortunately does not raise any insightful info or runtime exceptions that can point to the exact issue.
However backtracking the change history in our codebase we can clearly see that the issue started when the sdk version was bumped to 1.1.8
The app passes the SplashScreen on devices (android
and ios
) and emulator (android
).
We understand that this camera sdk is supported for devices as they're the only ones with camera hardware to validate functionality for DynamsoftBarcodeReader
and DynamsoftCameraEnhancer
. However version 1.1.7
did not experience this issue and the simulator would work fine. We even downgraded the sdk
to validate this is the case.
We cannot rely on device only for development purposes as other team members don't use a device to work on other functionality for the app. They may just use a simulator or an emulator. This issue basically will block their local development environment.
Details of the changes that introduced the issue
Perhaps this may have been introduced in the pods DynamsoftBarcodeReader (9.6.10) and DynamsoftCameraEnhancer (2.3.1) when dynamsoft-capture-vision-react-native
version bump from 1.1.7 to 1.1.8?
Basically DynamsoftBarcodeReader (9.2.13) and DynamsoftCameraEnhancer (2.3.2) were free of this issue but had other issues such as scanRegion problems.
Could you please have a look and apologies for not offering more details.
Thanks a lot.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.