react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.20
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/Unistyles.podspec +3 -2
- package/cxx/common/Constants.h +2 -0
- package/cxx/common/Helpers.h +97 -5
- package/cxx/core/HostStyle.cpp +19 -13
- package/cxx/core/HostStyle.h +4 -0
- package/cxx/core/StyleSheet.h +0 -2
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +7 -10
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +78 -10
- package/cxx/core/UnistylesCommitHook.cpp +22 -13
- package/cxx/core/UnistylesCommitHook.h +8 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +37 -0
- package/cxx/core/UnistylesMountHook.h +31 -0
- package/cxx/core/UnistylesRegistry.cpp +56 -81
- package/cxx/core/UnistylesRegistry.h +15 -13
- package/cxx/core/UnistylesState.cpp +14 -8
- package/cxx/core/UnistylesState.h +1 -0
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -9
- package/cxx/hybridObjects/HybridStyleSheet.cpp +43 -38
- package/cxx/hybridObjects/HybridStyleSheet.h +10 -7
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +35 -16
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +105 -164
- package/cxx/parser/Parser.h +8 -14
- package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +33 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +13 -11
- package/cxx/shadowTree/ShadowTreeManager.h +1 -0
- package/ios/Unistyles.h +1 -0
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/index.js +4 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +7 -6
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +51 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/createUnistylesComponent.js +61 -0
- package/lib/commonjs/web/createUnistylesComponent.js.map +1 -0
- package/lib/commonjs/web/index.js +60 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +20 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listenToDependencies.js +38 -0
- package/lib/commonjs/web/listener/listenToDependencies.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +35 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +28 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +10 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +50 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +163 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/shadowRegistry.js +123 -0
- package/lib/commonjs/web/shadowRegistry.js.map +1 -0
- package/lib/commonjs/web/state.js +81 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +130 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +59 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +7 -6
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +46 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/createUnistylesComponent.js +54 -0
- package/lib/module/web/createUnistylesComponent.js.map +1 -0
- package/lib/module/web/index.js +26 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +5 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listenToDependencies.js +33 -0
- package/lib/module/web/listener/listenToDependencies.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +24 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +5 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +46 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +159 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/shadowRegistry.js +119 -0
- package/lib/module/web/shadowRegistry.js.map +1 -0
- package/lib/module/web/state.js +77 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +112 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +54 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +12 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +2 -2
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
- package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/index.d.ts +14 -13
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts +3 -0
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
- package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/src/web/mock.d.ts +5 -0
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts +6 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/src/web/registry.d.ts +15 -0
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
- package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -9
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/src/web/utils.d.ts +35 -0
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
- package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
- package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
- package/package.json +3 -3
- package/plugin/__tests__/dependencies.spec.js +199 -111
- package/plugin/__tests__/ref.spec.js +638 -202
- package/plugin/__tests__/stylesheet.spec.js +182 -71
- package/plugin/index.js +110 -23
- package/plugin/ref.js +64 -13
- package/plugin/style.js +82 -22
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/index.ts +3 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +10 -9
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +2 -2
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +2 -2
- package/{web → src/web}/convert/types.ts +1 -1
- package/src/web/create.ts +50 -0
- package/src/web/createUnistylesComponent.tsx +54 -0
- package/{web → src/web}/index.ts +3 -2
- package/src/web/listener/index.ts +2 -0
- package/src/web/listener/listenToDependencies.ts +45 -0
- package/{web → src/web}/listener/listener.ts +2 -2
- package/{web → src/web}/mock.ts +2 -12
- package/src/web/pseudo.ts +137 -0
- package/src/web/registry.ts +60 -0
- package/{web → src/web}/runtime.ts +4 -6
- package/src/web/shadowRegistry.ts +124 -0
- package/{web → src/web}/state.ts +5 -49
- package/{web → src/web}/utils.ts +91 -17
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/src/web/variants/useVariants.ts +65 -0
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts +0 -2
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts +0 -14
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts +0 -4
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts +0 -12
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts +0 -18
- package/lib/typescript/web/utils.d.ts.map +0 -1
- package/web/create.ts +0 -102
- package/web/listener/index.ts +0 -1
- package/web/pseudo.ts +0 -11
- package/web/registry.ts +0 -41
- package/web/useVariants.ts +0 -99
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#include "UnistylesMountHook.h"
|
|
2
|
+
#include "ShadowTreeManager.h"
|
|
3
|
+
|
|
4
|
+
using namespace margelo::nitro::unistyles;
|
|
5
|
+
using namespace facebook::react;
|
|
6
|
+
|
|
7
|
+
core::UnistylesMountHook::~UnistylesMountHook() noexcept {
|
|
8
|
+
_uiManager->unregisterMountHook(*this);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept {
|
|
12
|
+
auto rootNode = std::const_pointer_cast<RootShadowNode>(rootShadowNode);
|
|
13
|
+
auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(rootNode);
|
|
14
|
+
|
|
15
|
+
// if this is Unistyles commit, do nothing
|
|
16
|
+
if (unistylesRootNode->hasUnistylesMountTrait()) {
|
|
17
|
+
unistylesRootNode->removeUnistylesMountTrait();
|
|
18
|
+
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// React Native commit did mount
|
|
23
|
+
auto& registry = core::UnistylesRegistry::get();
|
|
24
|
+
|
|
25
|
+
// so, resume Unistyles commits
|
|
26
|
+
registry.trafficController.resumeUnistylesTraffic();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
shadow::ShadowLeafUpdates core::UnistylesMountHook::getUnistylesUpdates() {
|
|
30
|
+
auto& registry = core::UnistylesRegistry::get();
|
|
31
|
+
auto parser = parser::Parser(this->_unistylesRuntime);
|
|
32
|
+
auto dependencyMap = registry.buildDependencyMap(*this->_rt);
|
|
33
|
+
|
|
34
|
+
// don't rebuild dependency map, at this point it's already done
|
|
35
|
+
|
|
36
|
+
return parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/uimanager/UIManager.h>
|
|
4
|
+
#include <react/renderer/uimanager/UIManagerMountHook.h>
|
|
5
|
+
#include "HybridUnistylesRuntime.h"
|
|
6
|
+
#include "Parser.h"
|
|
7
|
+
#include "ShadowTreeManager.h"
|
|
8
|
+
|
|
9
|
+
namespace margelo::nitro::unistyles::core {
|
|
10
|
+
|
|
11
|
+
using namespace facebook::react;
|
|
12
|
+
|
|
13
|
+
struct UnistylesMountHook : public UIManagerMountHook {
|
|
14
|
+
UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, jsi::Runtime& rt)
|
|
15
|
+
: _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager}, _rt{&rt} {
|
|
16
|
+
_uiManager->registerMountHook(*this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
~UnistylesMountHook() noexcept override;
|
|
20
|
+
|
|
21
|
+
void shadowTreeDidMount(RootShadowNode::Shared const &rootShadowNode, double mountTime) noexcept override;
|
|
22
|
+
|
|
23
|
+
shadow::ShadowLeafUpdates getUnistylesUpdates();
|
|
24
|
+
|
|
25
|
+
private:
|
|
26
|
+
jsi::Runtime* _rt;
|
|
27
|
+
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
|
28
|
+
std::shared_ptr<UIManager> _uiManager;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -5,11 +5,6 @@ using namespace margelo::nitro::unistyles;
|
|
|
5
5
|
using namespace facebook;
|
|
6
6
|
using namespace facebook::react;
|
|
7
7
|
|
|
8
|
-
using DependencyMap = std::unordered_map<
|
|
9
|
-
std::shared_ptr<core::StyleSheet>,
|
|
10
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>>
|
|
11
|
-
>;
|
|
12
|
-
|
|
13
8
|
void core::UnistylesRegistry::registerTheme(jsi::Runtime& rt, std::string name, jsi::Object&& theme) {
|
|
14
9
|
auto& state = this->getState(rt);
|
|
15
10
|
|
|
@@ -62,113 +57,93 @@ void core::UnistylesRegistry::createState(jsi::Runtime& rt) {
|
|
|
62
57
|
void core::UnistylesRegistry::updateTheme(jsi::Runtime& rt, std::string& themeName, jsi::Function&& callback) {
|
|
63
58
|
auto& state = this->getState(rt);
|
|
64
59
|
auto it = state._jsThemes.find(themeName);
|
|
65
|
-
|
|
66
|
-
helpers::assertThat(rt, it != state._jsThemes.end(), "
|
|
67
|
-
|
|
60
|
+
|
|
61
|
+
helpers::assertThat(rt, it != state._jsThemes.end(), "Unistyles: You're trying to update theme '" + themeName + "' but it wasn't registered.");
|
|
62
|
+
|
|
68
63
|
auto currentThemeValue = it->second.lock(rt);
|
|
69
|
-
|
|
70
|
-
helpers::assertThat(rt, currentThemeValue.isObject(), "
|
|
71
|
-
|
|
64
|
+
|
|
65
|
+
helpers::assertThat(rt, currentThemeValue.isObject(), "Unistyles: Unable to update your theme from C++. It was already garbage collected.");
|
|
66
|
+
|
|
72
67
|
auto result = callback.call(rt, currentThemeValue.asObject(rt));
|
|
73
|
-
|
|
74
|
-
helpers::assertThat(rt, result.isObject(), "
|
|
68
|
+
|
|
69
|
+
helpers::assertThat(rt, result.isObject(), "Unistyles: Returned theme is not an object. Please check your updateTheme function.");
|
|
75
70
|
|
|
76
71
|
it->second = jsi::WeakObject(rt, result.asObject(rt));
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
75
|
+
jsi::Runtime& rt,
|
|
76
|
+
const ShadowNodeFamily* shadowNodeFamily,
|
|
77
|
+
std::vector<core::Unistyle::Shared>& unistyles,
|
|
78
|
+
Variants& variants,
|
|
79
|
+
std::vector<folly::dynamic>& arguments
|
|
80
|
+
) {
|
|
81
|
+
if (!this->_shadowRegistry[&rt].contains(shadowNodeFamily)) {
|
|
82
|
+
this->_shadowRegistry[&rt][shadowNodeFamily] = {};
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
-
this->_shadowRegistry[shadowNodeFamily].emplace_back(unistyle);
|
|
85
|
-
}
|
|
86
84
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (it != unistylesVec.end()) {
|
|
92
|
-
this->_shadowRegistry[shadowNodeFamily].erase(it);
|
|
93
|
-
}
|
|
85
|
+
std::for_each(unistyles.begin(), unistyles.end(), [&, this](Unistyle::Shared unistyle){
|
|
86
|
+
this->_shadowRegistry[&rt][shadowNodeFamily].emplace_back(std::make_shared<UnistyleData>(unistyle, variants, arguments));
|
|
87
|
+
});
|
|
94
88
|
}
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
this->
|
|
98
|
-
|
|
99
|
-
return this->_styleSheetRegistry.back();
|
|
90
|
+
void core::UnistylesRegistry::unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily* shadowNodeFamily) {
|
|
91
|
+
this->_shadowRegistry[&rt][shadowNodeFamily].clear();
|
|
100
92
|
}
|
|
101
93
|
|
|
102
|
-
|
|
103
|
-
auto
|
|
104
|
-
this->_styleSheetRegistry.begin(),
|
|
105
|
-
this->_styleSheetRegistry.end(),
|
|
106
|
-
[tag](std::shared_ptr<StyleSheet> styleSheet){
|
|
107
|
-
return styleSheet->tag == tag;
|
|
108
|
-
}
|
|
109
|
-
);
|
|
94
|
+
core::Unistyle::Shared core::UnistylesRegistry::findUnistyleFromKey(jsi::Runtime& rt, std::string styleKey, int tag) {
|
|
95
|
+
auto targetStyleSheet = this->_styleSheetRegistry[&rt][tag];
|
|
110
96
|
|
|
111
|
-
if (
|
|
112
|
-
|
|
97
|
+
if (targetStyleSheet == nullptr) {
|
|
98
|
+
return nullptr;
|
|
113
99
|
}
|
|
114
100
|
|
|
115
|
-
return
|
|
101
|
+
return targetStyleSheet.get()->unistyles[styleKey];
|
|
116
102
|
}
|
|
117
|
-
|
|
118
|
-
|
|
103
|
+
|
|
104
|
+
std::shared_ptr<core::StyleSheet> core::UnistylesRegistry::addStyleSheet(jsi::Runtime& rt, int unid, core::StyleSheetType type, jsi::Object&& rawValue) {
|
|
105
|
+
this->_styleSheetRegistry[&rt][unid] = std::make_shared<core::StyleSheet>(unid, type, std::move(rawValue));
|
|
106
|
+
|
|
107
|
+
return this->_styleSheetRegistry[&rt][unid];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps) {
|
|
119
111
|
DependencyMap dependencyMap;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// that depends on something affected
|
|
112
|
+
std::set<UnistyleDependency> uniqueDependencies(deps.begin(), deps.end());
|
|
113
|
+
|
|
114
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
|
115
|
+
for (const auto& unistyleData : unistyles) {
|
|
125
116
|
bool hasAnyOfDependencies = std::any_of(
|
|
126
|
-
unistyle->dependencies.begin(),
|
|
127
|
-
unistyle->dependencies.end(),
|
|
128
|
-
[&
|
|
129
|
-
return std::find(
|
|
117
|
+
unistyleData->unistyle->dependencies.begin(),
|
|
118
|
+
unistyleData->unistyle->dependencies.end(),
|
|
119
|
+
[&uniqueDependencies](UnistyleDependency dep) {
|
|
120
|
+
return std::find(uniqueDependencies.begin(), uniqueDependencies.end(), dep) != uniqueDependencies.end();
|
|
130
121
|
}
|
|
131
122
|
);
|
|
132
|
-
|
|
123
|
+
|
|
133
124
|
if (!hasAnyOfDependencies) {
|
|
134
125
|
continue;
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
for (const auto& shadowUnistyle : unistyles) {
|
|
142
|
-
if (unistyle != shadowUnistyle) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
dependencyMap[styleSheet][family].push_back(shadowUnistyle);
|
|
147
|
-
}
|
|
127
|
+
|
|
128
|
+
// we need to take in count all unistyles from the shadowNode
|
|
129
|
+
// as user might be using spreads and not all of them may have dependencies
|
|
130
|
+
for (const auto& unistyleData : unistyles) {
|
|
131
|
+
dependencyMap[family].emplace_back(unistyleData);
|
|
148
132
|
}
|
|
133
|
+
|
|
134
|
+
break;
|
|
149
135
|
}
|
|
150
136
|
}
|
|
151
137
|
|
|
152
138
|
return dependencyMap;
|
|
153
139
|
}
|
|
154
140
|
|
|
155
|
-
DependencyMap core::UnistylesRegistry::buildDependencyMap() {
|
|
141
|
+
core::DependencyMap core::UnistylesRegistry::buildDependencyMap(jsi::Runtime& rt) {
|
|
156
142
|
DependencyMap dependencyMap;
|
|
157
|
-
|
|
158
|
-
for (const auto&
|
|
159
|
-
for (const auto&
|
|
160
|
-
|
|
161
|
-
const auto& [family, unistyles] = pair;
|
|
162
|
-
|
|
163
|
-
for (const auto& shadowUnistyle : unistyles) {
|
|
164
|
-
if (unistyle != shadowUnistyle) {
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// make sure to use base Unistyle class
|
|
169
|
-
dependencyMap[styleSheet][family].push_back(shadowUnistyle);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
143
|
+
|
|
144
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
|
145
|
+
for (const auto& unistyleData : unistyles) {
|
|
146
|
+
dependencyMap[family].emplace_back(unistyleData);
|
|
172
147
|
}
|
|
173
148
|
}
|
|
174
149
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include "set"
|
|
3
4
|
#include <jsi/jsi.h>
|
|
5
|
+
#include <folly/dynamic.h>
|
|
4
6
|
#include <react/renderer/uimanager/UIManager.h>
|
|
5
7
|
#include <unordered_map>
|
|
6
8
|
#include <unordered_set>
|
|
@@ -8,6 +10,8 @@
|
|
|
8
10
|
#include "StyleSheetRegistry.h"
|
|
9
11
|
#include "StyleSheet.h"
|
|
10
12
|
#include "Unistyle.h"
|
|
13
|
+
#include "UnistyleData.h"
|
|
14
|
+
#include "ShadowTrafficController.h"
|
|
11
15
|
|
|
12
16
|
namespace margelo::nitro::unistyles::core {
|
|
13
17
|
|
|
@@ -16,10 +20,7 @@ struct UnistylesState;
|
|
|
16
20
|
using namespace facebook;
|
|
17
21
|
using namespace facebook::react;
|
|
18
22
|
|
|
19
|
-
using DependencyMap = std::unordered_map<
|
|
20
|
-
std::shared_ptr<core::StyleSheet>,
|
|
21
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>>
|
|
22
|
-
>;
|
|
23
|
+
using DependencyMap = std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>;
|
|
23
24
|
|
|
24
25
|
struct UnistylesRegistry: public StyleSheetRegistry {
|
|
25
26
|
static UnistylesRegistry& get();
|
|
@@ -35,19 +36,20 @@ struct UnistylesRegistry: public StyleSheetRegistry {
|
|
|
35
36
|
|
|
36
37
|
UnistylesState& getState(jsi::Runtime& rt);
|
|
37
38
|
void createState(jsi::Runtime& rt);
|
|
38
|
-
void linkShadowNodeWithUnistyle(const ShadowNodeFamily*,
|
|
39
|
-
void
|
|
40
|
-
std::shared_ptr<core::StyleSheet> addStyleSheet(int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
|
41
|
-
std::
|
|
42
|
-
|
|
43
|
-
DependencyMap buildDependencyMap();
|
|
44
|
-
|
|
39
|
+
void linkShadowNodeWithUnistyle(jsi::Runtime& rt, const ShadowNodeFamily*, std::vector<core::Unistyle::Shared>& unistyles, Variants& variants, std::vector<folly::dynamic>&);
|
|
40
|
+
void unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily*);
|
|
41
|
+
std::shared_ptr<core::StyleSheet> addStyleSheet(jsi::Runtime& rt, int tag, core::StyleSheetType type, jsi::Object&& rawValue);
|
|
42
|
+
DependencyMap buildDependencyMap(jsi::Runtime& rt, std::vector<UnistyleDependency>& deps);
|
|
43
|
+
Unistyle::Shared findUnistyleFromKey(jsi::Runtime& rt, std::string styleKey, int tag);
|
|
44
|
+
DependencyMap buildDependencyMap(jsi::Runtime& rt);
|
|
45
|
+
shadow::ShadowTrafficController trafficController{};
|
|
46
|
+
|
|
45
47
|
private:
|
|
46
48
|
UnistylesRegistry() = default;
|
|
47
49
|
|
|
48
50
|
std::unordered_map<jsi::Runtime*, UnistylesState> _states{};
|
|
49
|
-
std::
|
|
50
|
-
std::unordered_map<const ShadowNodeFamily*, std::vector<
|
|
51
|
+
std::unordered_map<jsi::Runtime*, std::unordered_map<int, std::shared_ptr<core::StyleSheet>>> _styleSheetRegistry{};
|
|
52
|
+
std::unordered_map<jsi::Runtime*, std::unordered_map<const ShadowNodeFamily*, std::vector<std::shared_ptr<UnistyleData>>>> _shadowRegistry{};
|
|
51
53
|
};
|
|
52
54
|
|
|
53
55
|
UnistylesRegistry& UnistylesRegistry::get() {
|
|
@@ -12,7 +12,7 @@ bool core::UnistylesState::hasAdaptiveThemes() {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
void core::UnistylesState::setTheme(std::string themeName) {
|
|
15
|
-
helpers::assertThat(*_rt, helpers::vecContainsKeys(this->_registeredThemeNames, {themeName}), "You're trying to set theme to: '" + std::string(themeName) + "', but it wasn't registered.");
|
|
15
|
+
helpers::assertThat(*_rt, helpers::vecContainsKeys(this->_registeredThemeNames, {themeName}), "Unistyles: You're trying to set theme to: '" + std::string(themeName) + "', but it wasn't registered.");
|
|
16
16
|
|
|
17
17
|
if (themeName != this->_currentThemeName) {
|
|
18
18
|
this->_currentThemeName = themeName;
|
|
@@ -31,15 +31,15 @@ jsi::Object core::UnistylesState::getJSTheme() {
|
|
|
31
31
|
return jsi::Object(*_rt);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
helpers::assertThat(*_rt, _currentThemeName.has_value(), "
|
|
34
|
+
helpers::assertThat(*_rt, _currentThemeName.has_value(), "Unistyles: One of your stylesheets is trying to get the theme, but no theme has been selected yet. Did you forget to select an initial theme?");
|
|
35
35
|
|
|
36
36
|
auto it = this->_jsThemes.find(_currentThemeName.value());
|
|
37
37
|
|
|
38
|
-
helpers::assertThat(*_rt, it != this->_jsThemes.end(), "
|
|
38
|
+
helpers::assertThat(*_rt, it != this->_jsThemes.end(), "Unistyles: You're trying to get theme '" + _currentThemeName.value() + "', but it was not registered. Did you forget to register it with StyleSheet.configure?");
|
|
39
39
|
|
|
40
40
|
auto maybeTheme = it->second.lock(*_rt);
|
|
41
41
|
|
|
42
|
-
helpers::assertThat(*_rt, maybeTheme.isObject(), "
|
|
42
|
+
helpers::assertThat(*_rt, maybeTheme.isObject(), "Unistyles: Unable to retrieve your theme from C++ as it has already been garbage collected, likely due to multiple hot reloads. Please live reload the app.");
|
|
43
43
|
|
|
44
44
|
return maybeTheme.asObject(*_rt);
|
|
45
45
|
}
|
|
@@ -88,8 +88,14 @@ int core::UnistylesState::parseColor(jsi::Value& maybeColor) {
|
|
|
88
88
|
return 0;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
auto colorString = maybeColor.asString(*_rt);
|
|
92
|
+
|
|
93
|
+
if (!this->_colorCache.contains(colorString.utf8(*_rt).c_str())) {
|
|
94
|
+
// we must convert it to uint32_t first, otherwise color will be broken
|
|
95
|
+
uint32_t color = this->_processColorFn.get()->call(*_rt, colorString).asNumber();
|
|
96
|
+
|
|
97
|
+
this->_colorCache[colorString.utf8(*_rt).c_str()] = color ? color : 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return this->_colorCache[colorString.utf8(*_rt).c_str()];
|
|
95
101
|
}
|
|
@@ -43,6 +43,7 @@ private:
|
|
|
43
43
|
std::vector<std::string> _registeredThemeNames{};
|
|
44
44
|
std::optional<std::string> _currentThemeName = std::nullopt;
|
|
45
45
|
std::shared_ptr<jsi::Function> _processColorFn;
|
|
46
|
+
std::unordered_map<std::string, uint32_t> _colorCache{};
|
|
46
47
|
|
|
47
48
|
friend class UnistylesRegistry;
|
|
48
49
|
};
|
|
@@ -4,23 +4,29 @@ using namespace margelo::nitro::unistyles;
|
|
|
4
4
|
using namespace facebook::react;
|
|
5
5
|
|
|
6
6
|
jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
7
|
+
helpers::assertThat(rt, count == 4, "Unistyles: Invalid babel transform 'ShadowRegistry link' expected 4 arguments.");
|
|
8
|
+
|
|
7
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
|
8
|
-
core::Unistyle::Shared
|
|
9
|
-
|
|
10
|
+
std::vector<core::Unistyle::Shared> unistyleWrappers = core::unistyleFromValue(rt, args[1]);
|
|
11
|
+
core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
|
|
12
|
+
auto rawArguments = args[3].asObject(rt).asArray(rt);
|
|
13
|
+
std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
|
|
14
|
+
|
|
10
15
|
auto& registry = core::UnistylesRegistry::get();
|
|
11
|
-
|
|
12
|
-
registry.linkShadowNodeWithUnistyle(&shadowNodeWrapper->getFamily(),
|
|
13
|
-
|
|
16
|
+
|
|
17
|
+
registry.linkShadowNodeWithUnistyle(rt, &shadowNodeWrapper->getFamily(), unistyleWrappers, variants, arguments);
|
|
18
|
+
|
|
14
19
|
return jsi::Value::undefined();
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
jsi::Value HybridShadowRegistry::unlink(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
23
|
+
helpers::assertThat(rt, count == 1, "Unistyles: Invalid babel transform 'ShadowRegistry unlink' expected 1 arguments.");
|
|
24
|
+
|
|
18
25
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
|
|
21
27
|
auto& registry = core::UnistylesRegistry::get();
|
|
22
28
|
|
|
23
|
-
registry.
|
|
24
|
-
|
|
29
|
+
registry.unlinkShadowNodeWithUnistyles(rt, &shadowNodeWrapper->getFamily());
|
|
30
|
+
|
|
25
31
|
return jsi::Value::undefined();
|
|
26
32
|
}
|
|
@@ -9,27 +9,21 @@ double HybridStyleSheet::getHairlineWidth() {
|
|
|
9
9
|
return nearestPixel / pixelRatio;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
double HybridStyleSheet::
|
|
12
|
+
double HybridStyleSheet::get__unid() {
|
|
13
13
|
return this->__unid;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
jsi::Value HybridStyleSheet::create(jsi::Runtime
|
|
17
|
-
|
|
16
|
+
jsi::Value HybridStyleSheet::create(jsi::Runtime& rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
|
|
17
|
+
// second argument is hidden, so validation is perfectly fine
|
|
18
|
+
helpers::assertThat(rt, count == 2, "StyleSheet.create expected to be called with one argument.");
|
|
19
|
+
helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.create expected to be called with object or function.");
|
|
18
20
|
|
|
19
21
|
auto thisStyleSheet = thisVal.asObject(rt);
|
|
20
22
|
auto& registry = core::UnistylesRegistry::get();
|
|
21
|
-
|
|
22
|
-
// this might happen only when hot reloading
|
|
23
|
-
if (this->__unid != -1) {
|
|
24
|
-
auto registeredStyleSheet = registry.getStyleSheetById(this->__unid);
|
|
25
|
-
auto style = std::make_shared<core::HostStyle>(registeredStyleSheet, this->_unistylesRuntime);
|
|
26
|
-
auto styleHostObject = jsi::Object::createFromHostObject(rt, style);
|
|
27
|
-
|
|
28
|
-
return styleHostObject;
|
|
29
|
-
}
|
|
23
|
+
int unid = arguments[1].asNumber();
|
|
30
24
|
|
|
31
25
|
jsi::Object rawStyleSheet = arguments[0].asObject(rt);
|
|
32
|
-
auto registeredStyleSheet = registry.addStyleSheetFromValue(rt, std::move(rawStyleSheet));
|
|
26
|
+
auto registeredStyleSheet = registry.addStyleSheetFromValue(rt, std::move(rawStyleSheet), unid);
|
|
33
27
|
|
|
34
28
|
this->__unid = registeredStyleSheet->tag;
|
|
35
29
|
|
|
@@ -45,7 +39,8 @@ jsi::Value HybridStyleSheet::create(jsi::Runtime &rt, const jsi::Value &thisVal,
|
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) {
|
|
48
|
-
helpers::assertThat(rt,
|
|
42
|
+
helpers::assertThat(rt, count == 1, "StyleSheet.configure expected to be called with one argument.");
|
|
43
|
+
helpers::assertThat(rt, arguments[0].isObject(), "StyleSheet.configure expected to be called with object.");
|
|
49
44
|
|
|
50
45
|
// create new state
|
|
51
46
|
auto config = arguments[0].asObject(rt);
|
|
@@ -55,29 +50,29 @@ jsi::Value HybridStyleSheet::configure(jsi::Runtime &rt, const jsi::Value &thisV
|
|
|
55
50
|
|
|
56
51
|
helpers::enumerateJSIObject(rt, config, [&](const std::string& propertyName, jsi::Value& propertyValue){
|
|
57
52
|
if (propertyName == "settings") {
|
|
58
|
-
helpers::assertThat(rt, propertyValue.isObject(), "settings must be an object.");
|
|
53
|
+
helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's settings must be an object.");
|
|
59
54
|
|
|
60
55
|
return this->parseSettings(rt, propertyValue.asObject(rt));
|
|
61
56
|
}
|
|
62
57
|
|
|
63
58
|
if (propertyName == "breakpoints") {
|
|
64
|
-
helpers::assertThat(rt, propertyValue.isObject(), "breakpoints must be an object.");
|
|
59
|
+
helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's breakpoints must be an object.");
|
|
65
60
|
|
|
66
61
|
return this->parseBreakpoints(rt, propertyValue.asObject(rt));
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
if (propertyName == "themes") {
|
|
70
|
-
helpers::assertThat(rt, propertyValue.isObject(), "themes must be an object.");
|
|
65
|
+
helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's themes must be an object.");
|
|
71
66
|
|
|
72
67
|
return this->parseThemes(rt, propertyValue.asObject(rt));
|
|
73
68
|
}
|
|
74
69
|
|
|
75
|
-
helpers::assertThat(rt, false, "received unexpected key: '" + std::string(propertyName) + "'.");
|
|
70
|
+
helpers::assertThat(rt, false, "StyleSheet.configure received unexpected key: '" + std::string(propertyName) + "'.");
|
|
76
71
|
});
|
|
77
72
|
|
|
78
73
|
verifyAndSelectTheme(rt);
|
|
79
74
|
loadExternalMethods(thisVal, rt);
|
|
80
|
-
|
|
75
|
+
registerHooks(rt);
|
|
81
76
|
|
|
82
77
|
return jsi::Value::undefined();
|
|
83
78
|
}
|
|
@@ -87,7 +82,7 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
|
|
|
87
82
|
|
|
88
83
|
helpers::enumerateJSIObject(rt, settings, [&](const std::string& propertyName, jsi::Value& propertyValue){
|
|
89
84
|
if (propertyName == "adaptiveThemes") {
|
|
90
|
-
helpers::assertThat(rt, propertyValue.isBool(), "adaptiveThemes
|
|
85
|
+
helpers::assertThat(rt, propertyValue.isBool(), "StyleSheet.configure's adaptiveThemes must be of boolean type.");
|
|
91
86
|
|
|
92
87
|
registry.setPrefersAdaptiveThemes(rt, propertyValue.asBool());
|
|
93
88
|
|
|
@@ -96,31 +91,31 @@ void HybridStyleSheet::parseSettings(jsi::Runtime &rt, jsi::Object settings) {
|
|
|
96
91
|
|
|
97
92
|
if (propertyName == "initialTheme") {
|
|
98
93
|
if (propertyValue.isObject()) {
|
|
99
|
-
helpers::assertThat(rt, propertyValue.asObject(rt).isFunction(rt), "initialTheme
|
|
94
|
+
helpers::assertThat(rt, propertyValue.asObject(rt).isFunction(rt), "StyleSheet.configure's initialTheme must be either a string or a function.");
|
|
100
95
|
|
|
101
96
|
auto result = propertyValue.asObject(rt).asFunction(rt).call(rt);
|
|
102
97
|
|
|
103
|
-
helpers::assertThat(rt, result.isString(), "initialTheme resolved from function is not a string. Please check your initialTheme function.");
|
|
98
|
+
helpers::assertThat(rt, result.isString(), "StyleSheet.configure's initialTheme resolved from function is not a string. Please check your initialTheme function.");
|
|
104
99
|
|
|
105
100
|
return registry.setInitialThemeName(rt, result.asString(rt).utf8(rt));
|
|
106
101
|
}
|
|
107
102
|
|
|
108
|
-
helpers::assertThat(rt, propertyValue.isString(), "initialTheme
|
|
103
|
+
helpers::assertThat(rt, propertyValue.isString(), "StyleSheet.configure's initialTheme must be either a string or a function.");
|
|
109
104
|
|
|
110
105
|
registry.setInitialThemeName(rt, propertyValue.asString(rt).utf8(rt));
|
|
111
106
|
|
|
112
107
|
return;
|
|
113
108
|
}
|
|
114
109
|
|
|
115
|
-
helpers::assertThat(rt, false, "settings received unexpected key: '" + std::string(propertyName) + "'");
|
|
110
|
+
helpers::assertThat(rt, false, "StyleSheet.configure's settings received unexpected key: '" + std::string(propertyName) + "'");
|
|
116
111
|
});
|
|
117
112
|
}
|
|
118
113
|
|
|
119
114
|
void HybridStyleSheet::parseBreakpoints(jsi::Runtime &rt, jsi::Object breakpoints){
|
|
120
115
|
helpers::Breakpoints sortedBreakpoints = helpers::jsiBreakpointsToVecPairs(rt, std::move(breakpoints));
|
|
121
116
|
|
|
122
|
-
helpers::assertThat(rt, sortedBreakpoints.size() > 0, "
|
|
123
|
-
helpers::assertThat(rt, sortedBreakpoints.front().second == 0, "first breakpoint must start from 0.");
|
|
117
|
+
helpers::assertThat(rt, sortedBreakpoints.size() > 0, "StyleSheet.configure's breakpoints can't be empty.");
|
|
118
|
+
helpers::assertThat(rt, sortedBreakpoints.front().second == 0, "StyleSheet.configure's first breakpoint must start from 0.");
|
|
124
119
|
|
|
125
120
|
auto& registry = core::UnistylesRegistry::get();
|
|
126
121
|
auto& state = registry.getState(rt);
|
|
@@ -133,7 +128,7 @@ void HybridStyleSheet::parseThemes(jsi::Runtime &rt, jsi::Object themes) {
|
|
|
133
128
|
auto& registry = core::UnistylesRegistry::get();
|
|
134
129
|
|
|
135
130
|
helpers::enumerateJSIObject(rt, themes, [&](const std::string& propertyName, jsi::Value& propertyValue){
|
|
136
|
-
helpers::assertThat(rt, propertyValue.isObject(), "registered theme '" + propertyName + "' must be an object.");
|
|
131
|
+
helpers::assertThat(rt, propertyValue.isObject(), "StyleSheet.configure's registered theme '" + propertyName + "' must be an object.");
|
|
137
132
|
|
|
138
133
|
registry.registerTheme(rt, propertyName, propertyValue.asObject(rt));
|
|
139
134
|
});
|
|
@@ -151,7 +146,7 @@ void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
|
|
|
151
146
|
|
|
152
147
|
// user tries to enable adaptive themes, but didn't register both 'light' and 'dark' themes
|
|
153
148
|
if (prefersAdaptiveThemes && !hasAdaptiveThemes) {
|
|
154
|
-
helpers::assertThat(rt, false, "
|
|
149
|
+
helpers::assertThat(rt, false, "Unistyles: You're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.");
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
// user didn't select initial theme nor can have adaptive themes, and registered more than 1 theme
|
|
@@ -175,14 +170,14 @@ void HybridStyleSheet::verifyAndSelectTheme(jsi::Runtime &rt) {
|
|
|
175
170
|
// user selected both initial theme and adaptive themes
|
|
176
171
|
// we should throw an error as these options are mutually exclusive
|
|
177
172
|
if (hasInitialTheme && hasAdaptiveThemes) {
|
|
178
|
-
helpers::assertThat(rt, false, "
|
|
173
|
+
helpers::assertThat(rt, false, "Unistyles: You're trying to set initial theme and enable adaptiveThemes, but these options are mutually exclusive.");
|
|
179
174
|
}
|
|
180
175
|
|
|
181
176
|
// user only selected initial theme
|
|
182
177
|
// validate if following theme exist
|
|
183
178
|
std::string selectedTheme = state.getInitialTheme().value();
|
|
184
179
|
|
|
185
|
-
helpers::assertThat(rt, state.hasTheme(selectedTheme), "
|
|
180
|
+
helpers::assertThat(rt, state.hasTheme(selectedTheme), "Unistyles: You're trying to select theme '" + selectedTheme + "' but it wasn't registered.");
|
|
186
181
|
|
|
187
182
|
state.setTheme(selectedTheme);
|
|
188
183
|
}
|
|
@@ -201,18 +196,18 @@ void HybridStyleSheet::setThemeFromColorScheme(jsi::Runtime& rt) {
|
|
|
201
196
|
|
|
202
197
|
return;
|
|
203
198
|
default:
|
|
204
|
-
throw std::runtime_error("
|
|
199
|
+
throw std::runtime_error("Unistyles: Unable to set adaptive theme as your device doesn't support it.");
|
|
205
200
|
}
|
|
206
201
|
}
|
|
207
202
|
|
|
208
203
|
void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt) {
|
|
209
204
|
auto jsMethods = thisValue.getObject(rt).getProperty(rt, "jsMethods");
|
|
210
205
|
|
|
211
|
-
helpers::assertThat(rt, jsMethods.isObject(), "
|
|
206
|
+
helpers::assertThat(rt, jsMethods.isObject(), "Unistyles: Can't find jsMethods.");
|
|
212
207
|
|
|
213
208
|
auto maybeProcessColorFn = jsMethods.asObject(rt).getProperty(rt, "processColor");
|
|
214
209
|
|
|
215
|
-
helpers::assertThat(rt, maybeProcessColorFn.isObject(), "
|
|
210
|
+
helpers::assertThat(rt, maybeProcessColorFn.isObject(), "Unistyles: Can't load processColor function from JS.");
|
|
216
211
|
|
|
217
212
|
auto processColorFn = maybeProcessColorFn.asObject(rt).asFunction(rt);
|
|
218
213
|
auto& registry = core::UnistylesRegistry::get();
|
|
@@ -224,22 +219,32 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
|
|
|
224
219
|
void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies) {
|
|
225
220
|
auto& registry = core::UnistylesRegistry::get();
|
|
226
221
|
auto parser = parser::Parser(this->_unistylesRuntime);
|
|
227
|
-
auto dependencyMap = registry.buildDependencyMap(dependencies);
|
|
228
222
|
auto& rt = this->_unistylesRuntime->getRuntime();
|
|
229
223
|
|
|
224
|
+
// check if color scheme changed and then if Unistyles state depend on it (adaptive themes)
|
|
225
|
+
auto colorSchemeIt = std::find(dependencies.begin(), dependencies.end(), UnistyleDependency::COLORSCHEME);
|
|
226
|
+
|
|
227
|
+
if (colorSchemeIt != dependencies.end()) {
|
|
228
|
+
this->_unistylesRuntime->includeDependenciesForColorSchemeChange(dependencies);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
auto dependencyMap = registry.buildDependencyMap(rt, dependencies);
|
|
232
|
+
|
|
230
233
|
if (dependencyMap.size() == 0) {
|
|
231
234
|
return;
|
|
232
235
|
}
|
|
233
236
|
|
|
234
237
|
parser.rebuildUnistylesInDependencyMap(rt, dependencyMap);
|
|
235
238
|
|
|
239
|
+
// this is required, otherwise shadow tree will ignore Unistyles commit
|
|
240
|
+
registry.trafficController.setHasUnistylesCommit(true);
|
|
241
|
+
|
|
236
242
|
auto shadowLeafUpdates = parser.dependencyMapToShadowLeafUpdates(dependencyMap);
|
|
237
243
|
|
|
238
244
|
shadow::ShadowTreeManager::updateShadowTree(rt, shadowLeafUpdates);
|
|
239
245
|
}
|
|
240
246
|
|
|
241
|
-
void HybridStyleSheet::
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(uiManager, this->_unistylesRuntime);
|
|
247
|
+
void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
|
|
248
|
+
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager, this->_unistylesRuntime, rt);
|
|
249
|
+
this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime, rt);
|
|
245
250
|
}
|