feat(ios): Make camera ready events to fire also on camera/device change to be consistent with Android. Fire unmount error when session or device fails to start. Update advanced example app to use camera ready event instead. (#2642)

This commit is contained in:
cristianoccazinsp 2019-12-13 14:51:50 -03:00 committed by Sibelius Seraphini
parent 0745fb90f0
commit 7abf3f78cb
3 changed files with 24 additions and 8 deletions

View File

@ -369,7 +369,7 @@ Note: This solve the flicker video recording issue for iOS
### `onCameraReady`
Function to be called when native code emit onCameraReady event, when camera is ready.
Function to be called when native code emit onCameraReady event, when camera is ready. This event will also fire when changing cameras (by `type` or `cameraId`).
### `onMountError`

View File

@ -300,7 +300,7 @@ class Camera extends Component{
if(s.cameraStatus == 'READY'){
let audioDisabled = s.recordAudioPermissionStatus == 'NOT_AUTHORIZED';
this.setState({cameraReady: true, audioDisabled: audioDisabled}, async () => {
this.setState({audioDisabled: audioDisabled}, async () => {
let ids = [];
@ -356,6 +356,18 @@ class Camera extends Component{
}
}
onCameraReady = () => {
if(!this.state.cameraReady){
this.setState({cameraReady: true});
}
}
onCameraMountError = () => {
setTimeout(()=>{
Alert.alert("Error", "Camera start failed.");
}, 150);
}
handleAppStateChange = (nextAppState) => {
}
@ -614,6 +626,8 @@ class Camera extends Component{
buttonNegative: 'Cancel',
}}
onStatusChange={this.onCameraStatusChange}
onCameraReady={this.onCameraReady}
onMountError={this.onCameraMountError}
pendingAuthorizationView={
<SafeAreaView style={styles.cameraLoading}>
<Spinner color={style.brandLight}/>
@ -898,11 +912,6 @@ class Camera extends Component{
else{
this.setState({cameraId: cameraId, ...defaultCameraOptions});
}
// disable and reenable camera on camera change
setTimeout(()=>{
this.setState({cameraReady: true});
}, 550);
});
});
}

View File

@ -1187,8 +1187,11 @@ BOOL _sessionInterrupted = NO;
#endif
dispatch_async(self.sessionQueue, ^{
// if session already running, also return.
// if session already running, also return and fire ready event
// this is helpfu when the device type or ID is changed and we must
// receive another ready event (like Android does)
if(self.session.isRunning){
[self onReady:nil];
return;
}
@ -1380,6 +1383,7 @@ BOOL _sessionInterrupted = NO;
// if the device we are setting is also invalid/nil, return
if(captureDevice == nil){
[self onMountingError:@{@"message": @"Invalid camera device."}];
return;
}
@ -1406,6 +1410,7 @@ BOOL _sessionInterrupted = NO;
if (error || captureDeviceInput == nil) {
RCTLog(@"%s: %@", __func__, error);
[self.session commitConfiguration];
[self onMountingError:@{@"message": @"Failed to setup capture device."}];
return;
}
@ -1454,6 +1459,8 @@ BOOL _sessionInterrupted = NO;
}
else{
RCTLog(@"The selected device does not work with the Preset [%@] or configuration provided", self.session.sessionPreset);
[self onMountingError:@{@"message": @"Camera device does not support selected settings."}];
}