perf: clean up delay code

This commit is contained in:
Marc Rousavy 2021-06-28 20:50:35 +02:00
parent da84a0fd42
commit f1a93664ae

View File

@ -10,9 +10,6 @@ import type { Point } from './Point';
import type { TakeSnapshotOptions } from './Snapshot';
import type { RecordVideoOptions, VideoFile } from './VideoFile';
// a custom delay to wait for after `componentDidMount` because view initialization takes longer on Android.
const NATIVE_VIEW_INIT_DELAY = Platform.OS === 'android' ? 300 : 0;
//#region Types
export type CameraPermissionStatus = 'authorized' | 'not-determined' | 'denied' | 'restricted';
export type CameraPermissionRequestResult = 'authorized' | 'denied';
@ -366,11 +363,16 @@ export class Camera extends React.PureComponent<CameraProps> {
* @internal
*/
componentDidMount(): void {
const frameProcessor = this.props.frameProcessor;
if (frameProcessor != null) {
if (this.props.frameProcessor != null) {
if (Platform.OS === 'android') {
// on Android the View is not fully mounted yet (`findViewById` returns null), so we wait 300ms.
setTimeout(() => {
this.setFrameProcessor(frameProcessor);
}, NATIVE_VIEW_INIT_DELAY);
if (this.props.frameProcessor != null) this.setFrameProcessor(this.props.frameProcessor);
}, 300);
} else {
// on other platforms (iOS) the View we can assume that the View is immediatelly available.
this.setFrameProcessor(this.props.frameProcessor);
}
}
}