react-native-yolo 0.0.2 → 0.0.3
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.
- package/README.md +28 -6
- package/android/build.gradle +5 -0
- package/android/src/main/java/com/yolo/HybridYolo.kt +36 -21
- package/android/src/main/java/com/yolo/YoloPackage.kt +2 -11
- package/android/src/main/java/com/yolo/loader/YoloModelLoader.kt +130 -0
- package/android/src/main/java/com/yolo/utils/ContextProvider.kt +14 -0
- package/ios/Bridge.h +1 -1
- package/ios/HybridYolo.swift +4 -11
- package/lib/commonjs/index.js +1 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +2 -3
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/yolo.nitro.d.ts +6 -8
- package/lib/typescript/src/specs/yolo.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/Yolo+autolinking.cmake +0 -2
- package/nitrogen/generated/android/YoloOnLoad.cpp +0 -2
- package/nitrogen/generated/android/c++/JHybridYoloSpec.cpp +11 -11
- package/nitrogen/generated/android/c++/JHybridYoloSpec.hpp +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/HybridYoloSpec.kt +8 -7
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Bridge.hpp +20 -0
- package/nitrogen/generated/ios/Yolo-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridYoloSpecSwift.hpp +16 -8
- package/nitrogen/generated/ios/swift/HybridYoloSpec.swift +4 -3
- package/nitrogen/generated/ios/swift/HybridYoloSpec_cxx.swift +20 -27
- package/nitrogen/generated/shared/c++/HybridYoloSpec.cpp +2 -2
- package/nitrogen/generated/shared/c++/HybridYoloSpec.hpp +4 -4
- package/package.json +1 -1
- package/src/index.ts +10 -12
- package/src/specs/yolo.nitro.ts +5 -11
- package/nitrogen/generated/android/c++/views/JHybridYoloStateUpdater.cpp +0 -56
- package/nitrogen/generated/android/c++/views/JHybridYoloStateUpdater.hpp +0 -49
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/views/HybridYoloManager.kt +0 -80
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/views/HybridYoloStateUpdater.kt +0 -23
- package/nitrogen/generated/ios/c++/views/HybridYoloComponent.mm +0 -122
- package/nitrogen/generated/shared/c++/views/HybridYoloComponent.cpp +0 -83
- package/nitrogen/generated/shared/c++/views/HybridYoloComponent.hpp +0 -110
- package/nitrogen/generated/shared/json/YoloConfig.json +0 -10
|
@@ -121,36 +121,29 @@ open class HybridYoloSpec_cxx {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
// Properties
|
|
124
|
-
|
|
125
|
-
@inline(__always)
|
|
126
|
-
get {
|
|
127
|
-
return self.__implementation.isRed
|
|
128
|
-
}
|
|
129
|
-
@inline(__always)
|
|
130
|
-
set {
|
|
131
|
-
self.__implementation.isRed = newValue
|
|
132
|
-
}
|
|
133
|
-
}
|
|
124
|
+
|
|
134
125
|
|
|
135
126
|
// Methods
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
public final func maybePrepareForRecycle() {
|
|
149
|
-
guard let recyclable = __implementation as? any RecyclableView else { return }
|
|
150
|
-
recyclable.prepareForRecycle()
|
|
127
|
+
@inline(__always)
|
|
128
|
+
public final func sum(num1: Double, num2: Double) -> bridge.Result_double_ {
|
|
129
|
+
do {
|
|
130
|
+
let __result = try self.__implementation.sum(num1: num1, num2: num2)
|
|
131
|
+
let __resultCpp = __result
|
|
132
|
+
return bridge.create_Result_double_(__resultCpp)
|
|
133
|
+
} catch (let __error) {
|
|
134
|
+
let __exceptionPtr = __error.toCpp()
|
|
135
|
+
return bridge.create_Result_double_(__exceptionPtr)
|
|
136
|
+
}
|
|
151
137
|
}
|
|
152
138
|
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
@inline(__always)
|
|
140
|
+
public final func loadModel(modelPath: std.string) -> bridge.Result_void_ {
|
|
141
|
+
do {
|
|
142
|
+
try self.__implementation.loadModel(modelPath: String(modelPath))
|
|
143
|
+
return bridge.create_Result_void_()
|
|
144
|
+
} catch (let __error) {
|
|
145
|
+
let __exceptionPtr = __error.toCpp()
|
|
146
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
147
|
+
}
|
|
155
148
|
}
|
|
156
149
|
}
|
|
@@ -14,8 +14,8 @@ namespace margelo::nitro::yolo {
|
|
|
14
14
|
HybridObject::loadHybridMethods();
|
|
15
15
|
// load custom methods/properties
|
|
16
16
|
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
-
prototype.
|
|
18
|
-
prototype.
|
|
17
|
+
prototype.registerHybridMethod("sum", &HybridYoloSpec::sum);
|
|
18
|
+
prototype.registerHybridMethod("loadModel", &HybridYoloSpec::loadModel);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
#include <string>
|
|
19
19
|
|
|
20
20
|
namespace margelo::nitro::yolo {
|
|
21
21
|
|
|
@@ -44,12 +44,12 @@ namespace margelo::nitro::yolo {
|
|
|
44
44
|
|
|
45
45
|
public:
|
|
46
46
|
// Properties
|
|
47
|
-
|
|
48
|
-
virtual void setIsRed(bool isRed) = 0;
|
|
47
|
+
|
|
49
48
|
|
|
50
49
|
public:
|
|
51
50
|
// Methods
|
|
52
|
-
|
|
51
|
+
virtual double sum(double num1, double num2) = 0;
|
|
52
|
+
virtual void loadModel(const std::string& modelPath) = 0;
|
|
53
53
|
|
|
54
54
|
protected:
|
|
55
55
|
// Hybrid Setup
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
YoloProps,
|
|
5
|
-
YoloMethods,
|
|
6
|
-
} from './specs/yolo.nitro'
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
+
import type { Yolo as YoloSpec } from './specs/yolo.nitro'
|
|
3
|
+
import { Image } from 'react-native'
|
|
7
4
|
|
|
5
|
+
const NativeYolo = NitroModules.createHybridObject<YoloSpec>('Yolo')
|
|
8
6
|
|
|
9
|
-
export const Yolo =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export const Yolo = Object.assign(NativeYolo, {
|
|
8
|
+
loadModelTest(modelAssetId: number){
|
|
9
|
+
const { uri } = Image.resolveAssetSource(modelAssetId);
|
|
10
|
+
return NativeYolo.loadModel(uri)
|
|
11
|
+
},
|
|
12
|
+
})
|
package/src/specs/yolo.nitro.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
HybridView,
|
|
3
|
-
HybridViewProps,
|
|
4
|
-
HybridViewMethods,
|
|
5
|
-
} from 'react-native-nitro-modules'
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules'
|
|
6
2
|
|
|
7
|
-
export interface YoloProps extends HybridViewProps {
|
|
8
|
-
isRed: boolean
|
|
9
|
-
}
|
|
10
3
|
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export interface Yolo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
|
|
5
|
+
sum(num1: number, num2: number): number
|
|
6
|
+
loadModel(modelPath: string): void
|
|
7
|
+
}
|
|
@@ -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
|
-
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/yolo/views/HybridYoloStateUpdater.kt
DELETED
|
@@ -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
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// HybridYoloComponent.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 "HybridYoloComponent.hpp"
|
|
9
|
-
|
|
10
|
-
#include <string>
|
|
11
|
-
#include <exception>
|
|
12
|
-
#include <utility>
|
|
13
|
-
#include <NitroModules/NitroDefines.hpp>
|
|
14
|
-
#include <NitroModules/JSIConverter.hpp>
|
|
15
|
-
#include <NitroModules/PropNameIDCache.hpp>
|
|
16
|
-
#include <react/renderer/core/RawValue.h>
|
|
17
|
-
#include <react/renderer/core/ShadowNode.h>
|
|
18
|
-
#include <react/renderer/core/ComponentDescriptor.h>
|
|
19
|
-
#include <react/renderer/components/view/ViewProps.h>
|
|
20
|
-
|
|
21
|
-
namespace margelo::nitro::yolo::views {
|
|
22
|
-
|
|
23
|
-
extern const char HybridYoloComponentName[] = "Yolo";
|
|
24
|
-
|
|
25
|
-
HybridYoloProps::HybridYoloProps(const react::PropsParserContext& context,
|
|
26
|
-
const HybridYoloProps& sourceProps,
|
|
27
|
-
const react::RawProps& rawProps):
|
|
28
|
-
react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
|
|
29
|
-
isRed([&]() -> CachedProp<bool> {
|
|
30
|
-
try {
|
|
31
|
-
const react::RawValue* rawValue = rawProps.at("isRed", nullptr, nullptr);
|
|
32
|
-
if (rawValue == nullptr) return sourceProps.isRed;
|
|
33
|
-
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
34
|
-
return CachedProp<bool>::fromRawValue(*runtime, value, sourceProps.isRed);
|
|
35
|
-
} catch (const std::exception& exc) {
|
|
36
|
-
throw std::runtime_error(std::string("Yolo.isRed: ") + exc.what());
|
|
37
|
-
}
|
|
38
|
-
}()),
|
|
39
|
-
hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridYoloSpec>& /* ref */)>>> {
|
|
40
|
-
try {
|
|
41
|
-
const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
|
|
42
|
-
if (rawValue == nullptr) return sourceProps.hybridRef;
|
|
43
|
-
const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
|
|
44
|
-
return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridYoloSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef);
|
|
45
|
-
} catch (const std::exception& exc) {
|
|
46
|
-
throw std::runtime_error(std::string("Yolo.hybridRef: ") + exc.what());
|
|
47
|
-
}
|
|
48
|
-
}()) { }
|
|
49
|
-
|
|
50
|
-
bool HybridYoloProps::filterObjectKeys(const std::string& propName) {
|
|
51
|
-
switch (hashString(propName)) {
|
|
52
|
-
case hashString("isRed"): return true;
|
|
53
|
-
case hashString("hybridRef"): return true;
|
|
54
|
-
default: return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
HybridYoloComponentDescriptor::HybridYoloComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
|
|
59
|
-
: ConcreteComponentDescriptor(parameters,
|
|
60
|
-
react::RawPropsParser(/* enableJsiParser */ true)) {}
|
|
61
|
-
|
|
62
|
-
std::shared_ptr<const react::Props> HybridYoloComponentDescriptor::cloneProps(const react::PropsParserContext& context,
|
|
63
|
-
const std::shared_ptr<const react::Props>& props,
|
|
64
|
-
react::RawProps rawProps) const {
|
|
65
|
-
// 1. Prepare raw props parser
|
|
66
|
-
rawProps.parse(rawPropsParser_);
|
|
67
|
-
// 2. Copy props with Nitro's cached copy constructor
|
|
68
|
-
return HybridYoloShadowNode::Props(context, /* & */ rawProps, props);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#ifdef ANDROID
|
|
72
|
-
void HybridYoloComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
|
|
73
|
-
// This is called immediately after `ShadowNode` is created, cloned or in progress.
|
|
74
|
-
// On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
|
|
75
|
-
auto& concreteShadowNode = static_cast<HybridYoloShadowNode&>(shadowNode);
|
|
76
|
-
const std::shared_ptr<const HybridYoloProps>& constProps = concreteShadowNode.getConcreteSharedProps();
|
|
77
|
-
const std::shared_ptr<HybridYoloProps>& props = std::const_pointer_cast<HybridYoloProps>(constProps);
|
|
78
|
-
HybridYoloState state{props};
|
|
79
|
-
concreteShadowNode.setStateData(std::move(state));
|
|
80
|
-
}
|
|
81
|
-
#endif
|
|
82
|
-
|
|
83
|
-
} // namespace margelo::nitro::yolo::views
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// HybridYoloComponent.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
|
-
#include <optional>
|
|
11
|
-
#include <NitroModules/NitroDefines.hpp>
|
|
12
|
-
#include <NitroModules/NitroHash.hpp>
|
|
13
|
-
#include <NitroModules/CachedProp.hpp>
|
|
14
|
-
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
-
#include <react/renderer/core/PropsParserContext.h>
|
|
16
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
-
#include <react/renderer/components/view/ViewProps.h>
|
|
18
|
-
|
|
19
|
-
#include <memory>
|
|
20
|
-
#include "HybridYoloSpec.hpp"
|
|
21
|
-
#include <functional>
|
|
22
|
-
#include <optional>
|
|
23
|
-
|
|
24
|
-
namespace margelo::nitro::yolo::views {
|
|
25
|
-
|
|
26
|
-
using namespace facebook;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The name of the actual native View.
|
|
30
|
-
*/
|
|
31
|
-
extern const char HybridYoloComponentName[];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Props for the "Yolo" View.
|
|
35
|
-
*/
|
|
36
|
-
class HybridYoloProps final: public react::ViewProps {
|
|
37
|
-
public:
|
|
38
|
-
HybridYoloProps() = default;
|
|
39
|
-
HybridYoloProps(const react::PropsParserContext& context,
|
|
40
|
-
const HybridYoloProps& sourceProps,
|
|
41
|
-
const react::RawProps& rawProps);
|
|
42
|
-
|
|
43
|
-
public:
|
|
44
|
-
CachedProp<bool> isRed;
|
|
45
|
-
CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridYoloSpec>& /* ref */)>>> hybridRef;
|
|
46
|
-
|
|
47
|
-
private:
|
|
48
|
-
static bool filterObjectKeys(const std::string& propName);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* State for the "Yolo" View.
|
|
53
|
-
*/
|
|
54
|
-
class HybridYoloState final {
|
|
55
|
-
public:
|
|
56
|
-
HybridYoloState() = default;
|
|
57
|
-
explicit HybridYoloState(const std::shared_ptr<HybridYoloProps>& props):
|
|
58
|
-
_props(props) {}
|
|
59
|
-
|
|
60
|
-
public:
|
|
61
|
-
[[nodiscard]]
|
|
62
|
-
const std::shared_ptr<HybridYoloProps>& getProps() const {
|
|
63
|
-
return _props;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public:
|
|
67
|
-
#ifdef ANDROID
|
|
68
|
-
HybridYoloState(const HybridYoloState& /* previousState */, folly::dynamic /* data */) {}
|
|
69
|
-
folly::dynamic getDynamic() const {
|
|
70
|
-
throw std::runtime_error("HybridYoloState does not support folly!");
|
|
71
|
-
}
|
|
72
|
-
react::MapBuffer getMapBuffer() const {
|
|
73
|
-
throw std::runtime_error("HybridYoloState does not support MapBuffer!");
|
|
74
|
-
};
|
|
75
|
-
#endif
|
|
76
|
-
|
|
77
|
-
private:
|
|
78
|
-
std::shared_ptr<HybridYoloProps> _props;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* The Shadow Node for the "Yolo" View.
|
|
83
|
-
*/
|
|
84
|
-
using HybridYoloShadowNode = react::ConcreteViewShadowNode<HybridYoloComponentName /* "HybridYolo" */,
|
|
85
|
-
HybridYoloProps /* custom props */,
|
|
86
|
-
react::ViewEventEmitter /* default */,
|
|
87
|
-
HybridYoloState /* custom state */>;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* The Component Descriptor for the "Yolo" View.
|
|
91
|
-
*/
|
|
92
|
-
class HybridYoloComponentDescriptor final: public react::ConcreteComponentDescriptor<HybridYoloShadowNode> {
|
|
93
|
-
public:
|
|
94
|
-
explicit HybridYoloComponentDescriptor(const react::ComponentDescriptorParameters& parameters);
|
|
95
|
-
|
|
96
|
-
public:
|
|
97
|
-
/**
|
|
98
|
-
* A faster path for cloning props - reuses the caching logic from `HybridYoloProps`.
|
|
99
|
-
*/
|
|
100
|
-
std::shared_ptr<const react::Props> cloneProps(const react::PropsParserContext& context,
|
|
101
|
-
const std::shared_ptr<const react::Props>& props,
|
|
102
|
-
react::RawProps rawProps) const override;
|
|
103
|
-
#ifdef ANDROID
|
|
104
|
-
void adopt(react::ShadowNode& shadowNode) const override;
|
|
105
|
-
#endif
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/* The actual view for "Yolo" needs to be implemented in platform-specific code. */
|
|
109
|
-
|
|
110
|
-
} // namespace margelo::nitro::yolo::views
|