fix: Fix circular dependency in FrameProcessorPlugins.ts

shoutout @bglgwyng
This commit is contained in:
Marc Rousavy 2023-08-24 10:55:57 +02:00
parent 4b009a0053
commit c88605e230
2 changed files with 8 additions and 12 deletions

View File

@ -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<CameraProps> {
//#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.

View File

@ -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<string, BasicParameterType | undefined>;
@ -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(