From 2fa0f8fd46a8ad993a3ff9e4ecde68c5969c1865 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 6 Jul 2021 16:42:58 +0200 Subject: [PATCH] chore: Clean up root directory (#236) * Clean up root * remove unused REA patches * Remove `cpp/` and create headers per platform * fix `#import` * fix `VISION_CAMERA_DISABLE_FRAME_PROCESSORS` --- .prettierrc.js | 10 --- android/CMakeLists.txt | 1 - android/src/main/cpp/MakeJSIRuntime.h | 30 +++++++++ babel.config.js | 3 - cpp/MakeJSIRuntime.h | 64 ------------------- cpp/README.md | 26 -------- cpp/SpeedChecker.h | 20 ------ docs/docusaurus.config.js | 2 +- .../react-native-reanimated+2.2.0.patch | 20 ------ .../FrameProcessorRuntimeManager.mm | 14 ++-- ios/React Utils/MakeJSIRuntime.h | 42 ++++++++++++ ios/VisionCamera.xcodeproj/project.pbxproj | 15 +---- package.json | 18 ++++-- patches/react-native-reanimated+2.2.0.patch | 20 ------ tsconfig.docs.json | 5 -- tsconfig.json | 1 - 16 files changed, 94 insertions(+), 197 deletions(-) delete mode 100644 .prettierrc.js create mode 100644 android/src/main/cpp/MakeJSIRuntime.h delete mode 100644 babel.config.js delete mode 100644 cpp/MakeJSIRuntime.h delete mode 100644 cpp/README.md delete mode 100644 cpp/SpeedChecker.h delete mode 100644 example/patches/react-native-reanimated+2.2.0.patch create mode 100644 ios/React Utils/MakeJSIRuntime.h delete mode 100644 patches/react-native-reanimated+2.2.0.patch delete mode 100644 tsconfig.docs.json diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 012b8bf..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - bracketSpacing: true, - jsxBracketSameLine: true, - singleQuote: true, - trailingComma: 'all', - semi: true, - tabWidth: 2, - useTabs: false, - printWidth: 140 -}; diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index d467204..ba887fd 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -49,7 +49,6 @@ target_include_directories( "${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/headers/Registries" "${NODE_MODULES_DIR}/react-native-reanimated/Common/cpp/hidden_headers" "src/main/cpp" - "../cpp" ) # find libraries diff --git a/android/src/main/cpp/MakeJSIRuntime.h b/android/src/main/cpp/MakeJSIRuntime.h new file mode 100644 index 0000000..fcd3d40 --- /dev/null +++ b/android/src/main/cpp/MakeJSIRuntime.h @@ -0,0 +1,30 @@ +// +// Created by Marc Rousavy on 06.07.21. +// + +#pragma once + +#include +#include + +#if FOR_HERMES + // Hermes + #include +#else + // JSC + #include +#endif + +using namespace facebook; + +namespace vision { + +static std::unique_ptr makeJSIRuntime() { + #if FOR_HERMES + return facebook::hermes::makeHermesRuntime(); + #else + return facebook::jsc::makeJSCRuntime(); + #endif +} + +} // namespace vision diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index f842b77..0000000 --- a/babel.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - presets: ['module:metro-react-native-babel-preset'], -}; diff --git a/cpp/MakeJSIRuntime.h b/cpp/MakeJSIRuntime.h deleted file mode 100644 index 1a392f2..0000000 --- a/cpp/MakeJSIRuntime.h +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include - -#ifdef ON_ANDROID - -// on Android we need to pass FOR_HERMES flag to determine if hermes is used or not since both headers are there. - -#if FOR_HERMES -// Hermes -#include -#else -// JSC -#include -#endif - -#else - -// on iOS, we simply check by __has_include. Headers are only available if the sources are there too. - -#if __has_include() -// Hermes (https://hermesengine.dev) (RN 0.65+) -#include -#elif __has_include() -// Hermes (https://hermesengine.dev) -#include -#elif __has_include() -// V8 (https://github.com/Kudo/react-native-v8) -#include -#else -// JSC -#include -#endif - -#endif - -using namespace facebook; - -namespace vision { - -static std::unique_ptr makeJSIRuntime() { -#ifdef ON_ANDROID - - #if FOR_HERMES - return facebook::hermes::makeHermesRuntime(); - #else - return facebook::jsc::makeJSCRuntime(); - #endif - -#else - - #if __has_include() || __has_include() - return facebook::hermes::makeHermesRuntime(); - #elif __has_include() - return facebook::createV8Runtime(""); - #else - return facebook::jsc::makeJSCRuntime(); - #endif - -#endif -} - -} // namespace vision diff --git a/cpp/README.md b/cpp/README.md deleted file mode 100644 index 8d32c6e..0000000 --- a/cpp/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# cpp - -This folder contains the Shared C++ code for react-native-vision-camera. - -## Prerequesites - -1. For Android, download the [NDK and build tools](https://developer.android.com/studio/projects/add-native-code#download-ndk) -2. For iOS, Xcode will be enough. -3. Install cpplint - ```sh - brew install cpplint - ``` - -## Getting Started - -It is recommended that you work on the code using the Example project (`example/android/` or `example/ios/VisionCameraExample.xcworkspace`), since that always includes the React Native header files, plus you can easily test changes that way. - -You can however still edit the library project here by opening this folder with any C++ editor. - -## Committing - -Before committing, make sure that you're not violating the cpplint codestyles. To do that, run the following command: - -```bash -yarn check-cpp -``` diff --git a/cpp/SpeedChecker.h b/cpp/SpeedChecker.h deleted file mode 100644 index 816d2ae..0000000 --- a/cpp/SpeedChecker.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "Logger.h" -#include - -namespace vision { - -class SpeedChecker { - public: - static void checkSpeed(std::string tag, std::function fun) { - auto start = std::chrono::system_clock::now(); - fun(); - auto end = std::chrono::system_clock::now(); - std::chrono::duration elapsed_seconds = end-start; - tag += " " + std::to_string(elapsed_seconds.count()) + "s"; - Logger::log(tag.c_str()); - } -}; - -} // namespace vision diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index cb72812..34c796f 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -118,7 +118,7 @@ module.exports = { name: 'VisionCamera', entryPoints: ['../src'], exclude: "../src/index.ts", - tsconfig: '../tsconfig.docs.json', + tsconfig: '../tsconfig.build.json', excludePrivate: true, excludeProtected: true, excludeExternals: true, diff --git a/example/patches/react-native-reanimated+2.2.0.patch b/example/patches/react-native-reanimated+2.2.0.patch deleted file mode 100644 index 55f0e67..0000000 --- a/example/patches/react-native-reanimated+2.2.0.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/node_modules/react-native-reanimated/android/build.gradle b/node_modules/react-native-reanimated/android/build.gradle -index bb707e7..9186873 100644 ---- a/node_modules/react-native-reanimated/android/build.gradle -+++ b/node_modules/react-native-reanimated/android/build.gradle -@@ -7,8 +7,12 @@ def reactNativeVersion = json.version as String - def (major, minor, patch) = reactNativeVersion.tokenize('.') - - def engine = "jsc" --if (project(':app').ext.react.enableHermes) { -- engine = "hermes" --} -+rootProject.getSubprojects().forEach({project -> -+ if (project.plugins.hasPlugin("com.android.application")) { -+ if(project.ext.react.enableHermes) { -+ engine = "hermes" -+ } -+ } -+ }) - - artifacts.add("default", file("react-native-reanimated-${minor}-${engine}.aar")) diff --git a/ios/Frame Processor/FrameProcessorRuntimeManager.mm b/ios/Frame Processor/FrameProcessorRuntimeManager.mm index dcae577..db9bcc8 100644 --- a/ios/Frame Processor/FrameProcessorRuntimeManager.mm +++ b/ios/Frame Processor/FrameProcessorRuntimeManager.mm @@ -19,25 +19,25 @@ #import #import -#if __has_include() - #if __has_include() - #ifndef VISION_CAMERA_DISABLE_FRAME_PROCESSORS +#ifndef VISION_CAMERA_DISABLE_FRAME_PROCESSORS + #if __has_include() + #if __has_include() #import #import #import #import #define ENABLE_FRAME_PROCESSORS + #else + #warning Your react-native-reanimated version is not compatible with VisionCamera, Frame Processors are disabled. Make sure you're using reanimated 2.2.0 or above! #endif #else - #warning Your react-native-reanimated version is not compatible with VisionCamera, Frame Processors are disabled. Make sure you're using reanimated 2.2.0 or above! + #warning The NativeReanimatedModule.h header could not be found, Frame Processors are disabled. If you want to use Frame Processors, make sure you install react-native-reanimated! #endif -#else - #warning The NativeReanimatedModule.h header could not be found, Frame Processors are disabled. If you want to use Frame Processors, make sure you install react-native-reanimated! #endif -#import "../../cpp/MakeJSIRuntime.h" #import "FrameProcessorUtils.h" #import "FrameProcessorCallback.h" +#import "../React Utils/MakeJSIRuntime.h" #import "../React Utils/JSIUtils.h" // Forward declarations for the Swift classes diff --git a/ios/React Utils/MakeJSIRuntime.h b/ios/React Utils/MakeJSIRuntime.h new file mode 100644 index 0000000..a428c01 --- /dev/null +++ b/ios/React Utils/MakeJSIRuntime.h @@ -0,0 +1,42 @@ +// +// MakeJSIRuntime.h +// VisionCamera +// +// Created by Marc Rousavy on 06.07.21. +// Copyright © 2021 mrousavy. All rights reserved. +// + +#pragma once + +#include +#include + +#if __has_include() + // Hermes (https://hermesengine.dev) (RN 0.65+) + #include +#elif __has_include() + // Hermes (https://hermesengine.dev) + #include +#elif __has_include() + // V8 (https://github.com/Kudo/react-native-v8) + #include +#else + // JSC + #include +#endif + +using namespace facebook; + +namespace vision { + +static std::unique_ptr makeJSIRuntime() { +#if __has_include() || __has_include() + return facebook::hermes::makeHermesRuntime(); +#elif __has_include() + return facebook::createV8Runtime(""); +#else + return facebook::jsc::makeJSCRuntime(); +#endif +} + +} // namespace vision diff --git a/ios/VisionCamera.xcodeproj/project.pbxproj b/ios/VisionCamera.xcodeproj/project.pbxproj index 8fa3e08..bbc9866 100644 --- a/ios/VisionCamera.xcodeproj/project.pbxproj +++ b/ios/VisionCamera.xcodeproj/project.pbxproj @@ -88,6 +88,7 @@ B84760A22608EE38004C3180 /* FrameHostObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FrameHostObject.h; sourceTree = ""; }; B84760A52608EE7C004C3180 /* FrameHostObject.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FrameHostObject.mm; sourceTree = ""; }; B84760DE2608F57D004C3180 /* CameraQueues.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraQueues.swift; sourceTree = ""; }; + B84C10592694A182006EFA70 /* MakeJSIRuntime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MakeJSIRuntime.h; sourceTree = ""; }; B86DC970260E2D5200FB17B2 /* AVAudioSession+trySetAllowHaptics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVAudioSession+trySetAllowHaptics.swift"; sourceTree = ""; }; B86DC973260E310600FB17B2 /* CameraView+AVAudioSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CameraView+AVAudioSession.swift"; sourceTree = ""; }; B86DC976260E315100FB17B2 /* CameraView+AVCaptureSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CameraView+AVCaptureSession.swift"; sourceTree = ""; }; @@ -138,8 +139,6 @@ B8DB3BC7263DC28C004C18D7 /* AVAssetWriter.Status+descriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVAssetWriter.Status+descriptor.swift"; sourceTree = ""; }; B8DB3BC9263DC4D8004C18D7 /* RecordingSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecordingSession.swift; sourceTree = ""; }; B8DB3BCB263DC97E004C18D7 /* AVFileType+descriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVFileType+descriptor.swift"; sourceTree = ""; }; - B8DCF09125EA7BEE00EA5C72 /* SpeedChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SpeedChecker.h; sourceTree = ""; }; - B8DCF14425EA817D00EA5C72 /* MakeJSIRuntime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MakeJSIRuntime.h; sourceTree = ""; }; B8F7DDD1266F715D00120533 /* Frame.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Frame.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -180,7 +179,6 @@ B887518125E0102000DB86D6 /* CameraViewManager.swift */, B8DB3BC9263DC4D8004C18D7 /* RecordingSession.swift */, B887515C25E0102000DB86D6 /* PhotoCaptureDelegate.swift */, - B8DCF08F25EA7BEE00EA5C72 /* cpp */, B887516125E0102000DB86D6 /* Extensions */, B887517225E0102000DB86D6 /* Parsers */, B887516D25E0102000DB86D6 /* React Utils */, @@ -222,6 +220,7 @@ B8994E6B263F03E100069589 /* JSIUtils.mm */, B8805065266798AB00EAD7F2 /* JSConsoleHelper.h */, B8805066266798B600EAD7F2 /* JSConsoleHelper.mm */, + B84C10592694A182006EFA70 /* MakeJSIRuntime.h */, ); path = "React Utils"; sourceTree = ""; @@ -247,16 +246,6 @@ path = Parsers; sourceTree = ""; }; - B8DCF08F25EA7BEE00EA5C72 /* cpp */ = { - isa = PBXGroup; - children = ( - B8DCF14425EA817D00EA5C72 /* MakeJSIRuntime.h */, - B8DCF09125EA7BEE00EA5C72 /* SpeedChecker.h */, - ); - name = cpp; - path = ../cpp; - sourceTree = ""; - }; B8DCF2D725EA940700EA5C72 /* Frame Processor */ = { isa = PBXGroup; children = ( diff --git a/package.json b/package.json index 0c65f12..8a65a2c 100644 --- a/package.json +++ b/package.json @@ -98,12 +98,18 @@ "react": "*", "react-native": "*" }, - "jest": { - "preset": "react-native", - "modulePathIgnorePatterns": [ - "/example/node_modules", - "/lib/" - ] + "prettier": { + "bracketSpacing": true, + "jsxBracketSameLine": true, + "singleQuote": true, + "trailingComma": "all", + "semi": true, + "tabWidth": 2, + "useTabs": false, + "printWidth": 140 + }, + "babel": { + "presets": ["module:metro-react-native-babel-preset"] }, "release-it": { "git": { diff --git a/patches/react-native-reanimated+2.2.0.patch b/patches/react-native-reanimated+2.2.0.patch deleted file mode 100644 index 55f0e67..0000000 --- a/patches/react-native-reanimated+2.2.0.patch +++ /dev/null @@ -1,20 +0,0 @@ -diff --git a/node_modules/react-native-reanimated/android/build.gradle b/node_modules/react-native-reanimated/android/build.gradle -index bb707e7..9186873 100644 ---- a/node_modules/react-native-reanimated/android/build.gradle -+++ b/node_modules/react-native-reanimated/android/build.gradle -@@ -7,8 +7,12 @@ def reactNativeVersion = json.version as String - def (major, minor, patch) = reactNativeVersion.tokenize('.') - - def engine = "jsc" --if (project(':app').ext.react.enableHermes) { -- engine = "hermes" --} -+rootProject.getSubprojects().forEach({project -> -+ if (project.plugins.hasPlugin("com.android.application")) { -+ if(project.ext.react.enableHermes) { -+ engine = "hermes" -+ } -+ } -+ }) - - artifacts.add("default", file("react-native-reanimated-${minor}-${engine}.aar")) diff --git a/tsconfig.docs.json b/tsconfig.docs.json deleted file mode 100644 index 999d3f3..0000000 --- a/tsconfig.docs.json +++ /dev/null @@ -1,5 +0,0 @@ - -{ - "extends": "./tsconfig", - "exclude": ["example"] -} diff --git a/tsconfig.json b/tsconfig.json index 7533010..20db155 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,7 +30,6 @@ "src", "example", ".eslintrc.js", - ".prettierrc.js", "babel.config.js", ], "exclude": [