From c88605e23008f81e3c4ce13c399d7c19c0f54e1f Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Thu, 24 Aug 2023 10:55:57 +0200 Subject: [PATCH] fix: Fix circular dependency in `FrameProcessorPlugins.ts` shoutout @bglgwyng --- src/Camera.tsx | 10 ---------- src/FrameProcessorPlugins.ts | 10 ++++++++-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/Camera.tsx b/src/Camera.tsx index 061d77a..90fcea8 100644 --- a/src/Camera.tsx +++ b/src/Camera.tsx @@ -4,7 +4,6 @@ import type { CameraDevice } from './CameraDevice'; import type { ErrorWithCause } from './CameraError'; import { CameraCaptureError, CameraRuntimeError, tryParseNativeCameraError, isErrorWithCause } from './CameraError'; import type { CameraProps, FrameProcessor } from './CameraProps'; -import { assertJSIAvailable } from './JSIHelper'; import { CameraModule } from './NativeCameraModule'; import type { PhotoFile, TakePhotoOptions } from './PhotoFile'; import type { Point } from './Point'; @@ -259,15 +258,6 @@ export class Camera extends React.PureComponent { //#endregion //#region Static Functions (NativeModule) - /** - * Install JSI Bindings for Frame Processors - */ - public static installFrameProcessorBindings(): void { - assertJSIAvailable(); - const result = CameraModule.installFrameProcessorBindings() as unknown; - if (result !== true) - throw new CameraRuntimeError('system/frame-processors-unavailable', 'Failed to install Frame Processor JSI bindings!'); - } /** * Get a list of all available camera devices on the current phone. diff --git a/src/FrameProcessorPlugins.ts b/src/FrameProcessorPlugins.ts index 29e5352..3b786ed 100644 --- a/src/FrameProcessorPlugins.ts +++ b/src/FrameProcessorPlugins.ts @@ -1,10 +1,11 @@ import type { Frame, FrameInternal } from './Frame'; import type { FrameProcessor } from './CameraProps'; -import { Camera } from './Camera'; import { CameraRuntimeError } from './CameraError'; // only import typescript types import type TWorklets from 'react-native-worklets-core'; +import { CameraModule } from './NativeCameraModule'; +import { assertJSIAvailable } from './JSIHelper'; type BasicParameterType = string | number | boolean | undefined; type ParameterType = BasicParameterType | BasicParameterType[] | Record; @@ -39,11 +40,16 @@ let runOnAsyncContext = (_frame: Frame, _func: () => void): void => { }; try { + assertJSIAvailable(); + // eslint-disable-next-line @typescript-eslint/no-var-requires const { Worklets } = require('react-native-worklets-core') as typeof TWorklets; // Install native Frame Processor Runtime Manager - Camera.installFrameProcessorBindings(); + const result = CameraModule.installFrameProcessorBindings() as unknown; + if (result !== true) + throw new CameraRuntimeError('system/frame-processors-unavailable', 'Failed to install Frame Processor JSI bindings!'); + // @ts-expect-error global is untyped, it's a C++ host-object if (global.VisionCameraProxy == null) { throw new CameraRuntimeError(