Camera crashing on Android when state changes

Description:
I’m trying to implement the screen below. The red border should only show when the camera is recording, but this crashes the phone on Android.

I think the problem is that if state changes, the camera needs to re-render (i.e. this.state.isRecording changes to true). Meanwhile this.camera.recordAsync is being called and it crashes the phone since the camera ref also changes and so trying to start a recording on a camera that has been unmounted causes the device to crash.

I even tried to use the setState second param callback, but this doesn’t work either and the screen just goes black.

Re-produce:
Click record on the snack below on an Android device.

Snack:
See functions record1 and record2, and containerStyles inside the render function.

1 Like

Hi @darkwata - I think you may be correct about the root cause of the crash you’re seeing. However, you can rather easily work around this by putting everything you want to change in a separate absolutely-positioned View that is on top of your Camera instance. I was able to get your example working with just a few changes: camera - Snack see the changes in styles.recordingContainer and in render.

Hope this helps!

1 Like

@esamelson THAT worked wonders! Thank you. I tried doing this before but I stopped part way through thinking it wasn’t going to work. You convinced me it could work so I refactored things and it worked out, you the best!

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.