From b9d51cd6b4b7166528720843828fc1be33b923b9 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Thu, 6 May 2021 16:48:02 +0200 Subject: [PATCH] fix: Simplify `cameraId` deriving --- src/Camera.tsx | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) diff --git a/src/Camera.tsx b/src/Camera.tsx index 3e8221d..1db4d15 100644 --- a/src/Camera.tsx +++ b/src/Camera.tsx @@ -32,13 +32,6 @@ type RefType = React.Component & Readonly; const CameraModule = NativeModules.CameraView; if (CameraModule == null) console.error("Camera: Native Module 'CameraView' was null! Did you run pod install?"); -interface CameraState { - /** - * The actual native ID for the camera device. - */ - cameraId?: string; -} - //#region Camera Component /** * ### A powerful `` component. @@ -69,7 +62,7 @@ interface CameraState { * * @component */ -export class Camera extends React.PureComponent { +export class Camera extends React.PureComponent { /** * @internal */ @@ -87,7 +80,6 @@ export class Camera extends React.PureComponent { */ constructor(props: CameraProps) { super(props); - this.state = { cameraId: undefined }; this.onInitialized = this.onInitialized.bind(this); this.onError = this.onError.bind(this); this.ref = React.createRef(); @@ -338,16 +330,6 @@ export class Camera extends React.PureComponent { } //#endregion - /** - * @internal - */ - static getDerivedStateFromProps(props: CameraProps, state: CameraState): CameraState | null { - const newCameraId = props.device.id; - if (state.cameraId !== newCameraId) return { ...state, cameraId: newCameraId }; - - return null; - } - /** * @internal */ @@ -394,19 +376,9 @@ export class Camera extends React.PureComponent { * @internal */ public render(): React.ReactNode { - if (this.state.cameraId == null) throw new Error('CameraID is null! Did you pass a valid `device`?'); // We remove the big `device` object from the props because we only need to pass `cameraId` to native. - const { device: _, frameProcessor: __, ...props } = this.props; - - return ( - - ); + const { device, frameProcessor: _, ...props } = this.props; + return ; } } //#endregion