react-native-nitro-modules 0.20.1 → 0.22.0
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/NitroModules.podspec +4 -1
- package/README.md +1 -1
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +4 -2
- package/android/gradle.properties +2 -2
- package/android/src/main/cpp/platform/ThreadUtils.cpp +4 -4
- package/android/src/main/cpp/registry/JHybridObjectRegistry.hpp +2 -0
- package/android/src/main/java/com/margelo/nitro/core/ArrayBuffer.kt +29 -8
- package/android/src/main/java/com/margelo/nitro/core/HybridObject.kt +11 -10
- package/android/src/main/java/com/margelo/nitro/core/HybridObjectInitializer.java +4 -0
- package/android/src/main/java/com/margelo/nitro/core/HybridObjectRegistry.java +2 -0
- package/android/src/main/java/com/margelo/nitro/views/HybridView.kt +23 -0
- package/cpp/core/ArrayBuffer.cpp +16 -1
- package/cpp/core/ArrayBuffer.hpp +20 -1
- package/cpp/core/HybridFunction.hpp +1 -1
- package/cpp/core/HybridObject.cpp +7 -6
- package/cpp/core/HybridObject.hpp +2 -2
- package/cpp/core/Promise.hpp +1 -1
- package/cpp/entrypoint/HybridNitroModulesProxy.cpp +8 -0
- package/cpp/entrypoint/HybridNitroModulesProxy.hpp +1 -0
- package/cpp/jsi/JSICache.cpp +1 -0
- package/cpp/jsi/JSICache.hpp +6 -0
- package/cpp/jsi/JSIConverter+Exception.hpp +1 -1
- package/cpp/jsi/JSIConverter+HostObject.hpp +1 -1
- package/cpp/jsi/JSIConverter+HybridObject.hpp +1 -1
- package/cpp/jsi/JSIConverter+Tuple.hpp +1 -1
- package/cpp/jsi/JSIConverter+Variant.hpp +1 -1
- package/cpp/jsi/JSIHelpers.hpp +1 -1
- package/cpp/prototype/HybridObjectPrototype.cpp +1 -1
- package/cpp/registry/HybridObjectRegistry.cpp +25 -12
- package/cpp/registry/HybridObjectRegistry.hpp +1 -0
- package/cpp/utils/AssertPromiseState.hpp +1 -1
- package/cpp/utils/BorrowingReference.hpp +4 -2
- package/cpp/utils/NitroDefines.hpp +13 -1
- package/cpp/utils/NitroHash.hpp +17 -0
- package/cpp/utils/{TypeInfo.hpp → NitroTypeInfo.hpp} +1 -1
- package/cpp/utils/OwningReference.hpp +15 -2
- package/cpp/views/CachedProp.hpp +43 -0
- package/ios/core/ArrayBufferHolder.hpp +3 -3
- package/ios/core/ArrayBufferHolder.swift +97 -9
- package/ios/core/HybridContext.hpp +1 -1
- package/ios/core/{HybridObjectSpec.swift → HybridObject.swift} +10 -2
- package/ios/core/PromiseHolder.hpp +1 -1
- package/ios/utils/RuntimeError.hpp +1 -1
- package/ios/views/HybridView.swift +41 -0
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/views/HybridView.js +17 -0
- package/lib/commonjs/views/HybridView.js.map +1 -0
- package/lib/commonjs/views/getHostComponent.js +22 -0
- package/lib/commonjs/views/getHostComponent.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/views/HybridView.js +30 -0
- package/lib/module/views/HybridView.js.map +1 -0
- package/lib/module/views/getHostComponent.js +15 -0
- package/lib/module/views/getHostComponent.js.map +1 -0
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/NitroModulesProxy.d.ts +7 -0
- package/lib/typescript/NitroModulesProxy.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/views/HybridView.d.ts +35 -0
- package/lib/typescript/views/HybridView.d.ts.map +1 -0
- package/lib/typescript/views/getHostComponent.d.ts +13 -0
- package/lib/typescript/views/getHostComponent.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/NitroModulesProxy.ts +8 -0
- package/src/index.ts +1 -0
- package/src/views/HybridView.ts +37 -0
- package/src/views/getHostComponent.ts +26 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
#define NitroDefines_h
|
|
10
10
|
|
|
11
11
|
// Sets the version of the native Nitro core library
|
|
12
|
-
#define NITRO_VERSION "0.
|
|
12
|
+
#define NITRO_VERSION "0.22.0"
|
|
13
13
|
|
|
14
14
|
// Sets whether to use debug or optimized production build flags
|
|
15
15
|
#ifdef DEBUG
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
#define _CXX_INTEROP_HAS_ATTRIBUTE(x) 0
|
|
32
32
|
#endif
|
|
33
33
|
|
|
34
|
+
// Closed/Final Enums
|
|
34
35
|
#if _CXX_INTEROP_HAS_ATTRIBUTE(enum_extensibility)
|
|
35
36
|
// Enum is marked as closed/not extensible
|
|
36
37
|
#define CLOSED_ENUM __attribute__((enum_extensibility(closed)))
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
#define CLOSED_ENUM
|
|
39
40
|
#endif
|
|
40
41
|
|
|
42
|
+
// Swift Support
|
|
41
43
|
#if __has_include(<swift/bridging>)
|
|
42
44
|
// Swift's bridging header defines those things
|
|
43
45
|
#include <swift/bridging>
|
|
@@ -50,4 +52,14 @@
|
|
|
50
52
|
#define SWIFT_NONCOPYABLE
|
|
51
53
|
#endif
|
|
52
54
|
|
|
55
|
+
// React Native Support
|
|
56
|
+
#if __has_include(<cxxreact/ReactNativeVersion.h>)
|
|
57
|
+
#include <cxxreact/ReactNativeVersion.h>
|
|
58
|
+
#endif
|
|
59
|
+
#ifndef REACT_NATIVE_VERSION_MINOR
|
|
60
|
+
#define REACT_NATIVE_VERSION_MAJOR 0
|
|
61
|
+
#define REACT_NATIVE_VERSION_MINOR 0
|
|
62
|
+
#define REACT_NATIVE_VERSION_PATCH 0
|
|
63
|
+
#endif
|
|
64
|
+
|
|
53
65
|
#endif /* NitroDefines_h */
|
package/cpp/utils/NitroHash.hpp
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
#include <cstddef>
|
|
11
11
|
#include <cstdint>
|
|
12
|
+
#include <string>
|
|
12
13
|
|
|
13
14
|
namespace margelo::nitro {
|
|
14
15
|
|
|
@@ -40,4 +41,20 @@ constexpr uint64_t hashString(const char (&str)[N]) {
|
|
|
40
41
|
return hashString(str, N - 1); // N includes the null terminator, so subtract 1
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Hashes the given `string_view` using the FNV-1a hashing algorithm.
|
|
46
|
+
* This can be constexpr.
|
|
47
|
+
*/
|
|
48
|
+
constexpr uint64_t hashString(const std::string_view& string) {
|
|
49
|
+
return hashString(string.data(), string.length());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Hashes the given `string` using the FNV-1a hashing algorithm.
|
|
54
|
+
* This happens at runtime.
|
|
55
|
+
*/
|
|
56
|
+
inline uint64_t hashString(const std::string& string) {
|
|
57
|
+
return hashString(string.c_str(), string.length());
|
|
58
|
+
}
|
|
59
|
+
|
|
43
60
|
} // namespace margelo::nitro
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
#include "BorrowingReference.hpp"
|
|
11
|
+
#include "NitroDefines.hpp"
|
|
11
12
|
#include "OwningLock.hpp"
|
|
12
13
|
#include <atomic>
|
|
13
14
|
#include <cstddef>
|
|
@@ -39,8 +40,10 @@ public:
|
|
|
39
40
|
OwningReference(const OwningReference& ref)
|
|
40
41
|
: _value(ref._value), _isDeleted(ref._isDeleted), _strongRefCount(ref._strongRefCount), _weakRefCount(ref._weakRefCount),
|
|
41
42
|
_mutex(ref._mutex) {
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (_strongRefCount != nullptr) {
|
|
44
|
+
// increment ref count after copy
|
|
45
|
+
(*_strongRefCount)++;
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
OwningReference(OwningReference&& ref)
|
|
@@ -161,10 +164,20 @@ public:
|
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
inline T& operator*() const {
|
|
167
|
+
#ifdef NITRO_DEBUG
|
|
168
|
+
if (!hasValue()) [[unlikely]] {
|
|
169
|
+
throw std::runtime_error("Tried to dereference (*) nullptr OwningReference<T>!");
|
|
170
|
+
}
|
|
171
|
+
#endif
|
|
164
172
|
return *_value;
|
|
165
173
|
}
|
|
166
174
|
|
|
167
175
|
inline T* operator->() const {
|
|
176
|
+
#ifdef NITRO_DEBUG
|
|
177
|
+
if (!hasValue()) [[unlikely]] {
|
|
178
|
+
throw std::runtime_error("Tried to dereference (->) nullptr OwningReference<T>!");
|
|
179
|
+
}
|
|
180
|
+
#endif
|
|
168
181
|
return _value;
|
|
169
182
|
}
|
|
170
183
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Marc Rousavy on 30.07.24.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "JSIConverter.hpp"
|
|
8
|
+
#include "NitroDefines.hpp"
|
|
9
|
+
#include "OwningReference.hpp"
|
|
10
|
+
#include <jsi/jsi.h>
|
|
11
|
+
|
|
12
|
+
namespace margelo::nitro {
|
|
13
|
+
|
|
14
|
+
using namespace facebook;
|
|
15
|
+
|
|
16
|
+
template <typename T>
|
|
17
|
+
struct CachedProp {
|
|
18
|
+
public:
|
|
19
|
+
T value;
|
|
20
|
+
OwningReference<jsi::Value> jsiValue;
|
|
21
|
+
bool isDirty = false;
|
|
22
|
+
|
|
23
|
+
public:
|
|
24
|
+
bool equals(jsi::Runtime& runtime, const jsi::Value& other) const {
|
|
25
|
+
if (!jsiValue)
|
|
26
|
+
return false;
|
|
27
|
+
return jsi::Value::strictEquals(runtime, *jsiValue, other);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
static CachedProp<T> fromRawValue(jsi::Runtime& runtime, const jsi::Value& value, const CachedProp<T>& oldProp) {
|
|
32
|
+
if (oldProp.equals(runtime, value)) {
|
|
33
|
+
// jsi::Value hasn't changed - no need to convert it again!
|
|
34
|
+
return oldProp;
|
|
35
|
+
}
|
|
36
|
+
T converted = JSIConverter<T>::fromJSI(runtime, value);
|
|
37
|
+
JSICacheReference cache = JSICache::getOrCreateCache(runtime);
|
|
38
|
+
OwningReference<jsi::Value> cached = cache.makeShared(jsi::Value(runtime, value));
|
|
39
|
+
return CachedProp<T>(std::move(converted), std::move(cached), /* isDirty */ true);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
} // namespace margelo::nitro
|
|
@@ -35,9 +35,9 @@ public:
|
|
|
35
35
|
* Once the `ArrayBuffer` is no longer in use, the given `deleteFunc` will be called with the given `deleteFuncContext`
|
|
36
36
|
* as an argument. The caller is responsible for deleting `data` once this is called.
|
|
37
37
|
*/
|
|
38
|
-
static ArrayBufferHolder
|
|
38
|
+
static ArrayBufferHolder wrap(uint8_t* _Nonnull data, size_t size, SwiftClosure destroy) {
|
|
39
39
|
std::function<void()> deleteFunc = destroy.getFunction();
|
|
40
|
-
auto arrayBuffer = ArrayBuffer::
|
|
40
|
+
auto arrayBuffer = ArrayBuffer::wrap(data, size, std::move(deleteFunc));
|
|
41
41
|
return ArrayBufferHolder(arrayBuffer);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -45,7 +45,7 @@ public:
|
|
|
45
45
|
/**
|
|
46
46
|
* Gets the raw bytes the underlying `ArrayBuffer` points to.
|
|
47
47
|
*/
|
|
48
|
-
|
|
48
|
+
uint8_t* _Nonnull getData() const SWIFT_COMPUTED_PROPERTY {
|
|
49
49
|
return _arrayBuffer->data();
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
@@ -15,6 +15,8 @@ import Foundation
|
|
|
15
15
|
*/
|
|
16
16
|
public typealias ArrayBufferHolder = margelo.nitro.ArrayBufferHolder
|
|
17
17
|
|
|
18
|
+
// pragma MARK: Wrap
|
|
19
|
+
|
|
18
20
|
public extension ArrayBufferHolder {
|
|
19
21
|
/**
|
|
20
22
|
* Create a new `ArrayBufferHolder` that wraps the given `data` of the given `size`
|
|
@@ -28,9 +30,27 @@ public extension ArrayBufferHolder {
|
|
|
28
30
|
// Convert escaping Swift closure to a `void*`
|
|
29
31
|
let swiftClosure = SwiftClosure(wrappingClosure: delete)
|
|
30
32
|
// Create ArrayBufferHolder with our wrapped Swift closure to make it callable as a C-function pointer
|
|
31
|
-
return ArrayBufferHolder.
|
|
33
|
+
return ArrayBufferHolder.wrap(data, size, swiftClosure)
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Create a new `ArrayBufferHolder` that wraps the given `data` of the given `size`
|
|
38
|
+
* without performing a copy.
|
|
39
|
+
* When the `ArrayBuffer` is no longer used, `onDelete` will be called, in which
|
|
40
|
+
* you as a caller are responsible for deleting `data`.
|
|
41
|
+
*/
|
|
42
|
+
static func wrap(dataWithoutCopy data: UnsafeMutableRawPointer,
|
|
43
|
+
size: Int,
|
|
44
|
+
onDelete delete: @escaping () -> Void) -> ArrayBufferHolder {
|
|
45
|
+
return ArrayBufferHolder.wrap(dataWithoutCopy: data.assumingMemoryBound(to: UInt8.self),
|
|
46
|
+
size: size,
|
|
47
|
+
onDelete: delete)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// pragma MARK: Allocate
|
|
52
|
+
|
|
53
|
+
public extension ArrayBufferHolder {
|
|
34
54
|
/**
|
|
35
55
|
* Allocate a new buffer of the given `size`.
|
|
36
56
|
* If `initializeToZero` is `true`, all bytes are set to `0`, otherwise they are left untouched.
|
|
@@ -40,24 +60,92 @@ public extension ArrayBufferHolder {
|
|
|
40
60
|
if initializeToZero {
|
|
41
61
|
data.initialize(repeating: 0, count: size)
|
|
42
62
|
}
|
|
43
|
-
|
|
44
63
|
let deleteFunc = SwiftClosure {
|
|
45
64
|
data.deallocate()
|
|
46
65
|
}
|
|
47
|
-
return ArrayBufferHolder.
|
|
66
|
+
return ArrayBufferHolder.wrap(data, size, deleteFunc)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// pragma MARK: Copy
|
|
71
|
+
|
|
72
|
+
public extension ArrayBufferHolder {
|
|
73
|
+
/**
|
|
74
|
+
* Copy the given `UnsafeMutablePointer<UInt8>` into a new **owning** `ArrayBufferHolder`.
|
|
75
|
+
*/
|
|
76
|
+
static func copy(of other: UnsafeMutablePointer<UInt8>,
|
|
77
|
+
size: Int) -> ArrayBufferHolder {
|
|
78
|
+
// 1. Create new `UnsafeMutablePointer<UInt8>`
|
|
79
|
+
let copy = UnsafeMutablePointer<UInt8>.allocate(capacity: size)
|
|
80
|
+
// 2. Copy over data
|
|
81
|
+
copy.initialize(from: other, count: size)
|
|
82
|
+
// 3. Create memory safe destroyer
|
|
83
|
+
let deleteFunc = SwiftClosure {
|
|
84
|
+
copy.deallocate()
|
|
85
|
+
}
|
|
86
|
+
return ArrayBufferHolder.wrap(copy, size, deleteFunc)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Copy the given `UnsafeMutableRawPointer` into a new **owning** `ArrayBufferHolder`.
|
|
91
|
+
*/
|
|
92
|
+
static func copy(of other: UnsafeMutableRawPointer,
|
|
93
|
+
size: Int) -> ArrayBufferHolder {
|
|
94
|
+
return ArrayBufferHolder.copy(of: other.assumingMemoryBound(to: UInt8.self),
|
|
95
|
+
size: size)
|
|
48
96
|
}
|
|
49
97
|
|
|
50
98
|
/**
|
|
51
99
|
* Copy the given `ArrayBufferHolder` into a new **owning** `ArrayBufferHolder`.
|
|
52
100
|
*/
|
|
53
101
|
static func copy(of other: ArrayBufferHolder) -> ArrayBufferHolder {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
data.initialize(from: pointer, count: other.size)
|
|
102
|
+
return ArrayBufferHolder.copy(of: other.data, size: other.size)
|
|
103
|
+
}
|
|
57
104
|
|
|
58
|
-
|
|
59
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Copy the given `Data` into a new **owning** `ArrayBufferHolder`.
|
|
107
|
+
*/
|
|
108
|
+
static func copy(data: Data) throws -> ArrayBufferHolder {
|
|
109
|
+
// 1. Create new `ArrayBuffer` of same size
|
|
110
|
+
let size = data.count
|
|
111
|
+
let arrayBuffer = ArrayBufferHolder.allocate(size: size)
|
|
112
|
+
// 2. Copy all bytes from `Data` into our new `ArrayBuffer`
|
|
113
|
+
try data.withUnsafeBytes { rawPointer in
|
|
114
|
+
guard let baseAddress = rawPointer.baseAddress else {
|
|
115
|
+
throw RuntimeError.error(withMessage: "Cannot get baseAddress of Data!")
|
|
116
|
+
}
|
|
117
|
+
memcpy(arrayBuffer.data, baseAddress, size)
|
|
118
|
+
}
|
|
119
|
+
return arrayBuffer
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
// pragma MARK: Data
|
|
125
|
+
|
|
126
|
+
public extension ArrayBufferHolder {
|
|
127
|
+
/**
|
|
128
|
+
* Wrap this `ArrayBufferHolder` in a `Data` instance, without performing a copy.
|
|
129
|
+
* - `copyIfNeeded`: If this `ArrayBuffer` is **non-owning**, the foreign
|
|
130
|
+
* data may needs to be copied to be safely used outside of the scope of the caller function.
|
|
131
|
+
* This flag controls that.
|
|
132
|
+
*/
|
|
133
|
+
func toData(copyIfNeeded: Bool) -> Data {
|
|
134
|
+
let shouldCopy = copyIfNeeded && !self.isOwner
|
|
135
|
+
if shouldCopy {
|
|
136
|
+
// COPY DATA
|
|
137
|
+
return Data.init(bytes: self.data, count: self.size)
|
|
138
|
+
} else {
|
|
139
|
+
// WRAP DATA
|
|
140
|
+
// 1. Get the std::shared_ptr<ArrayBuffer>
|
|
141
|
+
var sharedPointer = self.getArrayBuffer()
|
|
142
|
+
// 2. Create a Data object WRAPPING our pointer
|
|
143
|
+
return Data(bytesNoCopy: self.data, count: self.size, deallocator: .custom({ buffer, size in
|
|
144
|
+
// 3. Capture the std::shared_ptr<ArrayBuffer> in the deallocator lambda so it stays alive.
|
|
145
|
+
// As soon as this lambda gets called, the `sharedPointer` gets deleted causing the
|
|
146
|
+
// underlying `ArrayBuffer` to be freed.
|
|
147
|
+
sharedPointer.reset()
|
|
148
|
+
}))
|
|
60
149
|
}
|
|
61
|
-
return ArrayBufferHolder.makeBuffer(data, other.size, deleteFunc)
|
|
62
150
|
}
|
|
63
151
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//
|
|
2
|
-
//
|
|
2
|
+
// HybridObject.swift
|
|
3
3
|
// NitroModules
|
|
4
4
|
//
|
|
5
5
|
// Created by Marc Rousavy on 23.07.24.
|
|
@@ -10,7 +10,7 @@ import Foundation
|
|
|
10
10
|
/**
|
|
11
11
|
* A base protocol for all Swift-based Hybrid Objects.
|
|
12
12
|
*/
|
|
13
|
-
public protocol
|
|
13
|
+
public protocol HybridObject: AnyObject {
|
|
14
14
|
/**
|
|
15
15
|
* Get the memory size of the Swift instance (plus any external heap allocations),
|
|
16
16
|
* in bytes.
|
|
@@ -29,6 +29,14 @@ public protocol HybridObjectSpec: AnyObject {
|
|
|
29
29
|
var memorySize: Int { get }
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
public extension HybridObject {
|
|
33
|
+
// By default, this returns `0`.
|
|
34
|
+
var memorySize: Int { return 0 }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@available(*, deprecated, message: "HybridObjectSpec has been renamed to HybridObject. Update Nitrogen and re-generate your specs.")
|
|
38
|
+
public typealias HybridObjectSpec = HybridObject
|
|
39
|
+
|
|
32
40
|
public extension HybridObjectSpec {
|
|
33
41
|
@available(*, deprecated, message: "getSizeOf(...) will now be default-computed. Please remove getSizeOf() from your code.")
|
|
34
42
|
func getSizeOf<T: AnyObject>(_ instance: T) -> Int {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//
|
|
2
|
+
// HybridView.swift
|
|
3
|
+
// NitroModules
|
|
4
|
+
//
|
|
5
|
+
// Created by Marc Rousavy on 13.01.25.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#if canImport(UIKit)
|
|
9
|
+
|
|
10
|
+
import Foundation
|
|
11
|
+
import UIKit
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A base protocol for all Swift-based Hybrid Views.
|
|
15
|
+
*/
|
|
16
|
+
public protocol HybridView: HybridObject {
|
|
17
|
+
/**
|
|
18
|
+
* Get the ``UIView`` this HybridView is holding.
|
|
19
|
+
*
|
|
20
|
+
* This value should not change during the lifetime of this ``HybridView``.
|
|
21
|
+
*/
|
|
22
|
+
var view: UIView { get }
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Called right before updating props.
|
|
26
|
+
* React props are updated in a single batch/transaction.
|
|
27
|
+
*/
|
|
28
|
+
func beforeUpdate()
|
|
29
|
+
/**
|
|
30
|
+
* Called right after updating props.
|
|
31
|
+
* React props are updated in a single batch/transaction.
|
|
32
|
+
*/
|
|
33
|
+
func afterUpdate()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public extension HybridView {
|
|
37
|
+
func beforeUpdate() { /* noop */ }
|
|
38
|
+
func afterUpdate() { /* noop */ }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#endif
|
package/lib/commonjs/index.js
CHANGED
|
@@ -47,4 +47,15 @@ Object.keys(_Constructor).forEach(function (key) {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
});
|
|
50
|
+
var _HybridView = require("./views/HybridView");
|
|
51
|
+
Object.keys(_HybridView).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _HybridView[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _HybridView[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
50
61
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_HybridObject","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get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WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,YAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,YAAA,CAAAP,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_HybridObject","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_NitroModules","_AnyMap","_Constructor","_HybridView"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,aAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,aAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,aAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,aAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,aAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,aAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,OAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,YAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,YAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,YAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,YAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,WAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,WAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,WAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,WAAA,CAAAR,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _getHostComponent = require("./getHostComponent");
|
|
7
|
+
Object.keys(_getHostComponent).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _getHostComponent[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _getHostComponent[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=HybridView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_getHostComponent","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get"],"sourceRoot":"../../../src","sources":["views/HybridView.ts"],"mappings":";;;;;AAoCA,IAAAA,iBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,iBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,iBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,iBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getHostComponent = getHostComponent;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var NativeComponentRegistry = _interopRequireWildcard(require("react-native/Libraries/NativeComponent/NativeComponentRegistry"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
// @ts-expect-error this unfortunately isn't typed or default-exported.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Finds and returns a native view (aka {@linkcode HostComponent}) via the given {@linkcode name}.
|
|
15
|
+
*/
|
|
16
|
+
function getHostComponent(name, getViewConfig) {
|
|
17
|
+
if (NativeComponentRegistry == null) {
|
|
18
|
+
throw new Error(`NativeComponentRegistry is not available on ${_reactNative.Platform.OS}!`);
|
|
19
|
+
}
|
|
20
|
+
return NativeComponentRegistry.get(name, getViewConfig);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=getHostComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","NativeComponentRegistry","_interopRequireWildcard","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getHostComponent","name","getViewConfig","Error","Platform","OS"],"sourceRoot":"../../../src","sources":["views/getHostComponent.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAyG,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAF,wBAAAE,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IA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A,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,UAAU;AACxB,cAAc,eAAe","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,cAAc,gBAAgB;AAC9B,cAAc,gBAAgB;AAC9B,cAAc,UAAU;AACxB,cAAc,eAAe;AAC7B,cAAc,oBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Describes the languages this view will be implemented in.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents a Nitro `HybridView` which is implemented in a native language
|
|
9
|
+
* like Swift or Kotlin.
|
|
10
|
+
*
|
|
11
|
+
* `HybridViews`s use the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.
|
|
12
|
+
*
|
|
13
|
+
* All `HybridViews`s have a C++ Fabric View base with a backing Shadow Node.
|
|
14
|
+
*
|
|
15
|
+
* - TypeScript Properties (`name: Type`) will be React Props
|
|
16
|
+
* - TypeScript Methods (`name(): Type`) will be Ref Methods
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* export interface Camera extends HybridView {
|
|
21
|
+
* zoom: number
|
|
22
|
+
* flash: boolean
|
|
23
|
+
* takePhoto(): Image
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export * from './getHostComponent';
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=HybridView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["views/HybridView.ts"],"mappings":";;AAEA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,cAAc,oBAAoB;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
// @ts-expect-error this unfortunately isn't typed or default-exported.
|
|
5
|
+
import * as NativeComponentRegistry from 'react-native/Libraries/NativeComponent/NativeComponentRegistry';
|
|
6
|
+
/**
|
|
7
|
+
* Finds and returns a native view (aka {@linkcode HostComponent}) via the given {@linkcode name}.
|
|
8
|
+
*/
|
|
9
|
+
export function getHostComponent(name, getViewConfig) {
|
|
10
|
+
if (NativeComponentRegistry == null) {
|
|
11
|
+
throw new Error(`NativeComponentRegistry is not available on ${Platform.OS}!`);
|
|
12
|
+
}
|
|
13
|
+
return NativeComponentRegistry.get(name, getViewConfig);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getHostComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Platform","NativeComponentRegistry","getHostComponent","name","getViewConfig","Error","OS","get"],"sourceRoot":"../../../src","sources":["views/getHostComponent.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAA4B,cAAc;AAC3D;AACA,OAAO,KAAKC,uBAAuB,MAAM,gEAAgE;AAUzG;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,IAAY,EACZC,aAAsC,EAChB;EACtB,IAAIH,uBAAuB,IAAI,IAAI,EAAE;IACnC,MAAM,IAAII,KAAK,CACb,+CAA+CL,QAAQ,CAACM,EAAE,GAC5D,CAAC;EACH;EACA,OAAOL,uBAAuB,CAACM,GAAG,CAAQJ,IAAI,EAAEC,aAAa,CAAC;AAChE","ignoreList":[]}
|