11#include " HybridStyleRegistry.hpp"
22#include " Computed.hpp"
33#include " Observable.hpp"
4+ #include " Helpers.hpp"
45#include " ShadowTreeUpdateManager.hpp"
56#include " StyledComputedFactory.hpp"
67
@@ -55,6 +56,10 @@ namespace margelo::nitro::cssnitro {
5556
5657 void unlinkComponent (const std::string &componentId);
5758
59+ jsi::Value registerExternalMethods (jsi::Runtime &runtime,
60+ const jsi::Value &thisValue,
61+ const jsi::Value *args, size_t count);
62+
5863 private:
5964 // Per-component link info and update source
6065 struct ComponentLink {
@@ -71,18 +76,13 @@ namespace margelo::nitro::cssnitro {
7176 // Per-runtime effect (kept alive)
7277 std::unordered_map<jsi::Runtime *, std::shared_ptr<reactnativecss::Computed<bool >>> runtime_effects_;
7378
74- void ensureRuntimeEffect (jsi::Runtime &runtime);
75-
76- void applyUpdates (jsi::Runtime &runtime, const UpdatesMap &updates);
77-
78- void addUpdates (const std::string &componentId, const folly::dynamic &payload);
79-
8079 public:
8180 static std::once_flag flag_;
8281 static std::shared_ptr<Impl> inst_;
8382
8483 static std::shared_ptr<Impl> get ();
8584
85+ private:
8686 // Manager that owns per-runtime effects and updates batching
8787 std::unique_ptr<ShadowTreeUpdateManager> shadowUpdates_;
8888
@@ -145,13 +145,24 @@ namespace margelo::nitro::cssnitro {
145145 return impl_->linkComponent (runtime, thisValue, args, count);
146146 }
147147
148+ jsi::Value
149+ HybridStyleRegistry::registerExternalMethods (jsi::Runtime &runtime, const jsi::Value &thisValue,
150+ const jsi::Value *args, size_t count) {
151+ return impl_->registerExternalMethods (runtime, thisValue, args, count);
152+ }
153+
148154 void HybridStyleRegistry::loadHybridMethods () {
149155 HybridStyleRegistrySpec::loadHybridMethods ();
150156 registerHybrids (this , [](Prototype &prototype) {
151157 prototype.registerRawHybridMethod (
152158 " linkComponent" ,
153159 2 ,
154160 &HybridStyleRegistry::linkComponent);
161+
162+ prototype.registerRawHybridMethod (
163+ " registerExternalMethods" ,
164+ 1 ,
165+ &HybridStyleRegistry::registerExternalMethods);
155166 });
156167 }
157168
@@ -268,7 +279,25 @@ namespace margelo::nitro::cssnitro {
268279 shadowUpdates_->unlinkComponent (componentId);
269280 }
270281
271- // Update application is handled by ShadowTreeUpdateManager.
282+ jsi::Value HybridStyleRegistry::Impl::registerExternalMethods (
283+ jsi::Runtime &runtime, const jsi::Value &thisValue, const jsi::Value *args,
284+ size_t count) {
285+ (void ) thisValue;
286+
287+ if (!args[0 ].isObject ()) {
288+ return jsi::Value::undefined ();
289+ }
290+
291+ /* * processColor **/
292+ auto maybeProcessColorFn = args[0 ].asObject (runtime).getProperty (runtime, " processColor" );
293+ helpers::assertThat (runtime, maybeProcessColorFn.isObject (),
294+ " react-native-css: Can't load processColor function from JS." );
295+ jsi::Function processColorFn = maybeProcessColorFn.asObject (runtime).asFunction (runtime);
296+
297+ shadowUpdates_->registerProcessColorFunction (std::move (processColorFn));
298+
299+ return jsi::Value::undefined ();
300+ }
272301
273302 void HybridStyleRegistry::updateComponentInlineStyleKeys (
274303 const std::string &componentId,
0 commit comments