ideacreation / react-native-barcodescanner

A barcode scanner component for react native - not maintained anymore - use react-native-camera
MIT License
537 stars 162 forks source link

too slow when pop from the scanner page #46

Open 222xiaohuan opened 7 years ago

222xiaohuan commented 7 years ago

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-43 screenshot_2016-08-01-14-26-47

Best Regards & Thanks Emily

222xiaohuan commented 7 years ago

@andreaskeller can you please help to have a look at this problem? thanks very much!

Cocoon-break commented 7 years ago

@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.

jqn commented 7 years ago

Does anyone have a better solution?

namxam commented 7 years ago

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();
});
jqn commented 7 years ago

I'll give it a try, thanks @namxam.

liuyimx commented 7 years ago

@222xiaohuan 我也遇到了同样的问题,你现在使用什么解决方法,可以告诉我吗?

liuyimx commented 7 years ago

@222xiaohuan @Cocoon-break 当此问题出现之后,我同时再使用其他camera相关的插件,例如react-native-image-picker,这时候react-native-image-picker也会变得很慢,我就得这可能和资源没有释放干净有关。

222xiaohuan commented 7 years ago

@liuyimx 你解决了吗?我还没有解决,上面的方法你试了没,我一会试试看。这个性能老大完全不能接受T_T

liuyimx commented 7 years ago

@222xiaohuan 上面的方法我试了,先给个loading页面然后pop,视觉上pop没有卡顿,但是使用了此插件还是会导致react-native-image-picker及整个app变慢,另外 #47 问题依然存在。最近有个新插件叫 react-native-barcode-scanner-google,我试过貌似还不能用。现在我们正在改这个插件希望可以解决android的扫码问题。

222xiaohuan commented 7 years ago

@Cocoon-break your method works, thanks :)

someok commented 7 years ago

@Cocoon-break Your method will crash the app, and throw exception:

java.lang.RuntimeException: Camera is being used after Camera.release() was called

someok commented 7 years ago

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;
    };
222xiaohuan commented 7 years ago

@someok thanks, nice job, I finally added some release and start methods in module to solve this problem, will try your method later.

LitbLeo commented 7 years ago

@222xiaohuan 你解决了这个问题么?我也遇到了同样的问题,我尝试使用了someok的方法但是没作用。 如果你解决了可以告知一下吗?谢谢!

jqn commented 7 years ago

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();
        }
    }```
leonacky commented 7 years ago

@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.

daffy6537 commented 7 years ago

@someok where the variable ReadableArray?