@rive-app/react-native 0.2.3 → 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/ios/HybridRiveRuntime.swift +11 -0
- 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
|
@@ -30,6 +30,8 @@ namespace margelo::nitro::rive { class HybridRiveFileSpec; }
|
|
|
30
30
|
namespace margelo::nitro::rive { class HybridRiveImageFactorySpec; }
|
|
31
31
|
// Forward declaration of `HybridRiveImageSpec` to properly resolve imports.
|
|
32
32
|
namespace margelo::nitro::rive { class HybridRiveImageSpec; }
|
|
33
|
+
// Forward declaration of `HybridRiveRuntimeSpec` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::rive { class HybridRiveRuntimeSpec; }
|
|
33
35
|
// Forward declaration of `HybridRiveSpec` to properly resolve imports.
|
|
34
36
|
namespace margelo::nitro::rive { class HybridRiveSpec; }
|
|
35
37
|
// Forward declaration of `HybridRiveViewSpec` to properly resolve imports.
|
|
@@ -82,6 +84,8 @@ namespace RNRive { class HybridRiveFileSpec_cxx; }
|
|
|
82
84
|
namespace RNRive { class HybridRiveImageFactorySpec_cxx; }
|
|
83
85
|
// Forward declaration of `HybridRiveImageSpec_cxx` to properly resolve imports.
|
|
84
86
|
namespace RNRive { class HybridRiveImageSpec_cxx; }
|
|
87
|
+
// Forward declaration of `HybridRiveRuntimeSpec_cxx` to properly resolve imports.
|
|
88
|
+
namespace RNRive { class HybridRiveRuntimeSpec_cxx; }
|
|
85
89
|
// Forward declaration of `HybridRiveSpec_cxx` to properly resolve imports.
|
|
86
90
|
namespace RNRive { class HybridRiveSpec_cxx; }
|
|
87
91
|
// Forward declaration of `HybridRiveViewSpec_cxx` to properly resolve imports.
|
|
@@ -123,6 +127,7 @@ namespace RNRive { class HybridViewModelTriggerPropertySpec_cxx; }
|
|
|
123
127
|
#include "HybridRiveFileSpec.hpp"
|
|
124
128
|
#include "HybridRiveImageFactorySpec.hpp"
|
|
125
129
|
#include "HybridRiveImageSpec.hpp"
|
|
130
|
+
#include "HybridRiveRuntimeSpec.hpp"
|
|
126
131
|
#include "HybridRiveSpec.hpp"
|
|
127
132
|
#include "HybridRiveViewSpec.hpp"
|
|
128
133
|
#include "HybridViewModelArtboardPropertySpec.hpp"
|
|
@@ -530,6 +535,61 @@ namespace margelo::nitro::rive::bridge::swift {
|
|
|
530
535
|
return Result<std::shared_ptr<Promise<std::shared_ptr<HybridRiveImageSpec>>>>::withError(error);
|
|
531
536
|
}
|
|
532
537
|
|
|
538
|
+
// pragma MARK: std::shared_ptr<Promise<void>>
|
|
539
|
+
/**
|
|
540
|
+
* Specialized version of `std::shared_ptr<Promise<void>>`.
|
|
541
|
+
*/
|
|
542
|
+
using std__shared_ptr_Promise_void__ = std::shared_ptr<Promise<void>>;
|
|
543
|
+
inline std::shared_ptr<Promise<void>> create_std__shared_ptr_Promise_void__() noexcept {
|
|
544
|
+
return Promise<void>::create();
|
|
545
|
+
}
|
|
546
|
+
inline PromiseHolder<void> wrap_std__shared_ptr_Promise_void__(std::shared_ptr<Promise<void>> promise) noexcept {
|
|
547
|
+
return PromiseHolder<void>(std::move(promise));
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// pragma MARK: std::function<void()>
|
|
551
|
+
/**
|
|
552
|
+
* Specialized version of `std::function<void()>`.
|
|
553
|
+
*/
|
|
554
|
+
using Func_void = std::function<void()>;
|
|
555
|
+
/**
|
|
556
|
+
* Wrapper class for a `std::function<void()>`, this can be used from Swift.
|
|
557
|
+
*/
|
|
558
|
+
class Func_void_Wrapper final {
|
|
559
|
+
public:
|
|
560
|
+
explicit Func_void_Wrapper(std::function<void()>&& func): _function(std::make_unique<std::function<void()>>(std::move(func))) {}
|
|
561
|
+
inline void call() const noexcept {
|
|
562
|
+
_function->operator()();
|
|
563
|
+
}
|
|
564
|
+
private:
|
|
565
|
+
std::unique_ptr<std::function<void()>> _function;
|
|
566
|
+
} SWIFT_NONCOPYABLE;
|
|
567
|
+
Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
568
|
+
inline Func_void_Wrapper wrap_Func_void(Func_void value) noexcept {
|
|
569
|
+
return Func_void_Wrapper(std::move(value));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// pragma MARK: std::shared_ptr<HybridRiveRuntimeSpec>
|
|
573
|
+
/**
|
|
574
|
+
* Specialized version of `std::shared_ptr<HybridRiveRuntimeSpec>`.
|
|
575
|
+
*/
|
|
576
|
+
using std__shared_ptr_HybridRiveRuntimeSpec_ = std::shared_ptr<HybridRiveRuntimeSpec>;
|
|
577
|
+
std::shared_ptr<HybridRiveRuntimeSpec> create_std__shared_ptr_HybridRiveRuntimeSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
578
|
+
void* NON_NULL get_std__shared_ptr_HybridRiveRuntimeSpec_(std__shared_ptr_HybridRiveRuntimeSpec_ cppType);
|
|
579
|
+
|
|
580
|
+
// pragma MARK: std::weak_ptr<HybridRiveRuntimeSpec>
|
|
581
|
+
using std__weak_ptr_HybridRiveRuntimeSpec_ = std::weak_ptr<HybridRiveRuntimeSpec>;
|
|
582
|
+
inline std__weak_ptr_HybridRiveRuntimeSpec_ weakify_std__shared_ptr_HybridRiveRuntimeSpec_(const std::shared_ptr<HybridRiveRuntimeSpec>& strong) noexcept { return strong; }
|
|
583
|
+
|
|
584
|
+
// pragma MARK: Result<std::shared_ptr<Promise<void>>>
|
|
585
|
+
using Result_std__shared_ptr_Promise_void___ = Result<std::shared_ptr<Promise<void>>>;
|
|
586
|
+
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::shared_ptr<Promise<void>>& value) noexcept {
|
|
587
|
+
return Result<std::shared_ptr<Promise<void>>>::withValue(value);
|
|
588
|
+
}
|
|
589
|
+
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::exception_ptr& error) noexcept {
|
|
590
|
+
return Result<std::shared_ptr<Promise<void>>>::withError(error);
|
|
591
|
+
}
|
|
592
|
+
|
|
533
593
|
// pragma MARK: std::optional<bool>
|
|
534
594
|
/**
|
|
535
595
|
* Specialized version of `std::optional<bool>`.
|
|
@@ -708,40 +768,6 @@ namespace margelo::nitro::rive::bridge::swift {
|
|
|
708
768
|
return *optional;
|
|
709
769
|
}
|
|
710
770
|
|
|
711
|
-
// pragma MARK: std::shared_ptr<Promise<void>>
|
|
712
|
-
/**
|
|
713
|
-
* Specialized version of `std::shared_ptr<Promise<void>>`.
|
|
714
|
-
*/
|
|
715
|
-
using std__shared_ptr_Promise_void__ = std::shared_ptr<Promise<void>>;
|
|
716
|
-
inline std::shared_ptr<Promise<void>> create_std__shared_ptr_Promise_void__() noexcept {
|
|
717
|
-
return Promise<void>::create();
|
|
718
|
-
}
|
|
719
|
-
inline PromiseHolder<void> wrap_std__shared_ptr_Promise_void__(std::shared_ptr<Promise<void>> promise) noexcept {
|
|
720
|
-
return PromiseHolder<void>(std::move(promise));
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
// pragma MARK: std::function<void()>
|
|
724
|
-
/**
|
|
725
|
-
* Specialized version of `std::function<void()>`.
|
|
726
|
-
*/
|
|
727
|
-
using Func_void = std::function<void()>;
|
|
728
|
-
/**
|
|
729
|
-
* Wrapper class for a `std::function<void()>`, this can be used from Swift.
|
|
730
|
-
*/
|
|
731
|
-
class Func_void_Wrapper final {
|
|
732
|
-
public:
|
|
733
|
-
explicit Func_void_Wrapper(std::function<void()>&& func): _function(std::make_unique<std::function<void()>>(std::move(func))) {}
|
|
734
|
-
inline void call() const noexcept {
|
|
735
|
-
_function->operator()();
|
|
736
|
-
}
|
|
737
|
-
private:
|
|
738
|
-
std::unique_ptr<std::function<void()>> _function;
|
|
739
|
-
} SWIFT_NONCOPYABLE;
|
|
740
|
-
Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
741
|
-
inline Func_void_Wrapper wrap_Func_void(Func_void value) noexcept {
|
|
742
|
-
return Func_void_Wrapper(std::move(value));
|
|
743
|
-
}
|
|
744
|
-
|
|
745
771
|
// pragma MARK: std::variant<bool, std::string, double>
|
|
746
772
|
/**
|
|
747
773
|
* Wrapper struct for `std::variant<bool, std::string, double>`.
|
|
@@ -869,15 +895,6 @@ namespace margelo::nitro::rive::bridge::swift {
|
|
|
869
895
|
return Result<std::optional<std::shared_ptr<HybridViewModelInstanceSpec>>>::withError(error);
|
|
870
896
|
}
|
|
871
897
|
|
|
872
|
-
// pragma MARK: Result<std::shared_ptr<Promise<void>>>
|
|
873
|
-
using Result_std__shared_ptr_Promise_void___ = Result<std::shared_ptr<Promise<void>>>;
|
|
874
|
-
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::shared_ptr<Promise<void>>& value) noexcept {
|
|
875
|
-
return Result<std::shared_ptr<Promise<void>>>::withValue(value);
|
|
876
|
-
}
|
|
877
|
-
inline Result_std__shared_ptr_Promise_void___ create_Result_std__shared_ptr_Promise_void___(const std::exception_ptr& error) noexcept {
|
|
878
|
-
return Result<std::shared_ptr<Promise<void>>>::withError(error);
|
|
879
|
-
}
|
|
880
|
-
|
|
881
898
|
// pragma MARK: Result<bool>
|
|
882
899
|
using Result_bool_ = Result<bool>;
|
|
883
900
|
inline Result_bool_ create_Result_bool_(bool value) noexcept {
|
|
@@ -30,6 +30,8 @@ namespace margelo::nitro::rive { class HybridRiveFileSpec; }
|
|
|
30
30
|
namespace margelo::nitro::rive { class HybridRiveImageFactorySpec; }
|
|
31
31
|
// Forward declaration of `HybridRiveImageSpec` to properly resolve imports.
|
|
32
32
|
namespace margelo::nitro::rive { class HybridRiveImageSpec; }
|
|
33
|
+
// Forward declaration of `HybridRiveRuntimeSpec` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::rive { class HybridRiveRuntimeSpec; }
|
|
33
35
|
// Forward declaration of `HybridRiveSpec` to properly resolve imports.
|
|
34
36
|
namespace margelo::nitro::rive { class HybridRiveSpec; }
|
|
35
37
|
// Forward declaration of `HybridRiveViewSpec` to properly resolve imports.
|
|
@@ -83,6 +85,7 @@ namespace margelo::nitro::rive { struct UnifiedRiveEvent; }
|
|
|
83
85
|
#include "HybridRiveFileSpec.hpp"
|
|
84
86
|
#include "HybridRiveImageFactorySpec.hpp"
|
|
85
87
|
#include "HybridRiveImageSpec.hpp"
|
|
88
|
+
#include "HybridRiveRuntimeSpec.hpp"
|
|
86
89
|
#include "HybridRiveSpec.hpp"
|
|
87
90
|
#include "HybridRiveViewSpec.hpp"
|
|
88
91
|
#include "HybridViewModelArtboardPropertySpec.hpp"
|
|
@@ -135,6 +138,8 @@ namespace RNRive { class HybridRiveFileSpec_cxx; }
|
|
|
135
138
|
namespace RNRive { class HybridRiveImageFactorySpec_cxx; }
|
|
136
139
|
// Forward declaration of `HybridRiveImageSpec_cxx` to properly resolve imports.
|
|
137
140
|
namespace RNRive { class HybridRiveImageSpec_cxx; }
|
|
141
|
+
// Forward declaration of `HybridRiveRuntimeSpec_cxx` to properly resolve imports.
|
|
142
|
+
namespace RNRive { class HybridRiveRuntimeSpec_cxx; }
|
|
138
143
|
// Forward declaration of `HybridRiveSpec_cxx` to properly resolve imports.
|
|
139
144
|
namespace RNRive { class HybridRiveSpec_cxx; }
|
|
140
145
|
// Forward declaration of `HybridRiveViewSpec_cxx` to properly resolve imports.
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
#include "HybridRiveFileSpecSwift.hpp"
|
|
16
16
|
#include "HybridRiveViewSpecSwift.hpp"
|
|
17
17
|
#include "HybridRiveImageFactorySpecSwift.hpp"
|
|
18
|
+
#include "HybridRiveRuntimeSpecSwift.hpp"
|
|
18
19
|
|
|
19
20
|
@interface RNRiveAutolinking : NSObject
|
|
20
21
|
@end
|
|
@@ -60,6 +61,13 @@
|
|
|
60
61
|
return hybridObject;
|
|
61
62
|
}
|
|
62
63
|
);
|
|
64
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
65
|
+
"RiveRuntime",
|
|
66
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
67
|
+
std::shared_ptr<HybridRiveRuntimeSpec> hybridObject = RNRive::RNRiveAutolinking::createRiveRuntime();
|
|
68
|
+
return hybridObject;
|
|
69
|
+
}
|
|
70
|
+
);
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
@end
|
|
@@ -71,4 +71,16 @@ public final class RNRiveAutolinking {
|
|
|
71
71
|
public static func isRiveImageFactoryRecyclable() -> Bool {
|
|
72
72
|
return HybridRiveImageFactory.self is any RecyclableView.Type
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
public static func createRiveRuntime() -> bridge.std__shared_ptr_HybridRiveRuntimeSpec_ {
|
|
76
|
+
let hybridObject = HybridRiveRuntime()
|
|
77
|
+
return { () -> bridge.std__shared_ptr_HybridRiveRuntimeSpec_ in
|
|
78
|
+
let __cxxWrapped = hybridObject.getCxxWrapper()
|
|
79
|
+
return __cxxWrapped.getCxxPart()
|
|
80
|
+
}()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public static func isRiveRuntimeRecyclable() -> Bool {
|
|
84
|
+
return HybridRiveRuntime.self is any RecyclableView.Type
|
|
85
|
+
}
|
|
74
86
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpecSwift.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 "HybridRiveRuntimeSpecSwift.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::rive {
|
|
11
|
+
} // namespace margelo::nitro::rive
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpecSwift.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 "HybridRiveRuntimeSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridRiveRuntimeSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace RNRive { class HybridRiveRuntimeSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
#include <string>
|
|
18
|
+
#include <optional>
|
|
19
|
+
#include <NitroModules/Promise.hpp>
|
|
20
|
+
|
|
21
|
+
#include "RNRive-Swift-Cxx-Umbrella.hpp"
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro::rive {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The C++ part of HybridRiveRuntimeSpec_cxx.swift.
|
|
27
|
+
*
|
|
28
|
+
* HybridRiveRuntimeSpecSwift (C++) accesses HybridRiveRuntimeSpec_cxx (Swift), and might
|
|
29
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
30
|
+
*
|
|
31
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
32
|
+
* the future, HybridRiveRuntimeSpec_cxx can directly inherit from the C++ class HybridRiveRuntimeSpec
|
|
33
|
+
* to simplify the whole structure and memory management.
|
|
34
|
+
*/
|
|
35
|
+
class HybridRiveRuntimeSpecSwift: public virtual HybridRiveRuntimeSpec {
|
|
36
|
+
public:
|
|
37
|
+
// Constructor from a Swift instance
|
|
38
|
+
explicit HybridRiveRuntimeSpecSwift(const RNRive::HybridRiveRuntimeSpec_cxx& swiftPart):
|
|
39
|
+
HybridObject(HybridRiveRuntimeSpec::TAG),
|
|
40
|
+
_swiftPart(swiftPart) { }
|
|
41
|
+
|
|
42
|
+
public:
|
|
43
|
+
// Get the Swift part
|
|
44
|
+
inline RNRive::HybridRiveRuntimeSpec_cxx& getSwiftPart() noexcept {
|
|
45
|
+
return _swiftPart;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
50
|
+
return _swiftPart.getMemorySize();
|
|
51
|
+
}
|
|
52
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
53
|
+
if (auto otherCast = std::dynamic_pointer_cast<HybridRiveRuntimeSpecSwift>(other)) {
|
|
54
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
void dispose() noexcept override {
|
|
59
|
+
_swiftPart.dispose();
|
|
60
|
+
}
|
|
61
|
+
std::string toString() override {
|
|
62
|
+
return _swiftPart.toString();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
// Properties
|
|
67
|
+
inline bool getIsInitialized() noexcept override {
|
|
68
|
+
return _swiftPart.isInitialized();
|
|
69
|
+
}
|
|
70
|
+
inline std::optional<std::string> getInitError() noexcept override {
|
|
71
|
+
auto __result = _swiftPart.getInitError();
|
|
72
|
+
return __result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public:
|
|
76
|
+
// Methods
|
|
77
|
+
inline std::shared_ptr<Promise<void>> initialize() override {
|
|
78
|
+
auto __result = _swiftPart.initialize();
|
|
79
|
+
if (__result.hasError()) [[unlikely]] {
|
|
80
|
+
std::rethrow_exception(__result.error());
|
|
81
|
+
}
|
|
82
|
+
auto __value = std::move(__result.value());
|
|
83
|
+
return __value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private:
|
|
87
|
+
RNRive::HybridRiveRuntimeSpec_cxx _swiftPart;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
} // namespace margelo::nitro::rive
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridRiveRuntimeSpec.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
|
+
/// See ``HybridRiveRuntimeSpec``
|
|
12
|
+
public protocol HybridRiveRuntimeSpec_protocol: HybridObject {
|
|
13
|
+
// Properties
|
|
14
|
+
var isInitialized: Bool { get }
|
|
15
|
+
var initError: String? { get }
|
|
16
|
+
|
|
17
|
+
// Methods
|
|
18
|
+
func initialize() throws -> Promise<Void>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public extension HybridRiveRuntimeSpec_protocol {
|
|
22
|
+
/// Default implementation of ``HybridObject.toString``
|
|
23
|
+
func toString() -> String {
|
|
24
|
+
return "[HybridObject RiveRuntime]"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// See ``HybridRiveRuntimeSpec``
|
|
29
|
+
open class HybridRiveRuntimeSpec_base {
|
|
30
|
+
private weak var cxxWrapper: HybridRiveRuntimeSpec_cxx? = nil
|
|
31
|
+
public init() { }
|
|
32
|
+
public func getCxxWrapper() -> HybridRiveRuntimeSpec_cxx {
|
|
33
|
+
#if DEBUG
|
|
34
|
+
guard self is any HybridRiveRuntimeSpec else {
|
|
35
|
+
fatalError("`self` is not a `HybridRiveRuntimeSpec`! Did you accidentally inherit from `HybridRiveRuntimeSpec_base` instead of `HybridRiveRuntimeSpec`?")
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
39
|
+
return cxxWrapper
|
|
40
|
+
} else {
|
|
41
|
+
let cxxWrapper = HybridRiveRuntimeSpec_cxx(self as! any HybridRiveRuntimeSpec)
|
|
42
|
+
self.cxxWrapper = cxxWrapper
|
|
43
|
+
return cxxWrapper
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A Swift base-protocol representing the RiveRuntime HybridObject.
|
|
50
|
+
* Implement this protocol to create Swift-based instances of RiveRuntime.
|
|
51
|
+
* ```swift
|
|
52
|
+
* class HybridRiveRuntime : HybridRiveRuntimeSpec {
|
|
53
|
+
* // ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
public typealias HybridRiveRuntimeSpec = HybridRiveRuntimeSpec_protocol & HybridRiveRuntimeSpec_base
|
|
@@ -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];
|