-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix(android): prevent shutting down camera when re-mounting children #1995
Conversation
I think we should fix the root cause of this issue instead of some temporary hack |
Does this happen on Expo câmera module as well? I think we can use this hacky for now |
Didn't test it with Expo. However I've managed to run debugger and this is the code that fails:
but Ideas on why this happens? |
this is the same code of expo camera https://github.com/expo/expo/blob/eafa96e0d6/packages/expo-camera/android/src/main/java/expo/modules/camera/ExpoCameraView.java#L162 |
I think we can try to solve this using react native lifecycles onHostResume my guess is that onPause or onResume is not being called properly by react-native |
by adding this code to if (hasCameraPermissions()) {
start();
} Maybe your solution is the right solution 😕 |
Without this method overrriden the React injected UI (children) flash for a split of second and once the component mounts, the camera is put on top. So the solution is to remove and add views with 0 index, because that's supposedly how you can be sure about the view (camera) can be on the very bottom, and React UI is on still on top. Not sure why this happens, maybe because of how the camera screen lays out?
The camera instance is still present and I'm not experienced in Android dev (just did some basics years ago), so it's all new to me and I'm just trying to get my head around it 😅 |
react-native-linear-gradient avoids passing in children into the NativeView https://github.com/react-native-community/react-native-linear-gradient/blob/master/index.ios.js Other libraries from |
So, maybe we should follow this guidance? Should be possible to remove that hack from 2yrs ago altogether. |
@thymikee I agree. I would prefer an implementation like this one: https://github.com/react-native-community/react-native-linear-gradient/blob/master/index.android.js#L84 |
Gonna work on it over the weekend then! Thanks for helping out |
@thymikee Thank you for getting this finally fixed 🎉 |
I prefer to avoid absolute position why should we stop camera when changing children? |
@sibelius Do you know any project that implemented passing children to the native component directly (without the issues we are experiencing)? |
we can check on github https://github.com/search?l=Java&q=ViewGroupManager&type=Code maybe someone in the react native core could help us on this |
@n1ru4l addressed your feedback, so it still works well and we got rid of a hacky behavior on Android. |
The pull request will fix this, but for completeness sake, I want to point to #1862 (comment) which I believe is the reason why the issue exists when children are added inside the native view. |
@sibelius Do you want to investigate more or accept this solution? I am fine with this "workaround". |
I’m fine with this workaround, we can accept a native solution later on if someone fixes it |
🎉 This PR is included in version 1.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [1.7.0](react-native-camera/react-native-camera@v1.6.6...v1.7.0) (2019-01-08) ### Bug Fixes * **android:** prevent shutting down camera when re-mounting children ([#1995](react-native-camera/react-native-camera#1995)) ([5695f5d](react-native-camera/react-native-camera@5695f5d)) ### Features * **tidelift:** add tidelift badge on readme ([#2038](react-native-camera/react-native-camera#2038)) ([5768d30](react-native-camera/react-native-camera@5768d30))
Fixes #1311
There's a bug where re-mounting children without transparent background shuts down the camera on Android (adb on LG G2 shows that
stopPreview
fromQCamera2HWI
gets called, but I couldn't set up debugging to see what's calling it, help appreciated).By accident I've found a workaround, which involves wrapping children in a transparent view (not sure why
backgroundColor: 'transparent'
plays role here but it does).As a manual test I've added a previously buggy behavior to example app – pressing zoom in / zoom out will mount/unmount a
Text
node which is a direct child ofRNCamera
.