react-native-yolo 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +51 -29
  3. package/Yolo.podspec +31 -31
  4. package/android/CMakeLists.txt +35 -32
  5. package/android/build.gradle +154 -147
  6. package/android/fix-prefab.gradle +50 -50
  7. package/android/gradle.properties +5 -5
  8. package/android/src/main/AndroidManifest.xml +3 -2
  9. package/android/src/main/cpp/cpp-adapter.cpp +8 -8
  10. package/android/src/main/java/com/yolo/HybridYolo.kt +65 -27
  11. package/android/src/main/java/com/yolo/YoloPackage.kt +20 -29
  12. package/android/src/main/java/com/yolo/loader/YoloModelLoader.kt +130 -0
  13. package/android/src/main/java/com/yolo/utils/BitmapOrientationFixer.kt +56 -0
  14. package/android/src/main/java/com/yolo/utils/ContextProvider.kt +14 -0
  15. package/android/src/main/java/com/yolo/utils/FrameJpegConverter.kt +27 -0
  16. package/android/src/main/java/com/yolo/utils/FrameValidator.kt +29 -0
  17. package/android/src/main/java/com/yolo/utils/Nv21JpegEncoder.kt +34 -0
  18. package/android/src/main/java/com/yolo/utils/Yuv420ToNv21Converter.kt +62 -0
  19. package/ios/Bridge.h +8 -8
  20. package/ios/HybridYolo.swift +14 -21
  21. package/lib/commonjs/index.js +10 -3
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/module/index.js +11 -3
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/typescript/src/index.d.ts +4 -4
  26. package/lib/typescript/src/index.d.ts.map +1 -1
  27. package/lib/typescript/src/specs/yolo.nitro.d.ts +8 -8
  28. package/lib/typescript/src/specs/yolo.nitro.d.ts.map +1 -1
  29. package/nitro.json +29 -29
  30. package/nitrogen/generated/android/Yolo+autolinking.cmake +0 -2
  31. package/nitrogen/generated/android/YoloOnLoad.cpp +0 -2
  32. package/nitrogen/generated/android/c++/JHybridYoloSpec.cpp +21 -12
  33. package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +4 -3
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloSpec.kt +13 -7
  35. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.cpp +11 -0
  36. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +47 -0
  37. package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +8 -0
  38. package/nitrogen/generated/ios/c++/HybridYoloSpecSwift.hpp +28 -9
  39. package/nitrogen/generated/ios/swift/HybridYoloSpec.swift +6 -3
  40. package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +35 -25
  41. package/nitrogen/generated/shared/c++/HybridYoloSpec.cpp +3 -2
  42. package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +9 -5
  43. package/package.json +127 -122
  44. package/src/index.ts +12 -14
  45. package/src/specs/yolo.nitro.ts +8 -13
  46. package/nitrogen/generated/android/c++/views/JHybridYoloStateUpdater.cpp +0 -56
  47. package/nitrogen/generated/android/c++/views/JHybridYoloStateUpdater.hpp +0 -49
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/views/HybridYoloManager.kt +0 -80
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/views/HybridYoloStateUpdater.kt +0 -23
  50. package/nitrogen/generated/ios/c++/views/HybridYoloComponent.mm +0 -122
  51. package/nitrogen/generated/shared/c++/views/HybridYoloComponent.cpp +0 -83
  52. package/nitrogen/generated/shared/c++/views/HybridYoloComponent.hpp +0 -110
  53. package/nitrogen/generated/shared/json/YoloConfig.json +0 -10
