App not responding after using BarCodeScanner several times

Hello

I developing a programm using BarCodeScanner. Interface have two buttons and each calls its own interface with the camera. When i launch programm and start scan after 25-30 calls camera app not responding and crash. Try on android 5-7 versoin and the same result.

RN - 0.51
"expo": "^23.0.0",
"native-base": "^2.3.2",
"react": "16.0.0-alpha.12",
"react-native": "https://github.com/expo/react-native/archive/sdk-23.0.0.tar.gz",
"react-native-cancelable-fetch": "^0.1.1",
"react-native-linear-gradient": "^2.3.0",
"react-native-modal": "^4.0.0",
"react-native-modal-dropdown": "^0.5.0",
"react-native-pinch-zoom-view": "^0.1.2",
"react-native-popover": "^0.2.0",
"react-native-popup-menu": "^0.8.3",
"react-native-timer": "^1.3.1",
"react-navigation": "^1.0.0-beta.11",
"react-timer-mixin": "^0.13.3"

Screen from phone bug report

This looks like a bug in Expo.

@aalices Do you think you could look at this sometime in the future?

update:
Try to launch interface without scan. Just open, connect to BarCodeScaner and close. Every time after 25-30 launch freezes and not responding without bug report.
May be bug report - attempt to open two scaners and it is another problem

I am not sure if I get you right. Are you just leaving the app over 20 times - by clicking the home button or locking your screen?

Home interface with two buttons. I click on the any button and call interface with BarCodeScaner, scan qr or click back - return on home interface.
After several iterations app freezes and android tell me that app not respond.
It looks like BarCodeScaner cashed or async camera process is not destroyed.

When you “call the interface” are you using navigation or just rendering an additional component? Would be best if you provide a code snippet.

You can also try to use Camera component and pass it a onBarCodeRead prop.

Use navigation.

Code snippet to show camera with render:

(this.state.status==1) &&
<BarCodeScanner
barCodeTypes={[BarCodeScanner.Constants.BarCodeType.qr]}
torchMode="off"
ratio="1:1"
onBarCodeRead={this._handleBarCodeRead}
style={{width:win.width-20, height:win.width}}>
  <Image style={{width:win.width-60, height:win.width-60, marginTop:20, marginLeft:20}} source={require('../camera.png')} />
  <TouchableOpacity style={{top:-5, opacity:1}} transparent onPress={() => this.cameraflash() }>
    <Text style={{paddingLeft:10}}><Icon style={{color:"#fff", fontSize:40}} name='flash' /></Text>
  </TouchableOpacity>          
</BarCodeScanner>

and unmount component when leave interface

this.componentWillUnmount();
this.props.navigation.goBack();

+1

have the same problem trying to do similar thing:

there’s a section on my app that allows user to choose what kind of information to scan, depending on that the interface will be different. However, both pages simply call a scanner component which is similar to the expo snack provided with BarCodeScanner documentation.

I switch between those pages using RNRF tabs. and everytime I do (Home → scanner interface A (with Actions.jump) → home (with Actions.pop) → scanner interface B (with Actions.jump) the app will crash.

I even tried building apk with exp build:android and problem persists.

Any hints?

UPDATE:
traced this back to the fact that Scanner was never unmounted when its caller (interface A) was never unmounted before it is trying to be mounted once again by interface B. And as per documentation on expo Camera, this is normal behavior apparently…

UPDATE2:
Now I’m encountering same issue as this original post, when moving back n forth between scanner a and b app will freeze at some point depending on the phone performance, and once it freezes, app will always crash when opening scanner more than once although it has been unmounted (i checked that scanner’s componentwillunmount was called everytime i press back and remounted when i want to open interface b)
Just wanna know if this is a bug or something i neglected to do?
Thanks!:slight_smile:

Hello,
I have the same issue, using Expo 31.0.6.

  • While developing (inside Expo client): bar code scanner shows fine the first time, then every other time will take 10s to show.

  • In standalone app: bar code scanner will take longer and longer to show and then the app will crash on 4-5 attempt.

Same the other authors, the bar code scanner is on a separate screen inside my app and will get mounted/unmounted each time.

It’s really easy to repro, only two screens and a barcode scanner, but I can make a snack if needed.

Thanks!

I can confirm that switching to Camera fixes the problem.