@rive-app/react-native 0.2.2 → 0.2.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.
- package/android/build.gradle +4 -1
- package/android/src/main/AndroidManifest.xml +2 -12
- package/android/src/main/java/com/margelo/nitro/rive/HybridRiveRuntime.kt +26 -0
- package/android/src/main/java/com/rive/RiveInitializer.kt +64 -0
- package/android/src/main/java/com/rive/RivePackage.kt +17 -10
- package/android/src/main/java/com/rive/RiveReactNativeView.kt +70 -52
- package/ios/HybridRiveRuntime.swift +11 -0
- package/ios/RiveReactNativeView.swift +17 -19
- package/lib/module/core/RiveRuntime.js +22 -0
- package/lib/module/core/RiveRuntime.js.map +1 -0
- package/lib/module/hooks/useRiveProperty.js +3 -3
- package/lib/module/hooks/useRiveProperty.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/RiveRuntime.nitro.js +4 -0
- package/lib/module/specs/RiveRuntime.nitro.js.map +1 -0
- package/lib/typescript/src/core/RiveRuntime.d.ts +8 -0
- package/lib/typescript/src/core/RiveRuntime.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useRiveProperty.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RiveRuntime.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/RiveRuntime.nitro.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JHybridRiveRuntimeSpec.cpp +82 -0
- package/nitrogen/generated/android/c++/JHybridRiveRuntimeSpec.hpp +67 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/rive/HybridRiveRuntimeSpec.kt +64 -0
- package/nitrogen/generated/android/rive+autolinking.cmake +2 -0
- package/nitrogen/generated/android/riveOnLoad.cpp +10 -0
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.cpp +25 -8
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Bridge.hpp +60 -43
- package/nitrogen/generated/ios/RNRive-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/RNRiveAutolinking.mm +8 -0
- package/nitrogen/generated/ios/RNRiveAutolinking.swift +12 -0
- package/nitrogen/generated/ios/c++/HybridRiveRuntimeSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridRiveRuntimeSpecSwift.hpp +90 -0
- package/nitrogen/generated/ios/swift/HybridRiveRuntimeSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridRiveRuntimeSpec_cxx.swift +164 -0
- package/nitrogen/generated/shared/c++/HybridRiveRuntimeSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRiveRuntimeSpec.hpp +65 -0
- package/package.json +1 -1
- package/src/core/RiveRuntime.ts +23 -0
- package/src/hooks/useRiveProperty.ts +3 -7
- package/src/index.tsx +1 -0
- package/src/specs/RiveRuntime.nitro.ts +8 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpec_cxx.swift
|
|
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 Foundation
|
|
9
|
+
import NitroModules
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A class implementation that bridges HybridRiveRuntimeSpec 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 HybridRiveRuntimeSpec_cxx {
|
|
21
|
+
/**
|
|
22
|
+
* The Swift <> C++ bridge's namespace (`margelo::nitro::rive::bridge::swift`)
|
|
23
|
+
* from `RNRive-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.rive.bridge.swift
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Holds an instance of the `HybridRiveRuntimeSpec` Swift protocol.
|
|
30
|
+
*/
|
|
31
|
+
private var __implementation: any HybridRiveRuntimeSpec
|
|
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_HybridRiveRuntimeSpec_
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create a new `HybridRiveRuntimeSpec_cxx` that wraps the given `HybridRiveRuntimeSpec`.
|
|
40
|
+
* All properties and methods bridge to C++ types.
|
|
41
|
+
*/
|
|
42
|
+
public init(_ implementation: any HybridRiveRuntimeSpec) {
|
|
43
|
+
self.__implementation = implementation
|
|
44
|
+
self.__cxxPart = .init()
|
|
45
|
+
/* no base class */
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the actual `HybridRiveRuntimeSpec` instance this class wraps.
|
|
50
|
+
*/
|
|
51
|
+
@inline(__always)
|
|
52
|
+
public func getHybridRiveRuntimeSpec() -> any HybridRiveRuntimeSpec {
|
|
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 `HybridRiveRuntimeSpec_cxx`.
|
|
66
|
+
* The pointer has to be a retained opaque `Unmanaged<HybridRiveRuntimeSpec_cxx>`.
|
|
67
|
+
* This removes one strong reference from the object!
|
|
68
|
+
*/
|
|
69
|
+
public class func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> HybridRiveRuntimeSpec_cxx {
|
|
70
|
+
return Unmanaged<HybridRiveRuntimeSpec_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<HybridRiveRuntimeSpec>`.
|
|
76
|
+
*/
|
|
77
|
+
public func getCxxPart() -> bridge.std__shared_ptr_HybridRiveRuntimeSpec_ {
|
|
78
|
+
let cachedCxxPart = self.__cxxPart.lock()
|
|
79
|
+
if Bool(fromCxx: cachedCxxPart) {
|
|
80
|
+
return cachedCxxPart
|
|
81
|
+
} else {
|
|
82
|
+
let newCxxPart = bridge.create_std__shared_ptr_HybridRiveRuntimeSpec_(self.toUnsafe())
|
|
83
|
+
__cxxPart = bridge.weakify_std__shared_ptr_HybridRiveRuntimeSpec_(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
|
+
* Compares this object with the given [other] object for reference equality.
|
|
101
|
+
*/
|
|
102
|
+
@inline(__always)
|
|
103
|
+
public func equals(other: HybridRiveRuntimeSpec_cxx) -> Bool {
|
|
104
|
+
return self.__implementation === other.__implementation
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Call dispose() on the Swift class.
|
|
109
|
+
* This _may_ be called manually from JS.
|
|
110
|
+
*/
|
|
111
|
+
@inline(__always)
|
|
112
|
+
public func dispose() {
|
|
113
|
+
self.__implementation.dispose()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Call toString() on the Swift class.
|
|
118
|
+
*/
|
|
119
|
+
@inline(__always)
|
|
120
|
+
public func toString() -> String {
|
|
121
|
+
return self.__implementation.toString()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Properties
|
|
125
|
+
public final var isInitialized: Bool {
|
|
126
|
+
@inline(__always)
|
|
127
|
+
get {
|
|
128
|
+
return self.__implementation.isInitialized
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public final var initError: bridge.std__optional_std__string_ {
|
|
133
|
+
@inline(__always)
|
|
134
|
+
get {
|
|
135
|
+
return { () -> bridge.std__optional_std__string_ in
|
|
136
|
+
if let __unwrappedValue = self.__implementation.initError {
|
|
137
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
138
|
+
} else {
|
|
139
|
+
return .init()
|
|
140
|
+
}
|
|
141
|
+
}()
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Methods
|
|
146
|
+
@inline(__always)
|
|
147
|
+
public final func initialize() -> bridge.Result_std__shared_ptr_Promise_void___ {
|
|
148
|
+
do {
|
|
149
|
+
let __result = try self.__implementation.initialize()
|
|
150
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_void__ in
|
|
151
|
+
let __promise = bridge.create_std__shared_ptr_Promise_void__()
|
|
152
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_void__(__promise)
|
|
153
|
+
__result
|
|
154
|
+
.then({ __result in __promiseHolder.resolve() })
|
|
155
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
156
|
+
return __promise
|
|
157
|
+
}()
|
|
158
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__resultCpp)
|
|
159
|
+
} catch (let __error) {
|
|
160
|
+
let __exceptionPtr = __error.toCpp()
|
|
161
|
+
return bridge.create_Result_std__shared_ptr_Promise_void___(__exceptionPtr)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpec.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 "HybridRiveRuntimeSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::rive {
|
|
11
|
+
|
|
12
|
+
void HybridRiveRuntimeSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridGetter("isInitialized", &HybridRiveRuntimeSpec::getIsInitialized);
|
|
18
|
+
prototype.registerHybridGetter("initError", &HybridRiveRuntimeSpec::getInitError);
|
|
19
|
+
prototype.registerHybridMethod("initialize", &HybridRiveRuntimeSpec::initialize);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::rive
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpec.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
|
+
#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
|
+
#include <string>
|
|
19
|
+
#include <optional>
|
|
20
|
+
#include <NitroModules/Promise.hpp>
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::rive {
|
|
23
|
+
|
|
24
|
+
using namespace margelo::nitro;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* An abstract base class for `RiveRuntime`
|
|
28
|
+
* Inherit this class to create instances of `HybridRiveRuntimeSpec` in C++.
|
|
29
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
30
|
+
* @example
|
|
31
|
+
* ```cpp
|
|
32
|
+
* class HybridRiveRuntime: public HybridRiveRuntimeSpec {
|
|
33
|
+
* public:
|
|
34
|
+
* HybridRiveRuntime(...): HybridObject(TAG) { ... }
|
|
35
|
+
* // ...
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
class HybridRiveRuntimeSpec: public virtual HybridObject {
|
|
40
|
+
public:
|
|
41
|
+
// Constructor
|
|
42
|
+
explicit HybridRiveRuntimeSpec(): HybridObject(TAG) { }
|
|
43
|
+
|
|
44
|
+
// Destructor
|
|
45
|
+
~HybridRiveRuntimeSpec() override = default;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
// Properties
|
|
49
|
+
virtual bool getIsInitialized() = 0;
|
|
50
|
+
virtual std::optional<std::string> getInitError() = 0;
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Methods
|
|
54
|
+
virtual std::shared_ptr<Promise<void>> initialize() = 0;
|
|
55
|
+
|
|
56
|
+
protected:
|
|
57
|
+
// Hybrid Setup
|
|
58
|
+
void loadHybridMethods() override;
|
|
59
|
+
|
|
60
|
+
protected:
|
|
61
|
+
// Tag for logging
|
|
62
|
+
static constexpr auto TAG = "RiveRuntime";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro::rive
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { RiveRuntime as RiveRuntimeSpec } from '../specs/RiveRuntime.nitro';
|
|
3
|
+
|
|
4
|
+
const RiveRuntimeInternal =
|
|
5
|
+
NitroModules.createHybridObject<RiveRuntimeSpec>('RiveRuntime');
|
|
6
|
+
|
|
7
|
+
export namespace RiveRuntime {
|
|
8
|
+
export async function initialize(): Promise<void> {
|
|
9
|
+
await RiveRuntimeInternal.initialize();
|
|
10
|
+
if (!RiveRuntimeInternal.isInitialized) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Rive initialization failed: ${RiveRuntimeInternal.initError ?? 'Unknown error'}`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getStatus(): { isInitialized: boolean; error?: string } {
|
|
18
|
+
return {
|
|
19
|
+
isInitialized: RiveRuntimeInternal.isInitialized,
|
|
20
|
+
error: RiveRuntimeInternal.initError ?? undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -86,15 +86,11 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
|
|
|
86
86
|
};
|
|
87
87
|
}, [options, property]);
|
|
88
88
|
|
|
89
|
-
// Set the value of the property
|
|
89
|
+
// Set the value of the property (no-op if property isn't available yet)
|
|
90
90
|
const setPropertyValue = useCallback(
|
|
91
91
|
(valueOrUpdater: T | ((prevValue: T | undefined) => T)) => {
|
|
92
92
|
if (!property) {
|
|
93
|
-
|
|
94
|
-
new Error(
|
|
95
|
-
`Cannot set value for property "${path}" because it was not found. Your view model instance may be undefined, or the path may be incorrect.`
|
|
96
|
-
)
|
|
97
|
-
);
|
|
93
|
+
return;
|
|
98
94
|
} else {
|
|
99
95
|
const newValue =
|
|
100
96
|
typeof valueOrUpdater === 'function'
|
|
@@ -105,7 +101,7 @@ export function useRiveProperty<P extends ViewModelProperty, T>(
|
|
|
105
101
|
property.value = newValue;
|
|
106
102
|
}
|
|
107
103
|
},
|
|
108
|
-
[property
|
|
104
|
+
[property]
|
|
109
105
|
);
|
|
110
106
|
|
|
111
107
|
return [value, setPropertyValue, error, property as unknown as P];
|
package/src/index.tsx
CHANGED
|
@@ -55,4 +55,5 @@ export { useViewModelInstance } from './hooks/useViewModelInstance';
|
|
|
55
55
|
export { useRiveFile } from './hooks/useRiveFile';
|
|
56
56
|
export { type RiveFileInput } from './hooks/useRiveFile';
|
|
57
57
|
export { type SetValueAction } from './types';
|
|
58
|
+
export { RiveRuntime } from './core/RiveRuntime';
|
|
58
59
|
export { DataBindMode };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
|
|
3
|
+
export interface RiveRuntime
|
|
4
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
5
|
+
initialize(): Promise<void>;
|
|
6
|
+
readonly isInitialized: boolean;
|
|
7
|
+
readonly initError: string | undefined;
|
|
8
|
+
}
|