Upgrade Example to RN 0.64 (#83)

* ReactLogger: Also log function

* Run SwiftFormat & SwiftLint in example project

* Upgrade to RN 0.64 1/2

* Update lockfiles

* Upgrade a few packages

* index.tsx -> index.js

* Upgrade docusaurus

* Fix line length violation

* Update CameraView.swift

* Update gradle plugin

* Fix example to prefer higher res cameras

* Remove unused log line

* Update App.tsx
This commit is contained in:
Marc Rousavy
2021-03-19 15:53:19 +01:00
committed by GitHub
parent 1def7230c8
commit 35806ff660
30 changed files with 2160 additions and 2831 deletions

View File

@@ -0,0 +1,45 @@
import { useEffect, useMemo, useState } from 'react';
import { Camera, CameraDevice, sortDevices } from 'react-native-vision-camera';
/**
* A custom hook that's just like `useCameraDevices` from VisionCamera, but ignores `'telephoto-camera'` devices since those often have poor quality.
*/
export const useCameraDevice = (): {
front: CameraDevice | undefined;
back: CameraDevice | undefined;
} => {
const [backDevice, setBackDevice] = useState<CameraDevice>();
const [frontDevice, setFrontDevice] = useState<CameraDevice>();
useEffect(() => {
let isMounted = true;
const loadDevice = async (): Promise<void> => {
const devices = await Camera.getAvailableCameraDevices();
if (!isMounted) return;
// use any device
const filtered = devices.filter((d) => !d.devices.includes('telephoto-camera'));
const sorted = filtered.sort(sortDevices);
const back = sorted.find((d) => d.position === 'back');
const front = sorted.find((d) => d.position === 'front');
setBackDevice(back);
setFrontDevice(front);
console.log(`Devices: ${sorted.map((d) => d.name).join(', ')}`);
};
loadDevice();
return () => {
isMounted = false;
};
}, []);
return useMemo(
() => ({
back: backDevice,
front: frontDevice,
}),
[backDevice, frontDevice],
);
};