Skip to content

Commit

Permalink
fix all types, delete old native camera
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Oct 29, 2024
1 parent 8033258 commit 340a6ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 82 deletions.
28 changes: 7 additions & 21 deletions package/src/Camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ import type { TakeSnapshotOptions } from './types/Snapshot'
import { SkiaCameraCanvas } from './skia/SkiaCameraCanvas'
import type { Frame } from './types/Frame'
import { FpsGraph, MAX_BARS } from './FpsGraph'
import type {
AverageFpsChangedEvent,
NativeCameraViewProps,
OnCodeScannedEvent,
OnErrorEvent,
OutputOrientationChangedEvent,
PreviewOrientationChangedEvent,
} from './NativeCameraView'
// import { NativeCameraView } from './NativeCameraView'
import CameraViewNativeComponent from './CameraViewNativeComponent'
import CameraViewNativeComponent, { type NativeProps } from './CameraViewNativeComponent'
import { RotationHelper } from './RotationHelper'

//#region Types
Expand All @@ -35,7 +26,7 @@ type NativeRecordVideoOptions = Omit<RecordVideoOptions, 'onRecordingError' | 'o
videoBitRateOverride?: number
videoBitRateMultiplier?: number
}
type RefType = React.Component<NativeCameraViewProps> & Readonly<NativeMethods>
type RefType = React.Component<NativeProps> & Readonly<NativeMethods>
interface CameraState {
isRecordingWithFlash: boolean
averageFpsSamples: number[]
Expand Down Expand Up @@ -95,17 +86,12 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
constructor(props: CameraProps) {
super(props)
this.onViewReady = this.onViewReady.bind(this)
this.onAverageFpsChanged = this.onAverageFpsChanged.bind(this)
this.onInitialized = this.onInitialized.bind(this)
this.onStarted = this.onStarted.bind(this)
this.onStopped = this.onStopped.bind(this)
this.onPreviewStarted = this.onPreviewStarted.bind(this)
this.onPreviewStopped = this.onPreviewStopped.bind(this)
this.onShutter = this.onShutter.bind(this)
this.onOutputOrientationChanged = this.onOutputOrientationChanged.bind(this)
this.onPreviewOrientationChanged = this.onPreviewOrientationChanged.bind(this)
this.onError = this.onError.bind(this)
this.onCodeScanned = this.onCodeScanned.bind(this)
this.ref = React.createRef<RefType>()
this.lastFrameProcessor = undefined
this.state = {
Expand Down Expand Up @@ -506,7 +492,7 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
//#endregion

//#region Events (Wrapped to maintain reference equality)
private onError(event: NativeSyntheticEvent<OnErrorEvent>): void {
private onError: NativeProps['onError'] = (event) => {
const error = event.nativeEvent
const cause = isErrorWithCause(error.cause) ? error.cause : undefined
// @ts-expect-error We're casting from unknown bridge types to TS unions, I expect it to hopefully work
Expand Down Expand Up @@ -544,13 +530,13 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
this.props.onShutter?.(event.nativeEvent)
}

private onOutputOrientationChanged({ nativeEvent: { outputOrientation } }: NativeSyntheticEvent<OutputOrientationChangedEvent>): void {
private onOutputOrientationChanged: NativeProps['onOutputOrientationChanged'] = ({ nativeEvent: { outputOrientation } }) => {
this.rotationHelper.outputOrientation = outputOrientation
this.props.onOutputOrientationChanged?.(outputOrientation)
this.maybeUpdateUIRotation()
}

private onPreviewOrientationChanged({ nativeEvent: { previewOrientation } }: NativeSyntheticEvent<PreviewOrientationChangedEvent>): void {
private onPreviewOrientationChanged: NativeProps['onPreviewOrientationChanged'] = ({ nativeEvent: { previewOrientation } }) => {
this.rotationHelper.previewOrientation = previewOrientation
this.props.onPreviewOrientationChanged?.(previewOrientation)
this.maybeUpdateUIRotation()
Expand All @@ -570,7 +556,7 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
}
//#endregion

private onCodeScanned(event: NativeSyntheticEvent<OnCodeScannedEvent>): void {
private onCodeScanned: NativeProps['onCodeScanned'] = (event) => {
const codeScanner = this.props.codeScanner
if (codeScanner == null) return

Expand All @@ -595,7 +581,7 @@ export class Camera extends React.PureComponent<CameraProps, CameraState> {
}
}

private onAverageFpsChanged({ nativeEvent: { averageFps } }: NativeSyntheticEvent<AverageFpsChangedEvent>): void {
private onAverageFpsChanged: NativeProps['onAverageFpsChanged'] = ({ nativeEvent: { averageFps } }) => {
this.setState((state) => {
const averageFpsSamples = [...state.averageFpsSamples, averageFps]
while (averageFpsSamples.length >= MAX_BARS + 1) {
Expand Down
61 changes: 0 additions & 61 deletions package/src/NativeCameraView.ts

This file was deleted.

0 comments on commit 340a6ed

Please sign in to comment.