|
6 | 6 | #include <vector> |
7 | 7 |
|
8 | 8 | #include <folly/dynamic.h> |
9 | | -#include <react/renderer/core/ReactPrimitives.h> // facebook::react::Tag |
10 | | -#include <jsi/jsi.h> |
| 9 | +#include <react/renderer/core/ReactPrimitives.h> |
11 | 10 |
|
12 | | -#include "Observable.hpp" |
13 | | -#include "Effect.hpp" |
| 11 | +namespace facebook::jsi { |
| 12 | + class Runtime; |
14 | 13 |
|
15 | | -// Forward declarations for Nitro Any types |
16 | | -namespace margelo { |
17 | | - namespace nitro { |
18 | | - class AnyMap; |
19 | | - } |
| 14 | + class Function; |
20 | 15 | } |
21 | 16 |
|
22 | | -// Provide a convenient alias matching React Native's JSI namespace |
23 | | -namespace jsi = facebook::jsi; |
| 17 | +namespace reactnativecss { |
| 18 | + template<typename T> |
| 19 | + class Observable; |
| 20 | + |
| 21 | + class Effect; |
| 22 | +} |
24 | 23 |
|
25 | | -namespace margelo { |
26 | | - namespace nitro { |
27 | | - namespace cssnitro { |
| 24 | +namespace margelo::nitro { class AnyMap; } |
| 25 | + |
| 26 | +namespace jsi = facebook::jsi; |
28 | 27 |
|
29 | | - struct VariantConverter; // forward decl for friend |
| 28 | +namespace margelo::nitro::cssnitro { |
30 | 29 |
|
31 | | - class ShadowTreeUpdateManager final { |
32 | | - public: |
33 | | - using UpdatesMap = std::unordered_map<facebook::react::Tag, folly::dynamic>; |
| 30 | + struct VariantConverter; |
34 | 31 |
|
35 | | - ShadowTreeUpdateManager(); |
| 32 | + class ShadowTreeUpdateManager final { |
| 33 | + public: |
| 34 | + using UpdatesMap = std::unordered_map<facebook::react::Tag, folly::dynamic>; |
36 | 35 |
|
37 | | - void linkComponent(jsi::Runtime &runtime, |
38 | | - const std::string &componentId, |
39 | | - facebook::react::Tag tag); |
| 36 | + ShadowTreeUpdateManager(); |
40 | 37 |
|
41 | | - void unlinkComponent(const std::string &componentId); |
| 38 | + void linkComponent(jsi::Runtime &runtime, |
| 39 | + const std::string &componentId, |
| 40 | + facebook::react::Tag tag); |
42 | 41 |
|
43 | | - // Accept the style entries from Styled.next.style and convert internally |
44 | | - void addUpdates(const std::string &componentId, |
45 | | - const std::vector<std::shared_ptr<::margelo::nitro::AnyMap>> &styleEntries); |
| 42 | + void unlinkComponent(const std::string &componentId); |
46 | 43 |
|
47 | | - void registerProcessColorFunction(jsi::Function &&fn); |
| 44 | + void addUpdates(const std::string &componentId, |
| 45 | + const std::vector<std::shared_ptr<::margelo::nitro::AnyMap>> &styleEntries); |
48 | 46 |
|
49 | | - private: |
50 | | - friend struct VariantConverter; |
51 | | - struct ComponentLink { |
52 | | - facebook::react::Tag tag{0}; |
53 | | - jsi::Runtime *runtime{nullptr}; |
54 | | - }; |
| 47 | + void registerProcessColorFunction(jsi::Function &&fn); |
55 | 48 |
|
56 | | - std::shared_ptr<jsi::Function> process_color_; |
57 | | - // Cache for processed color strings -> int result |
58 | | - std::unordered_map<std::string, int> process_color_cache_; |
| 49 | + private: |
| 50 | + friend struct VariantConverter; |
| 51 | + struct ComponentLink { |
| 52 | + facebook::react::Tag tag{0}; |
| 53 | + jsi::Runtime *runtime{nullptr}; |
| 54 | + }; |
59 | 55 |
|
60 | | - // componentId -> {tag, runtime*} |
61 | | - std::unordered_map<std::string, ComponentLink> component_links_; |
| 56 | + std::shared_ptr<jsi::Function> process_color_; |
| 57 | + std::unordered_map<std::string, int> process_color_cache_; |
62 | 58 |
|
63 | | - // Per-runtime updates observable/effect |
64 | | - std::unordered_map<jsi::Runtime *, std::shared_ptr<reactnativecss::Observable<UpdatesMap>>> runtime_updates_; |
| 59 | + std::unordered_map<std::string, ComponentLink> component_links_; |
65 | 60 |
|
66 | | - struct RuntimeEffectHolder { |
67 | | - std::shared_ptr<reactnativecss::Effect> effect; |
68 | | - }; |
69 | | - std::unordered_map<jsi::Runtime *, std::shared_ptr<RuntimeEffectHolder>> runtime_effects_; |
| 61 | + std::unordered_map<jsi::Runtime *, std::shared_ptr<reactnativecss::Observable<UpdatesMap>>> runtime_updates_; |
70 | 62 |
|
71 | | - void ensureRuntimeEffect(jsi::Runtime &runtime); |
| 63 | + // Keep one effect per runtime |
| 64 | + std::unordered_map<jsi::Runtime *, std::shared_ptr<reactnativecss::Effect>> runtime_effects_; |
72 | 65 |
|
73 | | - static void applyUpdates(jsi::Runtime &runtime, const UpdatesMap &updates); |
| 66 | + void ensureRuntimeEffect(jsi::Runtime &runtime); |
74 | 67 |
|
75 | | - // String color processing (with caching) |
76 | | - folly::dynamic |
77 | | - processColorDynamic(jsi::Runtime &runtime, const folly::dynamic &value); |
| 68 | + static void applyUpdates(jsi::Runtime &runtime, const UpdatesMap &updates); |
78 | 69 |
|
79 | | - // styleEntryToUpdate was inlined into addUpdates |
80 | | - }; |
| 70 | + // String color processing (with caching) |
| 71 | + folly::dynamic |
| 72 | + processColorDynamic(jsi::Runtime &runtime, const folly::dynamic &value); |
81 | 73 |
|
82 | | - } |
83 | | - } |
| 74 | + // styleEntryToUpdate was inlined into addUpdates |
| 75 | + }; |
84 | 76 | } // namespace margelo::nitro::cssnitro |
0 commit comments