react-native-nitro-list 0.0.1

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/NitroList.podspec +31 -0
  3. package/README.md +29 -0
  4. package/android/CMakeLists.txt +32 -0
  5. package/android/build.gradle +148 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/nitrolist/HybridNitroList.kt +27 -0
  11. package/android/src/main/java/com/nitrolist/NitroListPackage.kt +29 -0
  12. package/ios/Bridge.h +8 -0
  13. package/ios/HybridNitroList.swift +21 -0
  14. package/lib/commonjs/index.js +11 -0
  15. package/lib/commonjs/index.js.map +1 -0
  16. package/lib/commonjs/package.json +1 -0
  17. package/lib/commonjs/specs/nitro-list.nitro.js +6 -0
  18. package/lib/commonjs/specs/nitro-list.nitro.js.map +1 -0
  19. package/lib/module/index.js +6 -0
  20. package/lib/module/index.js.map +1 -0
  21. package/lib/module/specs/nitro-list.nitro.js +4 -0
  22. package/lib/module/specs/nitro-list.nitro.js.map +1 -0
  23. package/lib/typescript/src/index.d.ts +5 -0
  24. package/lib/typescript/src/index.d.ts.map +1 -0
  25. package/lib/typescript/src/specs/nitro-list.nitro.d.ts +11 -0
  26. package/lib/typescript/src/specs/nitro-list.nitro.d.ts.map +1 -0
  27. package/nitro.json +24 -0
  28. package/nitrogen/generated/.gitattributes +1 -0
  29. package/nitrogen/generated/android/NitroList+autolinking.cmake +83 -0
  30. package/nitrogen/generated/android/NitroList+autolinking.gradle +27 -0
  31. package/nitrogen/generated/android/NitroListOnLoad.cpp +46 -0
  32. package/nitrogen/generated/android/NitroListOnLoad.hpp +25 -0
  33. package/nitrogen/generated/android/c++/JHybridNitroListSpec.cpp +56 -0
  34. package/nitrogen/generated/android/c++/JHybridNitroListSpec.hpp +66 -0
  35. package/nitrogen/generated/android/c++/views/JHybridNitroListStateUpdater.cpp +56 -0
  36. package/nitrogen/generated/android/c++/views/JHybridNitroListStateUpdater.hpp +49 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/HybridNitroListSpec.kt +59 -0
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/NitroListOnLoad.kt +35 -0
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/views/HybridNitroListManager.kt +50 -0
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/views/HybridNitroListStateUpdater.kt +23 -0
  41. package/nitrogen/generated/ios/NitroList+autolinking.rb +60 -0
  42. package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.cpp +33 -0
  43. package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.hpp +40 -0
  44. package/nitrogen/generated/ios/NitroList-Swift-Cxx-Umbrella.hpp +41 -0
  45. package/nitrogen/generated/ios/NitroListAutolinking.mm +33 -0
  46. package/nitrogen/generated/ios/NitroListAutolinking.swift +25 -0
  47. package/nitrogen/generated/ios/c++/HybridNitroListSpecSwift.cpp +11 -0
  48. package/nitrogen/generated/ios/c++/HybridNitroListSpecSwift.hpp +74 -0
  49. package/nitrogen/generated/ios/c++/views/HybridNitroListComponent.mm +96 -0
  50. package/nitrogen/generated/ios/swift/HybridNitroListSpec.swift +56 -0
  51. package/nitrogen/generated/ios/swift/HybridNitroListSpec_cxx.swift +140 -0
  52. package/nitrogen/generated/shared/c++/HybridNitroListSpec.cpp +22 -0
  53. package/nitrogen/generated/shared/c++/HybridNitroListSpec.hpp +63 -0
  54. package/nitrogen/generated/shared/c++/views/HybridNitroListComponent.cpp +88 -0
  55. package/nitrogen/generated/shared/c++/views/HybridNitroListComponent.hpp +107 -0
  56. package/nitrogen/generated/shared/json/NitroListConfig.json +10 -0
  57. package/package.json +122 -0
  58. package/src/index.ts +14 -0
  59. package/src/specs/nitro-list.nitro.ts +13 -0
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// NitroListAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "NitroList-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridNitroListSpecSwift.hpp"
14
+
15
+ @interface NitroListAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroListAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::nitrolist;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "NitroList",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ std::shared_ptr<HybridNitroListSpec> hybridObject = NitroList::NitroListAutolinking::createNitroList();
28
+ return hybridObject;
29
+ }
30
+ );
31
+ }
32
+
33
+ @end
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// NitroListAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ public final class NitroListAutolinking {
9
+ public typealias bridge = margelo.nitro.nitrolist.bridge.swift
10
+
11
+ /**
12
+ * Creates an instance of a Swift class that implements `HybridNitroListSpec`,
13
+ * and wraps it in a Swift class that can directly interop with C++ (`HybridNitroListSpec_cxx`)
14
+ *
15
+ * This is generated by Nitrogen and will initialize the class specified
16
+ * in the `"autolinking"` property of `nitro.json` (in this case, `HybridNitroList`).
17
+ */
18
+ public static func createNitroList() -> bridge.std__shared_ptr_HybridNitroListSpec_ {
19
+ let hybridObject = HybridNitroList()
20
+ return { () -> bridge.std__shared_ptr_HybridNitroListSpec_ in
21
+ let __cxxWrapped = hybridObject.getCxxWrapper()
22
+ return __cxxWrapped.getCxxPart()
23
+ }()
24
+ }
25
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridNitroListSpecSwift.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridNitroListSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::nitrolist {
11
+ } // namespace margelo::nitro::nitrolist
@@ -0,0 +1,74 @@
1
+ ///
2
+ /// HybridNitroListSpecSwift.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include "HybridNitroListSpec.hpp"
11
+
12
+ // Forward declaration of `HybridNitroListSpec_cxx` to properly resolve imports.
13
+ namespace NitroList { class HybridNitroListSpec_cxx; }
14
+
15
+
16
+
17
+
18
+
19
+ #include "NitroList-Swift-Cxx-Umbrella.hpp"
20
+
21
+ namespace margelo::nitro::nitrolist {
22
+
23
+ /**
24
+ * The C++ part of HybridNitroListSpec_cxx.swift.
25
+ *
26
+ * HybridNitroListSpecSwift (C++) accesses HybridNitroListSpec_cxx (Swift), and might
27
+ * contain some additional bridging code for C++ <> Swift interop.
28
+ *
29
+ * Since this obviously introduces an overhead, I hope at some point in
30
+ * the future, HybridNitroListSpec_cxx can directly inherit from the C++ class HybridNitroListSpec
31
+ * to simplify the whole structure and memory management.
32
+ */
33
+ class HybridNitroListSpecSwift: public virtual HybridNitroListSpec {
34
+ public:
35
+ // Constructor from a Swift instance
36
+ explicit HybridNitroListSpecSwift(const NitroList::HybridNitroListSpec_cxx& swiftPart):
37
+ HybridObject(HybridNitroListSpec::TAG),
38
+ _swiftPart(swiftPart) { }
39
+
40
+ public:
41
+ // Get the Swift part
42
+ inline NitroList::HybridNitroListSpec_cxx& getSwiftPart() noexcept {
43
+ return _swiftPart;
44
+ }
45
+
46
+ public:
47
+ inline size_t getExternalMemorySize() noexcept override {
48
+ return _swiftPart.getMemorySize();
49
+ }
50
+ void dispose() noexcept override {
51
+ _swiftPart.dispose();
52
+ }
53
+ std::string toString() override {
54
+ return _swiftPart.toString();
55
+ }
56
+
57
+ public:
58
+ // Properties
59
+ inline bool getIsRed() noexcept override {
60
+ return _swiftPart.isRed();
61
+ }
62
+ inline void setIsRed(bool isRed) noexcept override {
63
+ _swiftPart.setIsRed(std::forward<decltype(isRed)>(isRed));
64
+ }
65
+
66
+ public:
67
+ // Methods
68
+
69
+
70
+ private:
71
+ NitroList::HybridNitroListSpec_cxx _swiftPart;
72
+ };
73
+
74
+ } // namespace margelo::nitro::nitrolist
@@ -0,0 +1,96 @@
1
+ ///
2
+ /// HybridNitroListComponent.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import "HybridNitroListComponent.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 "HybridNitroListSpecSwift.hpp"
18
+ #import "NitroList-Swift-Cxx-Umbrella.hpp"
19
+
20
+ using namespace facebook;
21
+ using namespace margelo::nitro::nitrolist;
22
+ using namespace margelo::nitro::nitrolist::views;
23
+
24
+ /**
25
+ * Represents the React Native View holder for the Nitro "NitroList" HybridView.
26
+ */
27
+ @interface HybridNitroListComponent: RCTViewComponentView
28
+ @end
29
+
30
+ @implementation HybridNitroListComponent {
31
+ std::shared_ptr<HybridNitroListSpecSwift> _hybridView;
32
+ }
33
+
34
+ + (void) load {
35
+ [super load];
36
+ [RCTComponentViewFactory.currentComponentViewFactory registerComponentViewClass:[HybridNitroListComponent class]];
37
+ }
38
+
39
+ + (react::ComponentDescriptorProvider) componentDescriptorProvider {
40
+ return react::concreteComponentDescriptorProvider<HybridNitroListComponentDescriptor>();
41
+ }
42
+
43
+ - (instancetype) init {
44
+ if (self = [super init]) {
45
+ std::shared_ptr<HybridNitroListSpec> hybridView = NitroList::NitroListAutolinking::createNitroList();
46
+ _hybridView = std::dynamic_pointer_cast<HybridNitroListSpecSwift>(hybridView);
47
+ [self updateView];
48
+ }
49
+ return self;
50
+ }
51
+
52
+ - (void) updateView {
53
+ // 1. Get Swift part
54
+ NitroList::HybridNitroListSpec_cxx& swiftPart = _hybridView->getSwiftPart();
55
+
56
+ // 2. Get UIView*
57
+ void* viewUnsafe = swiftPart.getView();
58
+ UIView* view = (__bridge_transfer UIView*) viewUnsafe;
59
+
60
+ // 3. Update RCTViewComponentView's [contentView]
61
+ [self setContentView:view];
62
+ }
63
+
64
+ - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
65
+ oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
66
+ // 1. Downcast props
67
+ const auto& newViewPropsConst = *std::static_pointer_cast<HybridNitroListProps const>(props);
68
+ auto& newViewProps = const_cast<HybridNitroListProps&>(newViewPropsConst);
69
+ NitroList::HybridNitroListSpec_cxx& swiftPart = _hybridView->getSwiftPart();
70
+
71
+ // 2. Update each prop individually
72
+ swiftPart.beforeUpdate();
73
+
74
+ // isRed: boolean
75
+ if (newViewProps.isRed.isDirty) {
76
+ swiftPart.setIsRed(newViewProps.isRed.value);
77
+ newViewProps.isRed.isDirty = false;
78
+ }
79
+
80
+ swiftPart.afterUpdate();
81
+
82
+ // 3. Update hybridRef if it changed
83
+ if (newViewProps.hybridRef.isDirty) {
84
+ // hybridRef changed - call it with new this
85
+ const auto& maybeFunc = newViewProps.hybridRef.value;
86
+ if (maybeFunc.has_value()) {
87
+ maybeFunc.value()(_hybridView);
88
+ }
89
+ newViewProps.hybridRef.isDirty = false;
90
+ }
91
+
92
+ // 4. Continue in base class
93
+ [super updateProps:props oldProps:oldProps];
94
+ }
95
+
96
+ @end
@@ -0,0 +1,56 @@
1
+ ///
2
+ /// HybridNitroListSpec.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /// See ``HybridNitroListSpec``
12
+ public protocol HybridNitroListSpec_protocol: HybridObject, HybridView {
13
+ // Properties
14
+ var isRed: Bool { get set }
15
+
16
+ // Methods
17
+
18
+ }
19
+
20
+ public extension HybridNitroListSpec_protocol {
21
+ /// Default implementation of ``HybridObject.toString``
22
+ func toString() -> String {
23
+ return "[HybridObject NitroList]"
24
+ }
25
+ }
26
+
27
+ /// See ``HybridNitroListSpec``
28
+ open class HybridNitroListSpec_base {
29
+ private weak var cxxWrapper: HybridNitroListSpec_cxx? = nil
30
+ public init() { }
31
+ public func getCxxWrapper() -> HybridNitroListSpec_cxx {
32
+ #if DEBUG
33
+ guard self is HybridNitroListSpec else {
34
+ fatalError("`self` is not a `HybridNitroListSpec`! Did you accidentally inherit from `HybridNitroListSpec_base` instead of `HybridNitroListSpec`?")
35
+ }
36
+ #endif
37
+ if let cxxWrapper = self.cxxWrapper {
38
+ return cxxWrapper
39
+ } else {
40
+ let cxxWrapper = HybridNitroListSpec_cxx(self as! HybridNitroListSpec)
41
+ self.cxxWrapper = cxxWrapper
42
+ return cxxWrapper
43
+ }
44
+ }
45
+ }
46
+
47
+ /**
48
+ * A Swift base-protocol representing the NitroList HybridObject.
49
+ * Implement this protocol to create Swift-based instances of NitroList.
50
+ * ```swift
51
+ * class HybridNitroList : HybridNitroListSpec {
52
+ * // ...
53
+ * }
54
+ * ```
55
+ */
56
+ public typealias HybridNitroListSpec = HybridNitroListSpec_protocol & HybridNitroListSpec_base
@@ -0,0 +1,140 @@
1
+ ///
2
+ /// HybridNitroListSpec_cxx.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import Foundation
9
+ import NitroModules
10
+
11
+ /**
12
+ * A class implementation that bridges HybridNitroListSpec over to C++.
13
+ * In C++, we cannot use Swift protocols - so we need to wrap it in a class to make it strongly defined.
14
+ *
15
+ * Also, some Swift types need to be bridged with special handling:
16
+ * - Enums need to be wrapped in Structs, otherwise they cannot be accessed bi-directionally (Swift bug: https://github.com/swiftlang/swift/issues/75330)
17
+ * - Other HybridObjects need to be wrapped/unwrapped from the Swift TCxx wrapper
18
+ * - Throwing methods need to be wrapped with a Result<T, Error> type, as exceptions cannot be propagated to C++
19
+ */
20
+ open class HybridNitroListSpec_cxx {
21
+ /**
22
+ * The Swift <> C++ bridge's namespace (`margelo::nitro::nitrolist::bridge::swift`)
23
+ * from `NitroList-Swift-Cxx-Bridge.hpp`.
24
+ * This contains specialized C++ templates, and C++ helper functions that can be accessed from Swift.
25
+ */
26
+ public typealias bridge = margelo.nitro.nitrolist.bridge.swift
27
+
28
+ /**
29
+ * Holds an instance of the `HybridNitroListSpec` Swift protocol.
30
+ */
31
+ private var __implementation: any HybridNitroListSpec
32
+
33
+ /**
34
+ * Holds a weak pointer to the C++ class that wraps the Swift class.
35
+ */
36
+ private var __cxxPart: bridge.std__weak_ptr_HybridNitroListSpec_
37
+
38
+ /**
39
+ * Create a new `HybridNitroListSpec_cxx` that wraps the given `HybridNitroListSpec`.
40
+ * All properties and methods bridge to C++ types.
41
+ */
42
+ public init(_ implementation: any HybridNitroListSpec) {
43
+ self.__implementation = implementation
44
+ self.__cxxPart = .init()
45
+ /* no base class */
46
+ }
47
+
48
+ /**
49
+ * Get the actual `HybridNitroListSpec` instance this class wraps.
50
+ */
51
+ @inline(__always)
52
+ public func getHybridNitroListSpec() -> any HybridNitroListSpec {
53
+ return __implementation
54
+ }
55
+
56
+ /**
57
+ * Casts this instance to a retained unsafe raw pointer.
58
+ * This acquires one additional strong reference on the object!
59
+ */
60
+ public func toUnsafe() -> UnsafeMutableRawPointer {
61
+ return Unmanaged.passRetained(self).toOpaque()
62
+ }
63
+
64
+ /**
65
+ * Casts an unsafe pointer to a `HybridNitroListSpec_cxx`.
66
+ * The pointer has to be a retained opaque `Unmanaged<HybridNitroListSpec_cxx>`.
67
+ * This removes one strong reference from the object!
68
+ */
69
+ public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridNitroListSpec_cxx {
70
+ return Unmanaged<HybridNitroListSpec_cxx>.fromOpaque(pointer).takeRetainedValue()
71
+ }
72
+
73
+ /**
74
+ * Gets (or creates) the C++ part of this Hybrid Object.
75
+ * The C++ part is a `std::shared_ptr<HybridNitroListSpec>`.
76
+ */
77
+ public func getCxxPart() -> bridge.std__shared_ptr_HybridNitroListSpec_ {
78
+ let cachedCxxPart = self.__cxxPart.lock()
79
+ if Bool(fromCxx: cachedCxxPart) {
80
+ return cachedCxxPart
81
+ } else {
82
+ let newCxxPart = bridge.create_std__shared_ptr_HybridNitroListSpec_(self.toUnsafe())
83
+ __cxxPart = bridge.weakify_std__shared_ptr_HybridNitroListSpec_(newCxxPart)
84
+ return newCxxPart
85
+ }
86
+ }
87
+
88
+
89
+
90
+ /**
91
+ * Get the memory size of the Swift class (plus size of any other allocations)
92
+ * so the JS VM can properly track it and garbage-collect the JS object if needed.
93
+ */
94
+ @inline(__always)
95
+ public var memorySize: Int {
96
+ return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
97
+ }
98
+
99
+ /**
100
+ * Call dispose() on the Swift class.
101
+ * This _may_ be called manually from JS.
102
+ */
103
+ @inline(__always)
104
+ public func dispose() {
105
+ self.__implementation.dispose()
106
+ }
107
+
108
+ /**
109
+ * Call toString() on the Swift class.
110
+ */
111
+ @inline(__always)
112
+ public func toString() -> String {
113
+ return self.__implementation.toString()
114
+ }
115
+
116
+ // Properties
117
+ public final var isRed: Bool {
118
+ @inline(__always)
119
+ get {
120
+ return self.__implementation.isRed
121
+ }
122
+ @inline(__always)
123
+ set {
124
+ self.__implementation.isRed = newValue
125
+ }
126
+ }
127
+
128
+ // Methods
129
+ public final func getView() -> UnsafeMutableRawPointer {
130
+ return Unmanaged.passRetained(__implementation.view).toOpaque()
131
+ }
132
+
133
+ public final func beforeUpdate() {
134
+ __implementation.beforeUpdate()
135
+ }
136
+
137
+ public final func afterUpdate() {
138
+ __implementation.afterUpdate()
139
+ }
140
+ }
@@ -0,0 +1,22 @@
1
+ ///
2
+ /// HybridNitroListSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridNitroListSpec.hpp"
9
+
10
+ namespace margelo::nitro::nitrolist {
11
+
12
+ void HybridNitroListSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridGetter("isRed", &HybridNitroListSpec::getIsRed);
18
+ prototype.registerHybridSetter("isRed", &HybridNitroListSpec::setIsRed);
19
+ });
20
+ }
21
+
22
+ } // namespace margelo::nitro::nitrolist
@@ -0,0 +1,63 @@
1
+ ///
2
+ /// HybridNitroListSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+
19
+
20
+ namespace margelo::nitro::nitrolist {
21
+
22
+ using namespace margelo::nitro;
23
+
24
+ /**
25
+ * An abstract base class for `NitroList`
26
+ * Inherit this class to create instances of `HybridNitroListSpec` in C++.
27
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
28
+ * @example
29
+ * ```cpp
30
+ * class HybridNitroList: public HybridNitroListSpec {
31
+ * public:
32
+ * HybridNitroList(...): HybridObject(TAG) { ... }
33
+ * // ...
34
+ * };
35
+ * ```
36
+ */
37
+ class HybridNitroListSpec: public virtual HybridObject {
38
+ public:
39
+ // Constructor
40
+ explicit HybridNitroListSpec(): HybridObject(TAG) { }
41
+
42
+ // Destructor
43
+ ~HybridNitroListSpec() override = default;
44
+
45
+ public:
46
+ // Properties
47
+ virtual bool getIsRed() = 0;
48
+ virtual void setIsRed(bool isRed) = 0;
49
+
50
+ public:
51
+ // Methods
52
+
53
+
54
+ protected:
55
+ // Hybrid Setup
56
+ void loadHybridMethods() override;
57
+
58
+ protected:
59
+ // Tag for logging
60
+ static constexpr auto TAG = "NitroList";
61
+ };
62
+
63
+ } // namespace margelo::nitro::nitrolist
@@ -0,0 +1,88 @@
1
+ ///
2
+ /// HybridNitroListComponent.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridNitroListComponent.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::nitrolist::views {
22
+
23
+ extern const char HybridNitroListComponentName[] = "NitroList";
24
+
25
+ HybridNitroListProps::HybridNitroListProps(const react::PropsParserContext& context,
26
+ const HybridNitroListProps& 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("NitroList.isRed: ") + exc.what());
37
+ }
38
+ }()),
39
+ hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridNitroListSpec>& /* 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<HybridNitroListSpec>& /* 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("NitroList.hybridRef: ") + exc.what());
47
+ }
48
+ }()) { }
49
+
50
+ HybridNitroListProps::HybridNitroListProps(const HybridNitroListProps& other):
51
+ react::ViewProps(),
52
+ isRed(other.isRed),
53
+ hybridRef(other.hybridRef) { }
54
+
55
+ bool HybridNitroListProps::filterObjectKeys(const std::string& propName) {
56
+ switch (hashString(propName)) {
57
+ case hashString("isRed"): return true;
58
+ case hashString("hybridRef"): return true;
59
+ default: return false;
60
+ }
61
+ }
62
+
63
+ HybridNitroListComponentDescriptor::HybridNitroListComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
64
+ : ConcreteComponentDescriptor(parameters,
65
+ react::RawPropsParser(/* enableJsiParser */ true)) {}
66
+
67
+ std::shared_ptr<const react::Props> HybridNitroListComponentDescriptor::cloneProps(const react::PropsParserContext& context,
68
+ const std::shared_ptr<const react::Props>& props,
69
+ react::RawProps rawProps) const {
70
+ // 1. Prepare raw props parser
71
+ rawProps.parse(rawPropsParser_);
72
+ // 2. Copy props with Nitro's cached copy constructor
73
+ return HybridNitroListShadowNode::Props(context, /* & */ rawProps, props);
74
+ }
75
+
76
+ #ifdef ANDROID
77
+ void HybridNitroListComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
78
+ // This is called immediately after `ShadowNode` is created, cloned or in progress.
79
+ // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
80
+ auto& concreteShadowNode = dynamic_cast<HybridNitroListShadowNode&>(shadowNode);
81
+ const HybridNitroListProps& props = concreteShadowNode.getConcreteProps();
82
+ HybridNitroListState state;
83
+ state.setProps(props);
84
+ concreteShadowNode.setStateData(std::move(state));
85
+ }
86
+ #endif
87
+
88
+ } // namespace margelo::nitro::nitrolist::views