From 82069f3bef8bf8bc014e56f044f25e567a3501e5 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 31 Jan 2024 18:40:12 -0700 Subject: [PATCH 1/6] Use react-native-vision-camera submodule --- .editorconfig | 9 +++++++++ .gitmodules | 3 +++ package.json | 1 - react-native-vision-camera | 1 + tsconfig.json | 8 +++++++- yarn.lock | 5 ----- 6 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitmodules create mode 160000 react-native-vision-camera diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c4bd5fb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*.json] +end_of_line = lf +charset = utf-8 +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c48e222 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "react-native-vision-camera"] + path = react-native-vision-camera + url = ssh://gitea@dev.railbird.ai:1123/railbird/react-native-vision-camera.git diff --git a/package.json b/package.json index 9c75b19..833af09 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,6 @@ "react-native-static-safe-area-insets": "^2.2.0", "react-native-svg": "13.9.0", "react-native-svg-charts": "^5.4.0", - "react-native-vision-camera": "^3.8.2", "typescript": "^5.3.3" }, "devDependencies": { diff --git a/react-native-vision-camera b/react-native-vision-camera new file mode 160000 index 0000000..fb42545 --- /dev/null +++ b/react-native-vision-camera @@ -0,0 +1 @@ +Subproject commit fb425458904eb240466768be08352973fd2f78d8 diff --git a/tsconfig.json b/tsconfig.json index 0e6371f..d423055 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,4 +1,10 @@ { - "compilerOptions": {}, + "compilerOptions": { + "paths": { + "react-native-vision-camera": [ + "./react-native-vision-camera/package/src/index" + ] + } + }, "extends": "expo/tsconfig.base" } diff --git a/yarn.lock b/yarn.lock index a31f8e8..8d54cfb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8417,11 +8417,6 @@ react-native-svg@^6.2.1: lodash "^4.16.6" pegjs "^0.10.0" -react-native-vision-camera@^3.8.2: - version "3.8.2" - resolved "https://registry.yarnpkg.com/react-native-vision-camera/-/react-native-vision-camera-3.8.2.tgz#f4f75f84c6a19e1c3474ddc0f7f785b5a526739b" - integrity sha512-MY39l2e3hNRPUefn2JPShOFExcw0PblbAcUGvJrIfS9pMzdIyceo0umRAx8lOGXzDUAdb+xy/tFWb8zGxKimCQ== - react-native@*: version "0.73.2" resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.73.2.tgz#74ee163c8189660d41d1da6560411da7ce41a608" From 85b1cb8759892b22d2c74c0c504e292466167fb1 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Wed, 31 Jan 2024 22:45:00 -0700 Subject: [PATCH 2/6] Close --- android/settings.gradle | 5 ++ app.json | 4 +- babel.config.js | 48 +++++++---- component/video/camera.tsx | 113 +++++++++++++++---------- flake.nix | 112 ++++++++++++------------ ios/Railbird.xcodeproj/project.pbxproj | 4 +- metro.config.js | 56 ++++++++++-- package.json | 6 +- tsconfig.json | 24 +++++- yarn.lock | 55 ++++++++++++ 10 files changed, 301 insertions(+), 126 deletions(-) diff --git a/android/settings.gradle b/android/settings.gradle index 2998473..a002532 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,10 +1,15 @@ rootProject.name = 'Railbird' apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute(null, rootDir).text.trim(), "../scripts/autolinking.gradle"); + useExpoModules() apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle"); + applyNativeModulesSettingsGradle(settings) include ':app' includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json')"].execute(null, rootDir).text.trim()).getParentFile()) + +include ':react-native-vision-camera' +project(':react-native-vision-camera').projectDir = new File(rootProject.projectDir, '../react-native-vision-camera/package/android') diff --git a/app.json b/app.json index e9a87f7..7766581 100644 --- a/app.json +++ b/app.json @@ -11,9 +11,7 @@ "resizeMode": "contain", "backgroundColor": "#ffffff" }, - "assetBundlePatterns": [ - "**/*" - ], + "assetBundlePatterns": ["**/*"], "plugins": [ "@react-native-firebase/app", "@react-native-firebase/auth", diff --git a/babel.config.js b/babel.config.js index cf6bd4c..2f02724 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,16 +1,34 @@ -module.exports = function(api) { - api.cache(true); - return { - presets: ["babel-preset-expo"], - plugins: [ - ["module:react-native-dotenv", { - "moduleName": "@env", - "path": ".env", - "safe": false, - "allowUndefined": true, - "verbose": false, - }], - 'react-native-reanimated/plugin', - ], - }; +const path = require("path"); +const pak = require("./react-native-vision-camera/package/package.json"); + +module.exports = function (api) { + api.cache(true); + return { + presets: ["babel-preset-expo"], + plugins: [ + [ + "module:react-native-dotenv", + { + moduleName: "@env", + path: ".env", + safe: false, + allowUndefined: true, + verbose: false, + }, + ], + "react-native-reanimated/plugin", + [ + "module-resolver", + { + alias: { + [pak.name]: path.join( + __dirname, + "./react-native-vision-camera/package", + pak.source, + ), + }, + }, + ], + ], + }; }; diff --git a/component/video/camera.tsx b/component/video/camera.tsx index ce1abf1..45f10a2 100644 --- a/component/video/camera.tsx +++ b/component/video/camera.tsx @@ -1,57 +1,68 @@ -import React, { useCallback, useRef, useState } from 'react' -import { Button, StyleSheet, Text, View } from 'react-native' -import { Camera, useCameraPermission, useCameraDevice, useCameraFormat, PhotoFile, VideoFile, CameraRuntimeError, Orientation } from 'react-native-vision-camera' -import { RecordingButton } from './capture-button' -import { useIsForeground } from './is-foreground' +import React, { useCallback, useRef, useState } from "react"; +import { Button, StyleSheet, Text, View } from "react-native"; +import { + Camera, + useCameraPermission, + useCameraDevice, + useCameraFormat, + PhotoFile, + VideoFile, + CameraRuntimeError, + Orientation, +} from "react-native-vision-camera"; +import { RecordingButton } from "./capture-button"; +import { useIsForeground } from "./is-foreground"; export default function CameraScreen(): React.ReactElement { - const camera = useRef(null) - const { hasPermission, requestPermission } = useCameraPermission() - const [isCameraInitialized, setIsCameraInitialized] = useState(false) + const camera = useRef(null); + const { hasPermission, requestPermission } = useCameraPermission(); + const [isCameraInitialized, setIsCameraInitialized] = + useState(false); - const isForeground: boolean = useIsForeground() - const isActive: boolean = isForeground // Should be combined with isFocused hook + const isForeground: boolean = useIsForeground(); + const isActive: boolean = isForeground; // Should be combined with isFocused hook const onError = useCallback((error: CameraRuntimeError) => { - console.error(error) - }, []) + console.error(error); + }, []); const onInitialized = useCallback(() => { - console.log('Camera initialized!') - setIsCameraInitialized(true) - }, []) + console.log("Camera initialized!"); + setIsCameraInitialized(true); + }, []); - const onMediaCaptured = useCallback( - (media: PhotoFile | VideoFile) => { - console.log(`Media captured! ${JSON.stringify(media)}`) - }, - [], - ) + const onMediaCaptured = useCallback((media: PhotoFile | VideoFile) => { + console.log(`Media captured! ${JSON.stringify(media)}`); + }, []); if (!hasPermission) { - requestPermission() + requestPermission(); // Error handling in case they refuse to give permission } - const device = useCameraDevice('back') + const device = useCameraDevice("back"); const format = useCameraFormat(device, [ { videoResolution: { width: 3048, height: 2160 } }, - { fps: 60 } - ]) // this sets as a target + { fps: 60 }, + ]); // this sets as a target //Orientation detection - const [orientation, setOrientation] = useState('portrait'); + const [orientation, setOrientation] = useState("portrait"); const toggleOrientation = () => { - setOrientation(currentOrientation => - currentOrientation === 'landscape-left' ? 'portrait' : 'landscape-left' // Can adjust this and the type to match what we want + setOrientation( + (currentOrientation) => + currentOrientation === "landscape-left" ? "portrait" : "landscape-left", // Can adjust this and the type to match what we want ); }; if (device === null) { - return Camera not available. Does user have permissions: {hasPermission} + return ( + + Camera not available. Does user have permissions: {hasPermission} + + ); } - return ( hasPermission && ( @@ -67,12 +78,22 @@ export default function CameraScreen(): React.ReactElement { isActive={isActive} /> - +