Open 222xiaohuan opened 7 years ago
@andreaskeller can you please help to have a look at this problem? thanks very much!
@222xiaohuan you can use a view to fix it. like this
let content if (this.state.backing) { content = <View style={{flex:1,backgroundColor:'rgba(0,0,0,0.6)'}}/> } else { content = <BarcodeScanner onBarCodeRead={this._onBarCodeRead} style={{height: screenHeight,flex:1}} torchMode={'off'} cameraType={'back'} /> }
onPress back you can change state on backing and then setTimeout to pop this scene.
Does anyone have a better solution?
I am doing almost the same… displaying a black screen with a loading animation. And then I replace it with the actual camera with
InteractionManager.runAfterInteractions(() => {
// Start scanner preview as soon as page transitions have finished
this.enable();
});
I'll give it a try, thanks @namxam.
@222xiaohuan 我也遇到了同样的问题,你现在使用什么解决方法,可以告诉我吗?
@222xiaohuan @Cocoon-break 当此问题出现之后,我同时再使用其他camera相关的插件,例如react-native-image-picker,这时候react-native-image-picker也会变得很慢,我就得这可能和资源没有释放干净有关。
@liuyimx 你解决了吗?我还没有解决,上面的方法你试了没,我一会试试看。这个性能老大完全不能接受T_T
@222xiaohuan 上面的方法我试了,先给个loading页面然后pop,视觉上pop没有卡顿,但是使用了此插件还是会导致react-native-image-picker及整个app变慢,另外 #47 问题依然存在。最近有个新插件叫 react-native-barcode-scanner-google,我试过貌似还不能用。现在我们正在改这个插件希望可以解决android的扫码问题。
@Cocoon-break your method works, thanks :)
@Cocoon-break Your method will crash the app, and throw exception:
java.lang.RuntimeException: Camera is being used after Camera.release() was called
BarcodeScannerManager add stopCamera method expose to js:
@Nullable
@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("stopCamera", COMMAND_STOP_CAMERA);
}
@Override
public void receiveCommand(BarcodeScannerView root, int commandId, @Nullable ReadableArray args) {
if (commandId == COMMAND_STOP_CAMERA) {
root.stopCamera();
}
}
BarcodeScannerView JS:
stopCamera() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.RNBarcodeScannerView.Commands.stopCamera,
[],
);
}
We can use it like this:
componentWillMount() {
InteractionManager.runAfterInteractions(() => {
this.setState({
showOverlay: false,
showBarcodeScanner: true,
});
});
}
_onBackHandler = () => {
this.setState({
showOverlay: true
}, () => {
this.scanner.stopCamera();
this.timeout = setTimeout(() => {
this.props.router.pop();
}, 1000);
});
return true;
};
@someok thanks, nice job, I finally added some release and start methods in module to solve this problem, will try your method later.
@222xiaohuan 你解决了这个问题么?我也遇到了同样的问题,我尝试使用了someok的方法但是没作用。 如果你解决了可以告知一下吗?谢谢!
Just an update to @someok comment for those of us who don't speak java. This code should be in: android/src/main/java/com/eguma/barcodescanner/BarcodeScannerManager.java
@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("stopCamera", COMMAND_STOP_CAMERA);
}
@Override
public void receiveCommand(BarcodeScannerView root, int commandId, @Nullable ReadableArray args) {
if (commandId == COMMAND_STOP_CAMERA) {
root.stopCamera();
}
}```
@Cocoon-break I have do it like you, but on some devices(Galaxy S7 Edge) will get error, have a black screen in the bottom, all animation is slow down.
@someok where the variable ReadableArray?
Hi Thanks for providing this awesome component, I already implemented this into our project, it is working! however we met a problem when running the app on android device, it is too slow when call " this.props.navigator.pop();" on the scanner page. is there any method to improve the performance? thanks very much. will attach some screenshots for your information. the fps is very low.
![screenshot_2016-08-01-14-26-47](https://cloud.githubusercontent.com/assets/38194/17285389/f8079504-57f4-11e6-86bc-0a5bda8f3d39.png)
Best Regards & Thanks Emily