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

Suggestion to make the example easier (Scanner not visible) #11

Open MariusBozem opened 8 years ago

MariusBozem commented 8 years ago

Hey, I just tried our the barcode scanner. At first I couldn't get it to work and was confused what my mistake was.

It turned out that the container element did not have "flex: 1" in its styles and therefore apparently had a height of 0 which meant that the barcode scanner wasn't visible at all. I don't know if others will stumble upon this aswell, but just in case, here's how I solved it:

in render(): <View style={styles.container}> <BarcodeScanner onBarCodeRead={this.barcodeReceived} style={{ flex: 1 }} torchMode={this.state.torchMode} cameraType={this.state.cameraType} /> </View> and the styles:

var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'red', } });

MariusBozem commented 8 years ago

Also the scanner seems to always be in landscape mode regardless of the device orientation. Is there a fix for that?

andreyvital commented 8 years ago

@MariusBozem I think that it isn't responsive to orientation changes. I'm willing to code this specific feature if necessary. But before we get to that, we have to discuss the API.

For example: it may be interesting to others a prop in BarcodeScanner component which allows you to set the orientation and then you can handle it in your application level – or – you can still have a prop that allows you to set the orientation and if isn't set then it starts responding to orientation changes automatically.

MariusBozem commented 8 years ago

Yes, I like both of your suggestions and for me it would be perfect if it would respond to orientation automatically for now

andreyvital commented 8 years ago

By looking at the dm77/barcodescanner (the library that this package uses for scanning) looks like it's already there: ViewFinderView.java#L149-L158

MariusBozem commented 8 years ago

Yes, I've done a bit of research and can confirm that the used library should support it.

I've only tried it on an emulator so far and it did not respond to orientation changes though

andreyvital commented 8 years ago

Well, I fixed the issue #9 which is about viewFinderDrawLaser, so I'm going to look about handling the orientation changes now and then submit a PR for both.

/cc @andreaskeller

andreyvital commented 8 years ago

@MariusBozem

I tried to debug but we're out of luck. It seems that DisplayUtils.getScreenOrientation(context) always returns 1 which is Configuration.PORTRAIT. I also tried to get current device orientation instead of application orientation – but all methods I've tried returned 1.

I don't have sufficient knowledge to debug what's going on :(. Maybe it's something related to RN rather than the library itself. Do you have any ideas of what can we do to solve this?

I also think that my first thought about introducing a new property which would allows us to define the initial orientation falls through, as ZXingScannerView doesn't provide an API to change it explicitly neither allows to change mFramingRect — the library handles orientation internally.

:sob:

MariusBozem commented 8 years ago

First of all, thanks for looking into it this quickly. Unfortunately I have to work on other parts of the app for now so I can't look into it right now, but I'll try to do it once I have finished the other parts.

andreaskeller commented 8 years ago

©CentaurWarchief thank you for your help. I will look into the orientation change.

MariusBozem commented 8 years ago

@andreaskeller Do you have an update on the orientation issue? Unless I'm doing sth. wrong, it doesn't work with portrait mode because the scanner is rendered as though it was landscape mode.

ddzyndra commented 8 years ago

Did anybody solved this issue with orientation ?