package/package.json CHANGED
@@ -1,122 +1,127 @@
1
- {
2
- "name": "react-native-yolo",
3
- "version": "0.0.2",
4
- "description": "react-native-yolo is a react native package built with Nitro",
5
- "main": "./lib/commonjs/index.js",
6
- "module": "./lib/module/index.js",
7
- "types": "./lib/typescript/src/index.d.ts",
8
- "react-native": "src/index",
9
- "source": "src/index",
10
- "scripts": {
11
- "typecheck": "tsc --noEmit",
12
- "clean": "git clean -dfX",
13
- "release": "semantic-release",
14
- "build": "npm run typecheck && bob build",
15
- "codegen": "nitrogen --logLevel=\"debug\" && npm run build && node post-script.js"
16
- },
17
- "keywords": [
18
- "react-native",
19
- "react-native-yolo"
20
- ],
21
- "files": [
22
- "src",
23
- "react-native.config.js",
24
- "lib",
25
- "nitrogen",
26
- "cpp",
27
- "nitro.json",
28
- "android/build.gradle",
29
- "android/fix-prefab.gradle",
30
- "android/gradle.properties",
31
- "android/CMakeLists.txt",
32
- "android/src",
33
- "ios/**/*.h",
34
- "ios/**/*.m",
35
- "ios/**/*.mm",
36
- "ios/**/*.cpp",
37
- "ios/**/*.swift",
38
- "app.plugin.js",
39
- "*.podspec",
40
- "README.md"
41
- ],
42
- "workspaces": [
43
- "example"
44
- ],
45
- "repository": "https://github.com/khaoula-ghalimi/react-native-yolo.git",
46
- "author": "Khaoula-Ghalimi",
47
- "license": "MIT",
48
- "bugs": "https://github.com/khaoula-ghalimi/react-native-yolo/issues",
49
- "homepage": "https://github.com/khaoula-ghalimi/react-native-yolo#readme",
50
- "publishConfig": {
51
- "access": "public",
52
- "registry": "https://registry.npmjs.org/"
53
- },
54
- "devDependencies": {
55
- "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
56
- "@semantic-release/changelog": "^6.0.3",
57
- "@semantic-release/git": "^10.0.1",
58
- "@types/jest": "^29.5.12",
59
- "@types/react": "19.2.0",
60
- "nitrogen": "0.35.9",
61
- "react": "19.2.3",
62
- "react-native": "0.84.1",
63
- "react-native-builder-bob": "^0.40.18",
64
- "react-native-nitro-modules": "0.35.9",
65
- "conventional-changelog-conventionalcommits": "^9.1.0",
66
- "semantic-release": "^25.0.3",
67
- "typescript": "^5.8.3"
68
- },
69
- "peerDependencies": {
70
- "react": "*",
71
- "react-native": "*",
72
- "react-native-nitro-modules": "*"
73
- },
74
- "eslintConfig": {
75
- "root": true,
76
- "extends": [
77
- "@react-native",
78
- "prettier"
79
- ],
80
- "plugins": [
81
- "prettier"
82
- ],
83
- "rules": {
84
- "prettier/prettier": [
85
- "warn",
86
- {
87
- "quoteProps": "consistent",
88
- "singleQuote": true,
89
- "tabWidth": 2,
90
- "trailingComma": "es5",
91
- "useTabs": false
92
- }
93
- ]
94
- }
95
- },
96
- "eslintIgnore": [
97
- "node_modules/",
98
- "lib/"
99
- ],
100
- "prettier": {
101
- "quoteProps": "consistent",
102
- "singleQuote": true,
103
- "tabWidth": 2,
104
- "trailingComma": "es5",
105
- "useTabs": false,
106
- "semi": false
107
- },
108
- "react-native-builder-bob": {
109
- "source": "src",
110
- "output": "lib",
111
- "targets": [
112
- "commonjs",
113
- "module",
114
- [
115
- "typescript",
116
- {
117
- "project": "tsconfig.json"
118
- }
119
- ]
120
- ]
121
- }
122
- }
1
+ {
2
+ "name": "react-native-yolo",
3
+ "version": "0.0.4",
4
+ "description": "react-native-yolo is a react native package built with Nitro",
5
+ "main": "./lib/commonjs/index.js",
6
+ "module": "./lib/module/index.js",
7
+ "types": "./lib/typescript/src/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "scripts": {
11
+ "typecheck": "tsc --noEmit",
12
+ "clean": "git clean -dfX",
13
+ "release": "semantic-release",
14
+ "build": "npm run typecheck && bob build",
15
+ "codegen": "nitrogen --logLevel=\"debug\" && npm run build && node post-script.js"
16
+ },
17
+ "keywords": [
18
+ "react-native",
19
+ "react-native-yolo"
20
+ ],
21
+ "files": [
22
+ "src",
23
+ "react-native.config.js",
24
+ "lib",
25
+ "nitrogen",
26
+ "cpp",
27
+ "nitro.json",
28
+ "android/build.gradle",
29
+ "android/fix-prefab.gradle",
30
+ "android/gradle.properties",
31
+ "android/CMakeLists.txt",
32
+ "android/src",
33
+ "ios/**/*.h",
34
+ "ios/**/*.m",
35
+ "ios/**/*.mm",
36
+ "ios/**/*.cpp",
37
+ "ios/**/*.swift",
38
+ "app.plugin.js",
39
+ "*.podspec",
40
+ "README.md"
41
+ ],
42
+ "repository": "https://github.com/khaoula-ghalimi/react-native-yolo.git",
43
+ "author": "Khaoula-Ghalimi",
44
+ "license": "MIT",
45
+ "bugs": "https://github.com/khaoula-ghalimi/react-native-yolo/issues",
46
+ "homepage": "https://github.com/khaoula-ghalimi/react-native-yolo#readme",
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "registry": "https://registry.npmjs.org/"
50
+ },
51
+ "devDependencies": {
52
+ "@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
53
+ "@semantic-release/changelog": "^6.0.3",
54
+ "@semantic-release/git": "^10.0.1",
55
+ "@types/jest": "^29.5.12",
56
+ "@types/react": "19.2.0",
57
+ "conventional-changelog-conventionalcommits": "^9.1.0",
58
+ "nitrogen": "0.35.9",
59
+ "react": "19.2.3",
60
+ "react-native": "0.84.1",
61
+ "react-native-builder-bob": "^0.40.18",
62
+ "react-native-nitro-image": "^0.15.1",
63
+ "react-native-nitro-modules": "0.35.9",
64
+ "react-native-vision-camera": "^5.0.11",
65
+ "react-native-vision-camera-worklets": "^5.0.11",
66
+ "react-native-reanimated": "4.3.1",
67
+ "react-native-safe-area-context": "~5.7.0",
68
+ "react-native-worklets": "0.8.3",
69
+ "semantic-release": "^25.0.3",
70
+ "typescript": "^5.8.3"
71
+ },
72
+ "peerDependencies": {
73
+ "react": "*",
74
+ "react-native": "*",
75
+ "react-native-nitro-image": "^0.15.1",
76
+ "react-native-nitro-modules": "*",
77
+ "react-native-vision-camera": ">= 5.0"
78
+ },
79
+ "eslintConfig": {
80
+ "root": true,
81
+ "extends": [
82
+ "@react-native",
83
+ "prettier"
84
+ ],
85
+ "plugins": [
86
+ "prettier"
87
+ ],
88
+ "rules": {
89
+ "prettier/prettier": [
90
+ "warn",
91
+ {
92
+ "quoteProps": "consistent",
93
+ "singleQuote": true,
94
+ "tabWidth": 2,
95
+ "trailingComma": "es5",
96
+ "useTabs": false
97
+ }
98
+ ]
99
+ }
100
+ },
101
+ "eslintIgnore": [
102
+ "node_modules/",
103
+ "lib/"
104
+ ],
105
+ "prettier": {
106
+ "quoteProps": "consistent",
107
+ "singleQuote": true,
108
+ "tabWidth": 2,
109
+ "trailingComma": "es5",
110
+ "useTabs": false,
111
+ "semi": false
112
+ },
113
+ "react-native-builder-bob": {
114
+ "source": "src",
115
+ "output": "lib",
116
+ "targets": [
117
+ "commonjs",
118
+ "module",
119
+ [
120
+ "typescript",
121
+ {
122
+ "project": "tsconfig.json"
123
+ }
124
+ ]
125
+ ]
126
+ }
127
+ }
package/src/index.ts CHANGED
@@ -1,14 +1,12 @@
1
- import { getHostComponent, type HybridRef } from 'react-native-nitro-modules'
2
- import YoloConfig from '../nitrogen/generated/shared/json/YoloConfig.json'
3
- import type {
4
- YoloProps,
5
- YoloMethods,
6
- } from './specs/yolo.nitro'
7
-
8
-
9
- export const Yolo = getHostComponent<YoloProps, YoloMethods>(
10
- 'Yolo',
11
- () => YoloConfig
12
- )
13
-
14
- export type YoloRef = HybridRef<YoloProps, YoloMethods>
1
+ import { NitroModules } from 'react-native-nitro-modules'
2
+ import type { Yolo as YoloSpec } from './specs/yolo.nitro'
3
+ import { Image } from 'react-native'
4
+
5
+ const NativeYolo = NitroModules.createHybridObject<YoloSpec>('Yolo')
6
+
7
+ export const Yolo = Object.assign(NativeYolo, {
8
+ loadModelTest(modelAssetId: number){
9
+ const { uri } = Image.resolveAssetSource(modelAssetId);
10
+ return NativeYolo.loadModel(uri)
11
+ },
12
+ })
@@ -1,13 +1,8 @@
1
- import type {
2
- HybridView,
3
- HybridViewProps,
4
- HybridViewMethods,
5
- } from 'react-native-nitro-modules'
6
-
7
- export interface YoloProps extends HybridViewProps {
8
- isRed: boolean
9
- }
10
-
11
- export interface YoloMethods extends HybridViewMethods {}
12
-
13
- export type Yolo = HybridView<YoloProps, YoloMethods, { ios: 'swift', android: 'kotlin' }>
1
+ import type { HybridObject } from 'react-native-nitro-modules'
2
+ import type { Frame } from 'react-native-vision-camera'
3
+
4
+ export interface Yolo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
5
+ sum(num1: number, num2: number): number
6
+ loadModel(modelPath: string): void
7
+ frameToBase64(frame: Frame): string
8
+ }
@@ -1,56 +0,0 @@
1
- ///
2
- /// JHybridYoloStateUpdater.cpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- #include "JHybridYoloStateUpdater.hpp"
9
- #include "views/HybridYoloComponent.hpp"
10
- #include <NitroModules/NitroDefines.hpp>
11
- #include <react/fabric/StateWrapperImpl.h>
12
-
13
- namespace margelo::nitro::yolo::views {
14
-
15
- using namespace facebook;
16
- using ConcreteStateData = react::ConcreteState<HybridYoloState>;
17
-
18
- void JHybridYoloStateUpdater::updateViewProps(jni::alias_ref<jni::JClass> /* class */,
19
- jni::alias_ref<JHybridYoloSpec::JavaPart> javaView,
20
- jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface) {
21
- std::shared_ptr<JHybridYoloSpec> hybridView = javaView->getJHybridYoloSpec();
22
-
23
- // Get concrete StateWrapperImpl from passed StateWrapper interface object
24
- jobject rawStateWrapper = stateWrapperInterface.get();
25
- if (!stateWrapperInterface->isInstanceOf(react::StateWrapperImpl::javaClassStatic())) [[unlikely]] {
26
- throw std::runtime_error("StateWrapper is not a StateWrapperImpl");
27
- }
28
- auto stateWrapper = jni::alias_ref<react::StateWrapperImpl::javaobject>{
29
- static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)};
30
- std::shared_ptr<const react::State> state = stateWrapper->cthis()->getState();
31
- auto concreteState = std::static_pointer_cast<const ConcreteStateData>(state);
32
- const HybridYoloState& data = concreteState->getData();
33
- const std::shared_ptr<HybridYoloProps>& props = data.getProps();
34
- if (props == nullptr) [[unlikely]] {
35
- // Props aren't set yet!
36
- throw std::runtime_error("HybridYoloState's data doesn't contain any props!");
37
- }
38
-
39
- // Update all props if they are dirty
40
- if (props->isRed.isDirty) {
41
- hybridView->setIsRed(props->isRed.value);
42
- props->isRed.isDirty = false;
43
- }
44
-
45
- // Update hybridRef if it changed
46
- if (props->hybridRef.isDirty) {
47
- // hybridRef changed - call it with new this
48
- const auto& maybeFunc = props->hybridRef.value;
49
- if (maybeFunc.has_value()) {
50
- maybeFunc.value()(hybridView);
51
- }
52
- props->hybridRef.isDirty = false;
53
- }
54
- }
55
-
56
- } // namespace margelo::nitro::yolo::views
@@ -1,49 +0,0 @@
1
- ///
2
- /// JHybridYoloStateUpdater.hpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- #pragma once
9
-
10
- #ifndef RN_SERIALIZABLE_STATE
11
- #error Yolo was compiled without the 'RN_SERIALIZABLE_STATE' flag. This flag is required for Nitro Views - set it in your CMakeLists!
12
- #endif
13
-
14
- #include <fbjni/fbjni.h>
15
- #include <react/fabric/CoreComponentsRegistry.h>
16
- #include <react/fabric/StateWrapperImpl.h>
17
- #include <react/renderer/core/ConcreteComponentDescriptor.h>
18
- #include <NitroModules/NitroDefines.hpp>
19
- #include <NitroModules/JStateWrapper.hpp>
20
- #include "JHybridYoloSpec.hpp"
21
- #include "views/HybridYoloComponent.hpp"
22
-
23
- namespace margelo::nitro::yolo::views {
24
-
25
- using namespace facebook;
26
-
27
- class JHybridYoloStateUpdater final: public jni::JavaClass<JHybridYoloStateUpdater> {
28
- public:
29
- static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/yolo/views/HybridYoloStateUpdater;";
30
-
31
- public:
32
- static void updateViewProps(jni::alias_ref<jni::JClass> /* class */,
33
- jni::alias_ref<JHybridYoloSpec::JavaPart> view,
34
- jni::alias_ref<JStateWrapper::javaobject> stateWrapperInterface);
35
-
36
- public:
37
- static void registerNatives() {
38
- // Register JNI calls
39
- javaClassStatic()->registerNatives({
40
- makeNativeMethod("updateViewProps", JHybridYoloStateUpdater::updateViewProps),
41
- });
42
- // Register React Native view component descriptor
43
- auto provider = react::concreteComponentDescriptorProvider<HybridYoloComponentDescriptor>();
44
- auto providerRegistry = react::CoreComponentsRegistry::sharedProviderRegistry();
45
- providerRegistry->add(provider);
46
- }
47
- };
48
-
49
- } // namespace margelo::nitro::yolo::views
@@ -1,80 +0,0 @@
1
- ///
2
- /// HybridYoloManager.kt
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- package com.margelo.nitro.yolo.views
9
-
10
- import android.view.View
11
- import com.facebook.react.uimanager.ReactStylesDiffMap
12
- import com.facebook.react.uimanager.SimpleViewManager
13
- import com.facebook.react.uimanager.StateWrapper
14
- import com.facebook.react.uimanager.ThemedReactContext
15
- import com.margelo.nitro.R.id.associated_hybrid_view_tag
16
- import com.margelo.nitro.views.RecyclableView
17
- import com.yolo.*
18
-
19
- /**
20
- * Represents the React Native `ViewManager` for the "Yolo" Nitro HybridView.
21
- */
22
- public class HybridYoloManager: SimpleViewManager<View>() {
23
- init {
24
- if (RecyclableView::class.java.isAssignableFrom(HybridYolo::class.java)) {
25
- // Enable view recycling
26
- super.setupViewRecycling()
27
- }
28
- }
29
-
30
- override fun getName(): String {
31
- return "Yolo"
32
- }
33
-
34
- override fun createViewInstance(reactContext: ThemedReactContext): View {
35
- val hybridView = HybridYolo(reactContext)
36
- val view = hybridView.view
37
- view.setTag(associated_hybrid_view_tag, hybridView)
38
- return view
39
- }
40
-
41
- override fun updateState(view: View, props: ReactStylesDiffMap, stateWrapper: StateWrapper): Any? {
42
- val hybridView = getHybridView(view)
43
- ?: throw Error("Couldn't find view $view in local views table!")
44
-
45
- // 1. Update each prop individually
46
- hybridView.beforeUpdate()
47
- HybridYoloStateUpdater.updateViewProps(hybridView, stateWrapper)
48
- hybridView.afterUpdate()
49
-
50
- // 2. Continue in base View props
51
- return super.updateState(view, props, stateWrapper)
52
- }
53
-
54
- override fun onDropViewInstance(view: View) {
55
- val hybridView = getHybridView(view)
56
- hybridView?.onDropView()
57
- return super.onDropViewInstance(view)
58
- }
59
-
60
- protected override fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? {
61
- super.prepareToRecycleView(reactContext, view)
62
- val hybridView = getHybridView(view)
63
- ?: return null
64
-
65
- @Suppress("USELESS_IS_CHECK")
66
- if (hybridView is RecyclableView) {
67
- // Recycle in it's implementation
68
- hybridView.prepareForRecycle()
69
-
70
- // Maybe update the view if it changed
71
- return hybridView.view
72
- } else {
73
- return null
74
- }
75
- }
76
-
77
- private fun getHybridView(view: View): HybridYolo? {
78
- return view.getTag(associated_hybrid_view_tag) as? HybridYolo
79
- }
80
- }
@@ -1,23 +0,0 @@
1
- ///
2
- /// HybridYoloStateUpdater.kt
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- package com.margelo.nitro.yolo.views
9
-
10
- import com.facebook.react.uimanager.StateWrapper
11
- import com.margelo.nitro.yolo.*
12
-
13
- internal class HybridYoloStateUpdater {
14
- companion object {
15
- /**
16
- * Updates the props for [view] through C++.
17
- * The [state] prop is expected to contain [view]'s props as wrapped Fabric state.
18
- */
19
- @Suppress("KotlinJniMissingFunction")
20
- @JvmStatic
21
- external fun updateViewProps(view: HybridYoloSpec, state: StateWrapper)
22
- }
23
- }
@@ -1,122 +0,0 @@
1
- ///
2
- /// HybridYoloComponent.mm
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- #import "HybridYoloComponent.hpp"
9
- #import <memory>
10
- #import <react/renderer/componentregistry/ComponentDescriptorProvider.h>
11
- #import <React/RCTViewComponentView.h>
12
- #import <React/RCTComponentViewFactory.h>
13
- #import <React/UIView+ComponentViewProtocol.h>
14
- #import <NitroModules/NitroDefines.hpp>
15
- #import <UIKit/UIKit.h>
16
-
17
- #import "HybridYoloSpecSwift.hpp"
18
- #import "Yolo-Swift-Cxx-Umbrella.hpp"
19
-
20
- #if __has_include(<cxxreact/ReactNativeVersion.h>)
21
- #include <cxxreact/ReactNativeVersion.h>
22
- #if REACT_NATIVE_VERSION_MINOR >= 82
23
- #define ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
24
- #endif
25
- #endif
26
-
27
- using namespace facebook;
28
- using namespace margelo::nitro::yolo;
29
- using namespace margelo::nitro::yolo::views;
30
-
31
- /**
32
- * Represents the React Native View holder for the Nitro "Yolo" HybridView.
33
- */
34
- @interface HybridYoloComponent: RCTViewComponentView
35
- + (BOOL)shouldBeRecycled;
36
- @end
37
-
38
- @implementation HybridYoloComponent {
39
- std::shared_ptr<HybridYoloSpecSwift> _hybridView;
40
- }
41
-
42
- + (void) load {
43
- [super load];
44
- [RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[HybridYoloComponent class]];
45
- }
46
-
47
- + (react::ComponentDescriptorProvider) componentDescriptorProvider {
48
- return react::concreteComponentDescriptorProvider<HybridYoloComponentDescriptor>();
49
- }
50
-
51
- - (instancetype) init {
52
- if (self = [super init]) {
53
- std::shared_ptr<HybridYoloSpec> hybridView = Yolo::YoloAutolinking::createYolo();
54
- _hybridView = std::dynamic_pointer_cast<HybridYoloSpecSwift>(hybridView);
55
- [self updateView];
56
- }
57
- return self;
58
- }
59
-
60
- - (void) updateView {
61
- // 1. Get Swift part
62
- Yolo::HybridYoloSpec_cxx& swiftPart = _hybridView->getSwiftPart();
63
-
64
- // 2. Get UIView*
65
- void* viewUnsafe = swiftPart.getView();
66
- UIView* view = (__bridge_transfer UIView*) viewUnsafe;
67
-
68
- // 3. Update RCTViewComponentView's [contentView]
69
- [self setContentView:view];
70
- }
71
-
72
- - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
73
- oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
74
- // 1. Downcast props
75
- const auto& newViewPropsConst = *std::static_pointer_cast<HybridYoloProps const>(props);
76
- auto& newViewProps = const_cast<HybridYoloProps&>(newViewPropsConst);
77
- Yolo::HybridYoloSpec_cxx& swiftPart = _hybridView->getSwiftPart();
78
-
79
- // 2. Update each prop individually
80
- swiftPart.beforeUpdate();
81
-
82
- // isRed: boolean
83
- if (newViewProps.isRed.isDirty) {
84
- swiftPart.setIsRed(newViewProps.isRed.value);
85
- newViewProps.isRed.isDirty = false;
86
- }
87
-
88
- swiftPart.afterUpdate();
89
-
90
- // 3. Update hybridRef if it changed
91
- if (newViewProps.hybridRef.isDirty) {
92
- // hybridRef changed - call it with new this
93
- const auto& maybeFunc = newViewProps.hybridRef.value;
94
- if (maybeFunc.has_value()) {
95
- maybeFunc.value()(_hybridView);
96
- }
97
- newViewProps.hybridRef.isDirty = false;
98
- }
99
-
100
- // 4. Continue in base class
101
- [super updateProps:props oldProps:oldProps];
102
- }
103
-
104
- + (BOOL)shouldBeRecycled {
105
- return Yolo::YoloAutolinking::isYoloRecyclable();
106
- }
107
-
108
- - (void)prepareForRecycle {
109
- [super prepareForRecycle];
110
- Yolo::HybridYoloSpec_cxx& swiftPart = _hybridView->getSwiftPart();
111
- swiftPart.maybePrepareForRecycle();
112
- }
113
-
114
- #ifdef ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
115
- - (void)invalidate {
116
- Yolo::HybridYoloSpec_cxx& swiftPart = _hybridView->getSwiftPart();
117
- swiftPart.onDropView();
118
- [super invalidate];
119
- }
120
- #endif
121
-
122
- @end