fix(android): prevent shutting down camera when re-mounting children (#1995)

* fix(android): prevent shutting down camera when re-mounting children

* fix: render children outside of native component
This commit is contained in:
Michał Pierzchała 2019-01-08 11:48:54 +01:00 committed by Sibelius Seraphini
parent c7336b2ff4
commit 5695f5d066
3 changed files with 26 additions and 24 deletions

View File

@ -214,15 +214,6 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
// React handles this for us, so we don't need to call super.requestLayout();
}
@Override
public void onViewAdded(View child) {
if (this.getView() == child || this.getView() == null) return;
// remove and read view to make sure it is in the back.
// @TODO figure out why there was a z order issue in the first place and fix accordingly.
this.removeView(this.getView());
this.addView(this.getView(), 0);
}
public void setBarCodeTypes(List<String> barCodeTypes) {
mBarCodeTypes = barCodeTypes;
initBarcodeReader();

View File

@ -182,6 +182,9 @@ export default class CameraScreen extends React.Component {
)}
</TouchableOpacity>
</View>
{this.state.zoom !== 0 && (
<Text style={[styles.flipText, styles.zoomText]}>Zoom: {this.state.zoom}</Text>
)}
<View
style={{
flex: 0.1,
@ -247,6 +250,12 @@ const styles = StyleSheet.create({
color: 'white',
fontSize: 15,
},
zoomText: {
position: 'absolute',
bottom: 70,
zIndex: 2,
left: 2,
},
picButton: {
backgroundColor: 'darkseagreen',
},

View File

@ -447,25 +447,27 @@ export default class Camera extends React.Component<PropsType, StateType> {
};
render() {
const nativeProps = this._convertNativeProps(this.props);
const { style, ...nativeProps } = this._convertNativeProps(this.props);
if (this.state.isAuthorized || this.hasFaCC()) {
return (
<RNCamera
{...nativeProps}
ref={this._setReference}
onMountError={this._onMountError}
onCameraReady={this._onCameraReady}
onGoogleVisionBarcodesDetected={this._onObjectDetected(
this.props.onGoogleVisionBarcodesDetected,
)}
onBarCodeRead={this._onObjectDetected(this.props.onBarCodeRead)}
onFacesDetected={this._onObjectDetected(this.props.onFacesDetected)}
onTextRecognized={this._onObjectDetected(this.props.onTextRecognized)}
onPictureSaved={this._onPictureSaved}
>
<View style={style}>
<RNCamera
{...nativeProps}
style={StyleSheet.absoluteFill}
ref={this._setReference}
onMountError={this._onMountError}
onCameraReady={this._onCameraReady}
onGoogleVisionBarcodesDetected={this._onObjectDetected(
this.props.onGoogleVisionBarcodesDetected,
)}
onBarCodeRead={this._onObjectDetected(this.props.onBarCodeRead)}
onFacesDetected={this._onObjectDetected(this.props.onFacesDetected)}
onTextRecognized={this._onObjectDetected(this.props.onTextRecognized)}
onPictureSaved={this._onPictureSaved}
/>
{this.renderChildren()}
</RNCamera>
</View>
);
} else if (!this.state.isAuthorizationChecked) {
return this.props.pendingAuthorizationView;