chore: Remove semicolons (#1846)
* chore: Disable `semi` in Prettier * chore: Format w/o semi * Remove more `;` * Lint example * More ;
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { useMemo } from 'react';
|
||||
import { CameraDevice, CameraPosition } from '../CameraDevice';
|
||||
import { getCameraDevice, DeviceFilter } from '../devices/getCameraDevice';
|
||||
import { useCameraDevices } from './useCameraDevices';
|
||||
import { useMemo } from 'react'
|
||||
import { CameraDevice, CameraPosition } from '../CameraDevice'
|
||||
import { getCameraDevice, DeviceFilter } from '../devices/getCameraDevice'
|
||||
import { useCameraDevices } from './useCameraDevices'
|
||||
|
||||
/**
|
||||
* Get the best matching Camera device that best satisfies your requirements using a sorting filter.
|
||||
@@ -16,13 +16,13 @@ import { useCameraDevices } from './useCameraDevices';
|
||||
* ```
|
||||
*/
|
||||
export function useCameraDevice(position: CameraPosition, filter?: DeviceFilter): CameraDevice | undefined {
|
||||
const devices = useCameraDevices();
|
||||
const devices = useCameraDevices()
|
||||
|
||||
const device = useMemo(
|
||||
() => getCameraDevice(devices, position, filter),
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[devices, position, JSON.stringify(filter)],
|
||||
);
|
||||
)
|
||||
|
||||
return device;
|
||||
return device
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import type { CameraDevice } from '../CameraDevice';
|
||||
import { CameraDevices } from '../CameraDevices';
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { CameraDevice } from '../CameraDevice'
|
||||
import { CameraDevices } from '../CameraDevices'
|
||||
|
||||
/**
|
||||
* Get all available Camera Devices this phone has.
|
||||
@@ -10,14 +10,14 @@ import { CameraDevices } from '../CameraDevices';
|
||||
* so the result of this function might update over time.
|
||||
*/
|
||||
export function useCameraDevices(): CameraDevice[] {
|
||||
const [devices, setDevices] = useState(() => CameraDevices.getAvailableCameraDevices());
|
||||
const [devices, setDevices] = useState(() => CameraDevices.getAvailableCameraDevices())
|
||||
|
||||
useEffect(() => {
|
||||
const listener = CameraDevices.addCameraDevicesChangedListener((newDevices) => {
|
||||
setDevices(newDevices);
|
||||
});
|
||||
return () => listener.remove();
|
||||
}, []);
|
||||
setDevices(newDevices)
|
||||
})
|
||||
return () => listener.remove()
|
||||
}, [])
|
||||
|
||||
return devices;
|
||||
return devices
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
import { CameraDevice, CameraDeviceFormat } from '../CameraDevice';
|
||||
import { FormatFilter, getCameraFormat } from '../devices/getCameraFormat';
|
||||
import { useMemo } from 'react'
|
||||
import { CameraDevice, CameraDeviceFormat } from '../CameraDevice'
|
||||
import { FormatFilter, getCameraFormat } from '../devices/getCameraFormat'
|
||||
|
||||
/**
|
||||
* Get the best matching Camera format for the given device that satisfies your requirements using a sorting filter. By default, formats are sorted by highest to lowest resolution.
|
||||
@@ -22,10 +22,10 @@ import { FormatFilter, getCameraFormat } from '../devices/getCameraFormat';
|
||||
*/
|
||||
export function useCameraFormat(device: CameraDevice | undefined, filters: FormatFilter[]): CameraDeviceFormat | undefined {
|
||||
const format = useMemo(() => {
|
||||
if (device == null) return undefined;
|
||||
return getCameraFormat(device, filters);
|
||||
if (device == null) return undefined
|
||||
return getCameraFormat(device, filters)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [device, JSON.stringify(filters)]);
|
||||
}, [device, JSON.stringify(filters)])
|
||||
|
||||
return format;
|
||||
return format
|
||||
}
|
||||
|
@@ -1,17 +1,17 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Camera } from '../Camera';
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { Camera } from '../Camera'
|
||||
|
||||
interface PermissionState {
|
||||
/**
|
||||
* Whether the specified permission has explicitly been granted.
|
||||
* By default, this will be `false`. To request permission, call `requestPermission()`.
|
||||
*/
|
||||
hasPermission: boolean;
|
||||
hasPermission: boolean
|
||||
/**
|
||||
* Requests the specified permission from the user.
|
||||
* @returns Whether the specified permission has now been granted, or not.
|
||||
*/
|
||||
requestPermission: () => Promise<boolean>;
|
||||
requestPermission: () => Promise<boolean>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,23 +31,23 @@ interface PermissionState {
|
||||
* ```
|
||||
*/
|
||||
export function useCameraPermission(): PermissionState {
|
||||
const [hasPermission, setHasPermission] = useState(false);
|
||||
const [hasPermission, setHasPermission] = useState(false)
|
||||
|
||||
const requestPermission = useCallback(async () => {
|
||||
const result = await Camera.requestCameraPermission();
|
||||
const hasPermissionNow = result === 'granted';
|
||||
setHasPermission(hasPermissionNow);
|
||||
return hasPermissionNow;
|
||||
}, []);
|
||||
const result = await Camera.requestCameraPermission()
|
||||
const hasPermissionNow = result === 'granted'
|
||||
setHasPermission(hasPermissionNow)
|
||||
return hasPermissionNow
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
Camera.getCameraPermissionStatus().then((s) => setHasPermission(s === 'granted'));
|
||||
}, []);
|
||||
Camera.getCameraPermissionStatus().then((s) => setHasPermission(s === 'granted'))
|
||||
}, [])
|
||||
|
||||
return {
|
||||
hasPermission,
|
||||
requestPermission,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,21 +65,21 @@ export function useCameraPermission(): PermissionState {
|
||||
* ```
|
||||
*/
|
||||
export function useMicrophonePermission(): PermissionState {
|
||||
const [hasPermission, setHasPermission] = useState(false);
|
||||
const [hasPermission, setHasPermission] = useState(false)
|
||||
|
||||
const requestPermission = useCallback(async () => {
|
||||
const result = await Camera.requestMicrophonePermission();
|
||||
const hasPermissionNow = result === 'granted';
|
||||
setHasPermission(hasPermissionNow);
|
||||
return hasPermissionNow;
|
||||
}, []);
|
||||
const result = await Camera.requestMicrophonePermission()
|
||||
const hasPermissionNow = result === 'granted'
|
||||
setHasPermission(hasPermissionNow)
|
||||
return hasPermissionNow
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
Camera.getMicrophonePermissionStatus().then((s) => setHasPermission(s === 'granted'));
|
||||
}, []);
|
||||
Camera.getMicrophonePermissionStatus().then((s) => setHasPermission(s === 'granted'))
|
||||
}, [])
|
||||
|
||||
return {
|
||||
hasPermission,
|
||||
requestPermission,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { DependencyList, useMemo } from 'react';
|
||||
import type { Frame, FrameInternal } from '../Frame';
|
||||
import { FrameProcessor } from '../CameraProps';
|
||||
import { DependencyList, useMemo } from 'react'
|
||||
import type { Frame, FrameInternal } from '../Frame'
|
||||
import { FrameProcessor } from '../CameraProps'
|
||||
|
||||
/**
|
||||
* Create a new Frame Processor function which you can pass to the `<Camera>`.
|
||||
@@ -13,19 +13,20 @@ import { FrameProcessor } from '../CameraProps';
|
||||
export function createFrameProcessor(frameProcessor: FrameProcessor['frameProcessor'], type: FrameProcessor['type']): FrameProcessor {
|
||||
return {
|
||||
frameProcessor: (frame: Frame) => {
|
||||
'worklet';
|
||||
'worklet'
|
||||
// Increment ref-count by one
|
||||
(frame as FrameInternal).incrementRefCount();
|
||||
const internal = frame as FrameInternal
|
||||
internal.incrementRefCount()
|
||||
try {
|
||||
// Call sync frame processor
|
||||
frameProcessor(frame);
|
||||
frameProcessor(frame)
|
||||
} finally {
|
||||
// Potentially delete Frame if we were the last ref (no runAsync)
|
||||
(frame as FrameInternal).decrementRefCount();
|
||||
internal.decrementRefCount()
|
||||
}
|
||||
},
|
||||
type: type,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,5 +49,5 @@ export function createFrameProcessor(frameProcessor: FrameProcessor['frameProces
|
||||
*/
|
||||
export function useFrameProcessor(frameProcessor: (frame: Frame) => void, dependencies: DependencyList): FrameProcessor {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
return useMemo(() => createFrameProcessor(frameProcessor, 'frame-processor'), dependencies);
|
||||
return useMemo(() => createFrameProcessor(frameProcessor, 'frame-processor'), dependencies)
|
||||
}
|
||||
|
Reference in New Issue
Block a user