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
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
#include "Parser.h"
|
|
12
12
|
#include "ShadowTreeManager.h"
|
|
13
13
|
#include "UnistylesCommitHook.h"
|
|
14
|
+
#include "UnistylesMountHook.h"
|
|
14
15
|
|
|
15
16
|
using namespace margelo::nitro::unistyles;
|
|
16
17
|
using namespace facebook::react;
|
|
17
18
|
|
|
18
19
|
struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
|
|
19
|
-
HybridStyleSheet(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
HybridStyleSheet(std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, std::shared_ptr<UIManager> uiManager)
|
|
21
|
+
: HybridObject(TAG), _unistylesRuntime{unistylesRuntime}, _uiManager{uiManager} {
|
|
22
|
+
this->_unistylesRuntime->registerPlatformListener(
|
|
23
|
+
std::bind(&HybridStyleSheet::onPlatformDependenciesChange, this, std::placeholders::_1)
|
|
24
|
+
);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
jsi::Value create(jsi::Runtime& rt,
|
|
@@ -42,7 +43,7 @@ struct HybridStyleSheet: public HybridUnistylesStyleSheetSpec {
|
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
double getHairlineWidth() override;
|
|
45
|
-
double
|
|
46
|
+
double get__unid() override;
|
|
46
47
|
|
|
47
48
|
private:
|
|
48
49
|
void parseSettings(jsi::Runtime& rt, jsi::Object settings);
|
|
@@ -51,11 +52,13 @@ private:
|
|
|
51
52
|
void verifyAndSelectTheme(jsi::Runtime &rt);
|
|
52
53
|
void setThemeFromColorScheme(jsi::Runtime& rt);
|
|
53
54
|
void loadExternalMethods(const jsi::Value& thisValue, jsi::Runtime& rt);
|
|
55
|
+
void registerHooks(jsi::Runtime& rt);
|
|
54
56
|
void onPlatformDependenciesChange(std::vector<UnistyleDependency> dependencies);
|
|
55
|
-
void registerCommitHook(jsi::Runtime& rt);
|
|
56
57
|
|
|
57
58
|
double __unid = -1;
|
|
58
59
|
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
|
59
60
|
std::shared_ptr<core::UnistylesCommitHook> _unistylesCommitHook;
|
|
61
|
+
std::shared_ptr<core::UnistylesMountHook> _unistylesMountHook;
|
|
62
|
+
std::shared_ptr<UIManager> _uiManager;
|
|
60
63
|
};
|
|
61
64
|
|
|
@@ -45,7 +45,7 @@ Insets HybridUnistylesRuntime::getInsets() {
|
|
|
45
45
|
|
|
46
46
|
Orientation HybridUnistylesRuntime::getOrientation() {
|
|
47
47
|
int orientation = this->_nativePlatform.getOrientation();
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
return static_cast<Orientation>(orientation);
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -58,7 +58,7 @@ double HybridUnistylesRuntime::getFontScale() {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
|
|
61
|
-
helpers::assertThat(*_rt, !this->getHasAdaptiveThemes(), "You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
|
|
61
|
+
helpers::assertThat(*_rt, !this->getHasAdaptiveThemes(), "Unistyles: You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
|
|
62
62
|
|
|
63
63
|
auto& state = core::UnistylesRegistry::get().getState(*_rt);
|
|
64
64
|
|
|
@@ -68,14 +68,17 @@ void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
|
|
|
68
68
|
|
|
69
69
|
void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
70
70
|
auto& registry = core::UnistylesRegistry::get();
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
std::vector<UnistyleDependency> changedDependencies{};
|
|
73
|
+
|
|
74
|
+
changedDependencies.reserve(3);
|
|
75
|
+
|
|
73
76
|
bool hadAdaptiveThemes = this->getHasAdaptiveThemes();
|
|
74
77
|
|
|
75
78
|
registry.setPrefersAdaptiveThemes(*_rt, isEnabled);
|
|
76
|
-
|
|
79
|
+
|
|
77
80
|
bool haveAdaptiveThemes = this->getHasAdaptiveThemes();
|
|
78
|
-
|
|
81
|
+
|
|
79
82
|
if (hadAdaptiveThemes != haveAdaptiveThemes) {
|
|
80
83
|
changedDependencies.push_back(UnistyleDependency::ADAPTIVETHEMES);
|
|
81
84
|
}
|
|
@@ -83,12 +86,17 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
|
83
86
|
// if user disabled it, or can't have adaptive themes, do nothing
|
|
84
87
|
if (!this->getHasAdaptiveThemes()) {
|
|
85
88
|
this->_onDependenciesChange(changedDependencies);
|
|
86
|
-
|
|
89
|
+
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
93
|
// if user enabled adaptive themes, then we need to make sure
|
|
91
94
|
// we selected theme based on color scheme
|
|
95
|
+
this->calculateNewThemeAndDependencies(changedDependencies);
|
|
96
|
+
this->_onDependenciesChange(changedDependencies);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
void HybridUnistylesRuntime::calculateNewThemeAndDependencies(std::vector<UnistyleDependency>& changedDependencies) {
|
|
92
100
|
auto& state = core::UnistylesRegistry::get().getState(*_rt);
|
|
93
101
|
auto colorScheme = this->getColorScheme();
|
|
94
102
|
auto currentThemeName = this->getThemeName();
|
|
@@ -99,24 +107,23 @@ void HybridUnistylesRuntime::setAdaptiveThemes(bool isEnabled) {
|
|
|
99
107
|
if (!currentThemeName.has_value() || nextTheme != currentThemeName.value()) {
|
|
100
108
|
changedDependencies.push_back(UnistyleDependency::THEME);
|
|
101
109
|
changedDependencies.push_back(UnistyleDependency::THEMENAME);
|
|
102
|
-
|
|
110
|
+
|
|
103
111
|
state.setTheme(nextTheme);
|
|
104
112
|
}
|
|
105
|
-
|
|
106
|
-
this->_onDependenciesChange(changedDependencies);
|
|
107
|
-
};
|
|
113
|
+
}
|
|
108
114
|
|
|
109
115
|
jsi::Value HybridUnistylesRuntime::updateTheme(jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) {
|
|
110
|
-
helpers::assertThat(rt,
|
|
111
|
-
helpers::assertThat(rt, args[
|
|
116
|
+
helpers::assertThat(rt, count == 2, "UnistylesRuntime.updateTheme expected to be called with 2 arguments.");
|
|
117
|
+
helpers::assertThat(rt, args[0].isString(), "UnistylesRuntime.updateTheme expected first argument to be a string.");
|
|
118
|
+
helpers::assertThat(rt, args[1].isObject(), "UnistylesRuntime.updateTheme expected first argument to be a function.");
|
|
112
119
|
|
|
113
120
|
auto& registry = core::UnistylesRegistry::get();
|
|
114
121
|
auto themeName = args[0].asString(rt).utf8(rt);
|
|
115
122
|
|
|
116
|
-
helpers::assertThat(rt, args[1].asObject(rt).isFunction(rt), "second argument
|
|
123
|
+
helpers::assertThat(rt, args[1].asObject(rt).isFunction(rt), "UnistylesRuntime.updateTheme expected second argument to be a function.");
|
|
117
124
|
|
|
118
125
|
registry.updateTheme(rt, themeName, args[1].asObject(rt).asFunction(rt));
|
|
119
|
-
|
|
126
|
+
|
|
120
127
|
this->_onDependenciesChange({UnistyleDependency::THEME});
|
|
121
128
|
|
|
122
129
|
return jsi::Value::undefined();
|
|
@@ -163,7 +170,7 @@ UnistylesCxxMiniRuntime HybridUnistylesRuntime::getMiniRuntime() {
|
|
|
163
170
|
nativeMiniRuntime.statusBar,
|
|
164
171
|
nativeMiniRuntime.navigationBar
|
|
165
172
|
};
|
|
166
|
-
|
|
173
|
+
|
|
167
174
|
return cxxMiniRuntime;
|
|
168
175
|
}
|
|
169
176
|
|
|
@@ -185,7 +192,7 @@ jsi::Value HybridUnistylesRuntime::getMiniRuntimeAsValue(jsi::Runtime& rt) {
|
|
|
185
192
|
obj.setProperty(rt, "rtl", JSIConverter<bool>::toJSI(rt, miniRuntime.rtl));
|
|
186
193
|
obj.setProperty(rt, "statusBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.statusBar));
|
|
187
194
|
obj.setProperty(rt, "navigationBar", JSIConverter<Dimensions>::toJSI(rt, miniRuntime.navigationBar));
|
|
188
|
-
|
|
195
|
+
|
|
189
196
|
return obj;
|
|
190
197
|
}
|
|
191
198
|
|
|
@@ -197,3 +204,15 @@ void HybridUnistylesRuntime::registerPlatformListener(const std::function<void(s
|
|
|
197
204
|
this->_nativePlatform.registerPlatformListener(listener);
|
|
198
205
|
this->_onDependenciesChange = listener;
|
|
199
206
|
}
|
|
207
|
+
|
|
208
|
+
void HybridUnistylesRuntime::includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps) {
|
|
209
|
+
auto& registry = core::UnistylesRegistry::get();
|
|
210
|
+
auto& state = registry.getState(*this->_rt);
|
|
211
|
+
|
|
212
|
+
// ignore color scheme changes if user has no adaptive themes
|
|
213
|
+
if (!state.hasAdaptiveThemes()) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this->calculateNewThemeAndDependencies(deps);
|
|
218
|
+
}
|
|
@@ -58,6 +58,8 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
|
58
58
|
UnistylesCxxMiniRuntime getMiniRuntime() override;
|
|
59
59
|
jsi::Value getMiniRuntimeAsValue(jsi::Runtime& rt);
|
|
60
60
|
jsi::Runtime& getRuntime();
|
|
61
|
+
void includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps);
|
|
62
|
+
void calculateNewThemeAndDependencies(std::vector<UnistyleDependency>& deps);
|
|
61
63
|
|
|
62
64
|
private:
|
|
63
65
|
jsi::Runtime* _rt;
|
package/cxx/parser/Parser.cpp
CHANGED
|
@@ -11,7 +11,7 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
|
11
11
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet);
|
|
12
12
|
|
|
13
13
|
helpers::enumerateJSIObject(rt, unwrappedStyleSheet, [&](const std::string& styleKey, jsi::Value& propertyValue){
|
|
14
|
-
helpers::assertThat(rt, propertyValue.isObject(), "
|
|
14
|
+
helpers::assertThat(rt, propertyValue.isObject(), "Unistyles: Style with name '" + styleKey + "' is not a function or object.");
|
|
15
15
|
|
|
16
16
|
jsi::Object styleValue = propertyValue.asObject(rt);
|
|
17
17
|
|
|
@@ -20,7 +20,8 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
|
20
20
|
styleSheet->unistyles[styleKey] = std::make_shared<UnistyleDynamicFunction>(
|
|
21
21
|
UnistyleType::DynamicFunction,
|
|
22
22
|
styleKey,
|
|
23
|
-
styleValue
|
|
23
|
+
styleValue,
|
|
24
|
+
styleSheet
|
|
24
25
|
);
|
|
25
26
|
|
|
26
27
|
return;
|
|
@@ -29,7 +30,8 @@ void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
|
29
30
|
styleSheet->unistyles[styleKey] = std::make_shared<Unistyle>(
|
|
30
31
|
UnistyleType::Object,
|
|
31
32
|
styleKey,
|
|
32
|
-
styleValue
|
|
33
|
+
styleValue,
|
|
34
|
+
styleSheet
|
|
33
35
|
);
|
|
34
36
|
});
|
|
35
37
|
}
|
|
@@ -68,14 +70,14 @@ jsi::Object parser::Parser::unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<S
|
|
|
68
70
|
void parser::Parser::parseUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet) {
|
|
69
71
|
for (const auto& [_, unistyle] : styleSheet->unistyles) {
|
|
70
72
|
if (unistyle->type == core::UnistyleType::Object) {
|
|
71
|
-
auto result = this->parseFirstLevel(rt, unistyle,
|
|
73
|
+
auto result = this->parseFirstLevel(rt, unistyle, std::nullopt);
|
|
72
74
|
|
|
73
75
|
unistyle->parsedStyle = std::move(result);
|
|
74
76
|
unistyle->seal();
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
if (unistyle->type == core::UnistyleType::DynamicFunction) {
|
|
78
|
-
auto hostFn = this->createDynamicFunctionProxy(rt, unistyle
|
|
80
|
+
auto hostFn = this->createDynamicFunctionProxy(rt, unistyle);
|
|
79
81
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
|
80
82
|
|
|
81
83
|
// defer parsing dynamic functions
|
|
@@ -85,57 +87,72 @@ void parser::Parser::parseUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet
|
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
// rebuild all unistyles in StyleSheet that depends on variants
|
|
88
|
-
void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet) {
|
|
90
|
+
void parser::Parser::rebuildUnistylesWithVariants(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Variants& variants) {
|
|
89
91
|
for (const auto& [_, unistyle] : styleSheet->unistyles) {
|
|
90
92
|
if (!unistyle->dependsOn(UnistyleDependency::VARIANTS)) {
|
|
91
93
|
continue;
|
|
92
94
|
}
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
// todo skip dynamic functions
|
|
97
|
+
this->rebuildUnistyle(rt, styleSheet, unistyle, variants, std::nullopt);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
// rebuild all unistyles that are affected by platform event
|
|
99
102
|
void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, DependencyMap& dependencyMap) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
std::unordered_map<std::shared_ptr<StyleSheet>, jsi::Value> parsedStyleSheets{};
|
|
104
|
+
|
|
105
|
+
for (auto& [shadowNode, unistyles] : dependencyMap) {
|
|
106
|
+
auto styleSheet = unistyles.begin()->get()->unistyle->parent;
|
|
107
|
+
|
|
108
|
+
// stylesheet may be optional for exotic unistyles
|
|
109
|
+
if (styleSheet != nullptr && !parsedStyleSheets.contains(styleSheet)) {
|
|
110
|
+
parsedStyleSheets.emplace(styleSheet, this->unwrapStyleSheet(rt, styleSheet));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (auto& unistyleData : unistyles) {
|
|
114
|
+
auto& unistyle = unistyleData->unistyle;
|
|
115
|
+
|
|
116
|
+
// for RN styles or inline styles, compute styles only once
|
|
117
|
+
if (unistyle->styleKey == helpers::EXOTIC_STYLE_KEY.c_str() && !unistyleData->parsedStyle.has_value()) {
|
|
118
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->rawValue).asObject(rt);
|
|
119
|
+
|
|
120
|
+
continue;
|
|
112
121
|
}
|
|
122
|
+
|
|
123
|
+
// StyleSheet might have styles that are not affected
|
|
124
|
+
if (!parsedStyleSheets[styleSheet].asObject(rt).hasProperty(rt, unistyle->styleKey.c_str())) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
unistyle->rawValue = parsedStyleSheets[styleSheet].asObject(rt).getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
|
|
129
|
+
this->rebuildUnistyle(rt, styleSheet, unistyle, unistyleData->variants, unistyleData->dynamicFunctionMetadata);
|
|
130
|
+
unistyleData->parsedStyle = jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
|
113
131
|
}
|
|
114
132
|
}
|
|
115
133
|
}
|
|
116
134
|
|
|
117
135
|
// rebuild single unistyle
|
|
118
|
-
void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle) {
|
|
136
|
+
void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>> metadata) {
|
|
119
137
|
if (unistyle->type == core::UnistyleType::Object) {
|
|
120
|
-
auto result = this->parseFirstLevel(rt, unistyle,
|
|
138
|
+
auto result = this->parseFirstLevel(rt, unistyle, variants);
|
|
121
139
|
|
|
122
140
|
unistyle->parsedStyle = std::move(result);
|
|
123
141
|
}
|
|
124
142
|
|
|
125
143
|
// for functions we need to call memoized function
|
|
126
144
|
// with last know arguments and parse it with new theme and mini runtime
|
|
127
|
-
if (unistyle->type == core::UnistyleType::DynamicFunction) {
|
|
145
|
+
if (unistyle->type == core::UnistyleType::DynamicFunction && metadata.has_value()) {
|
|
128
146
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
|
129
|
-
auto maybeMetadata = unistyleFn->dynamicFunctionMetadata;
|
|
130
|
-
|
|
131
|
-
helpers::assertThat(rt, maybeMetadata.has_value(), "Your dynamic function '" + unistyleFn->styleKey + "' has no metadata and can't be processed.");
|
|
132
147
|
|
|
133
148
|
// convert arguments to jsi::Value
|
|
134
|
-
auto
|
|
149
|
+
auto dynamicFunctionMetadata = metadata.value();
|
|
135
150
|
std::vector<jsi::Value> args{};
|
|
136
151
|
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
args.reserve(dynamicFunctionMetadata.size());
|
|
153
|
+
|
|
154
|
+
for (int i = 0; i < dynamicFunctionMetadata.size(); i++) {
|
|
155
|
+
folly::dynamic& arg = dynamicFunctionMetadata.at(i);
|
|
139
156
|
|
|
140
157
|
args.emplace_back(jsi::valueFromDynamic(rt, arg));
|
|
141
158
|
}
|
|
@@ -143,94 +160,33 @@ void parser::Parser::rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleShee
|
|
|
143
160
|
const jsi::Value *argStart = args.data();
|
|
144
161
|
|
|
145
162
|
// call cached function with memoized arguments
|
|
146
|
-
auto functionResult = unistyleFn->
|
|
163
|
+
auto functionResult = unistyleFn->rawValue
|
|
164
|
+
.asFunction(rt)
|
|
165
|
+
.call(rt, argStart, dynamicFunctionMetadata.size())
|
|
166
|
+
.asObject(rt);
|
|
147
167
|
|
|
148
168
|
unistyleFn->unprocessedValue = std::move(functionResult);
|
|
149
|
-
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn,
|
|
169
|
+
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
|
150
170
|
}
|
|
151
171
|
}
|
|
152
172
|
|
|
153
173
|
// convert dependency map to shadow tree updates
|
|
154
|
-
shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(DependencyMap& dependencyMap) {
|
|
174
|
+
shadow::ShadowLeafUpdates parser::Parser::dependencyMapToShadowLeafUpdates(core::DependencyMap& dependencyMap) {
|
|
155
175
|
shadow::ShadowLeafUpdates updates;
|
|
156
176
|
auto& rt = this->_unistylesRuntime->getRuntime();
|
|
157
177
|
|
|
158
|
-
for (const auto& [
|
|
159
|
-
|
|
160
|
-
for (const auto& unistyle : unistyles) {
|
|
161
|
-
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyle->parsedStyle.value());
|
|
162
|
-
|
|
163
|
-
if (updates.contains(shadowNode)) {
|
|
164
|
-
updates[shadowNode].emplace_back(std::move(rawProps));
|
|
178
|
+
for (const auto& [shadowNode, unistyles] : dependencyMap) {
|
|
179
|
+
auto rawProps = this->parseStylesToShadowTreeStyles(rt, unistyles);
|
|
165
180
|
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
updates.emplace(shadowNode, std::vector<RawProps>{std::move(rawProps)});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
181
|
+
updates.emplace(shadowNode, std::move(rawProps));
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
return updates;
|
|
175
185
|
}
|
|
176
186
|
|
|
177
|
-
// convert jsi::Value arguments to folly::dynamic
|
|
178
|
-
std::vector<folly::dynamic> parser::Parser::parseDynamicFunctionArguments(jsi::Runtime& rt, size_t count, const jsi::Value* arguments) {
|
|
179
|
-
std::vector<folly::dynamic> parsedArgument{};
|
|
180
|
-
|
|
181
|
-
for (size_t i = 0; i < count; i++) {
|
|
182
|
-
auto& arg = arguments[i];
|
|
183
|
-
|
|
184
|
-
if (arg.isBool()) {
|
|
185
|
-
parsedArgument.push_back(folly::dynamic(arg.asBool()));
|
|
186
|
-
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (arg.isNumber()) {
|
|
191
|
-
parsedArgument.push_back(folly::dynamic(arg.asNumber()));
|
|
192
|
-
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (arg.isString()) {
|
|
197
|
-
parsedArgument.push_back(folly::dynamic(arg.asString(rt).utf8(rt)));
|
|
198
|
-
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (arg.isUndefined()) {
|
|
203
|
-
parsedArgument.push_back(folly::dynamic());
|
|
204
|
-
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (arg.isNull()) {
|
|
209
|
-
parsedArgument.push_back(folly::dynamic(nullptr));
|
|
210
|
-
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (!arg.isObject()) {
|
|
215
|
-
continue;;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
auto argObj = arg.asObject(rt);
|
|
219
|
-
|
|
220
|
-
// allow arrays and objects too
|
|
221
|
-
if (!argObj.isFunction(rt) && !argObj.isArrayBuffer(rt)) {
|
|
222
|
-
parsedArgument.push_back(jsi::dynamicFromValue(rt, arg));
|
|
223
|
-
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return parsedArgument;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
187
|
// first level of StyleSheet, we can expect here different properties than on second level
|
|
232
188
|
// eg. variants, compoundVariants, mq, breakpoints etc.
|
|
233
|
-
jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, Variants
|
|
189
|
+
jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants) {
|
|
234
190
|
// for objects - we simply operate on them
|
|
235
191
|
// for functions we need to work on the unprocessed result (object)
|
|
236
192
|
auto& style = unistyle->type == core::UnistyleType::Object
|
|
@@ -312,20 +268,16 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
|
312
268
|
|
|
313
269
|
parsedStyle.setProperty(rt, jsi::PropNameID::forUtf8(rt, propertyName), this->parseSecondLevel(rt, unistyle, valueFromBreakpoint));
|
|
314
270
|
});
|
|
315
|
-
|
|
316
|
-
if (shouldParseVariants) {
|
|
317
|
-
unistyle->addDependency(UnistyleDependency::VARIANTS);
|
|
318
|
-
}
|
|
319
271
|
|
|
320
|
-
if (shouldParseVariants && !variants.empty()) {
|
|
272
|
+
if (shouldParseVariants && variants.has_value() && !variants.value().empty()) {
|
|
321
273
|
auto propertyValueObject = style.getProperty(rt, "variants").asObject(rt);
|
|
322
|
-
auto parsedVariant = this->parseVariants(rt, unistyle, propertyValueObject, variants);
|
|
274
|
+
auto parsedVariant = this->parseVariants(rt, unistyle, propertyValueObject, variants.value());
|
|
323
275
|
|
|
324
276
|
helpers::mergeJSIObjects(rt, parsedStyle, parsedVariant);
|
|
325
277
|
|
|
326
278
|
if (shouldParseCompoundVariants) {
|
|
327
279
|
auto compoundVariants = style.getProperty(rt, "compoundVariants").asObject(rt);
|
|
328
|
-
auto parsedCompoundVariants = this->parseCompoundVariants(rt, unistyle, compoundVariants, variants);
|
|
280
|
+
auto parsedCompoundVariants = this->parseCompoundVariants(rt, unistyle, compoundVariants, variants.value());
|
|
329
281
|
|
|
330
282
|
helpers::mergeJSIObjects(rt, parsedStyle, parsedCompoundVariants);
|
|
331
283
|
}
|
|
@@ -335,14 +287,14 @@ jsi::Object parser::Parser::parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared u
|
|
|
335
287
|
}
|
|
336
288
|
|
|
337
289
|
// function replaces original user dynamic function with additional logic to memoize arguments
|
|
338
|
-
jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle
|
|
290
|
+
jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unistyle::Shared unistyle) {
|
|
339
291
|
auto unistylesRuntime = this->_unistylesRuntime;
|
|
340
292
|
|
|
341
293
|
return jsi::Function::createFromHostFunction(
|
|
342
294
|
rt,
|
|
343
295
|
jsi::PropNameID::forUtf8(rt, unistyle->styleKey),
|
|
344
296
|
1,
|
|
345
|
-
[this, unistylesRuntime, unistyle
|
|
297
|
+
[this, unistylesRuntime, unistyle](jsi::Runtime& rt, const jsi::Value& thisVal, const jsi::Value* args, size_t count) {
|
|
346
298
|
auto thisObject = thisVal.asObject(rt);
|
|
347
299
|
auto parser = parser::Parser(unistylesRuntime);
|
|
348
300
|
|
|
@@ -352,12 +304,15 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
|
352
304
|
// memoize metadata to call it later
|
|
353
305
|
auto unistyleFn = std::dynamic_pointer_cast<UnistyleDynamicFunction>(unistyle);
|
|
354
306
|
|
|
355
|
-
unistyleFn->dynamicFunctionMetadata = core::DynamicFunctionMetadata{
|
|
356
|
-
count,
|
|
357
|
-
this->parseDynamicFunctionArguments(rt, count, args)
|
|
358
|
-
};
|
|
359
|
-
|
|
360
307
|
unistyleFn->unprocessedValue = jsi::Value(rt, result).asObject(rt);
|
|
308
|
+
|
|
309
|
+
jsi::Value rawVariants = thisObject.hasProperty(rt, helpers::STYLE_VARIANTS.c_str())
|
|
310
|
+
? thisObject.getProperty(rt, helpers::STYLE_VARIANTS.c_str())
|
|
311
|
+
: jsi::Value::undefined();
|
|
312
|
+
std::optional<Variants> variants = rawVariants.isUndefined()
|
|
313
|
+
? std::nullopt
|
|
314
|
+
: std::optional<Variants>(helpers::variantsToPairs(rt, rawVariants.asObject(rt)));
|
|
315
|
+
|
|
361
316
|
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
|
362
317
|
unistyleFn->seal();
|
|
363
318
|
|
|
@@ -367,9 +322,11 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
|
367
322
|
|
|
368
323
|
// function convert babel generated dependencies to C++ dependencies
|
|
369
324
|
std::vector<UnistyleDependency> parser::Parser::parseDependencies(jsi::Runtime &rt, jsi::Object&& dependencies) {
|
|
370
|
-
helpers::assertThat(rt, dependencies.isArray(rt), "
|
|
325
|
+
helpers::assertThat(rt, dependencies.isArray(rt), "Unistyles: Babel transform is invalid - unexpected type for dependencies.");
|
|
371
326
|
|
|
372
|
-
std::vector<UnistyleDependency> parsedDependencies;
|
|
327
|
+
std::vector<UnistyleDependency> parsedDependencies{};
|
|
328
|
+
|
|
329
|
+
parsedDependencies.reserve(5);
|
|
373
330
|
|
|
374
331
|
helpers::iterateJSIArray(rt, dependencies.asArray(rt), [&](size_t i, jsi::Value& value){
|
|
375
332
|
auto dependency = static_cast<UnistyleDependency>(value.asNumber());
|
|
@@ -388,6 +345,8 @@ jsi::Value parser::Parser::parseTransforms(jsi::Runtime& rt, Unistyle::Shared un
|
|
|
388
345
|
|
|
389
346
|
std::vector<jsi::Value> parsedTransforms{};
|
|
390
347
|
|
|
348
|
+
parsedTransforms.reserve(2);
|
|
349
|
+
|
|
391
350
|
helpers::iterateJSIArray(rt, obj.asArray(rt), [&](size_t i, jsi::Value& value){
|
|
392
351
|
if (!value.isObject()) {
|
|
393
352
|
return;
|
|
@@ -434,7 +393,7 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
|
434
393
|
auto propertyName = propertyNames.getValueAtIndex(rt, i).asString(rt).utf8(rt);
|
|
435
394
|
auto propertyValue = obj.getProperty(rt, propertyName.c_str());
|
|
436
395
|
auto mq = core::UnistylesMQ{propertyName};
|
|
437
|
-
|
|
396
|
+
|
|
438
397
|
if (mq.isMQ()) {
|
|
439
398
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
|
440
399
|
}
|
|
@@ -447,11 +406,11 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
|
447
406
|
|
|
448
407
|
// check orientation breakpoints if user didn't register own breakpoint
|
|
449
408
|
bool hasOrientationBreakpoint = obj.hasProperty(rt, currentOrientation);
|
|
450
|
-
|
|
409
|
+
|
|
451
410
|
if (hasOrientationBreakpoint) {
|
|
452
411
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
|
453
412
|
}
|
|
454
|
-
|
|
413
|
+
|
|
455
414
|
if (!hasBreakpoints && hasOrientationBreakpoint) {
|
|
456
415
|
return obj.getProperty(rt, currentOrientation);
|
|
457
416
|
}
|
|
@@ -459,7 +418,7 @@ jsi::Value parser::Parser::getValueFromBreakpoints(jsi::Runtime& rt, Unistyle::S
|
|
|
459
418
|
if (!currentBreakpoint.has_value()) {
|
|
460
419
|
return jsi::Value::undefined();
|
|
461
420
|
}
|
|
462
|
-
|
|
421
|
+
|
|
463
422
|
unistyle->addDependency(UnistyleDependency::BREAKPOINTS);
|
|
464
423
|
|
|
465
424
|
// if you're still here it means that there is no
|
|
@@ -505,7 +464,7 @@ jsi::Object parser::Parser::parseVariants(jsi::Runtime& rt, Unistyle::Shared uni
|
|
|
505
464
|
: std::nullopt;
|
|
506
465
|
|
|
507
466
|
// we've got a match, but we need to check some condition
|
|
508
|
-
auto styles = this->getStylesForVariant(rt, groupValue.asObject(rt), selectedVariant);
|
|
467
|
+
auto styles = this->getStylesForVariant(rt, groupName, groupValue.asObject(rt), selectedVariant, variants);
|
|
509
468
|
|
|
510
469
|
// oops, invalid variant
|
|
511
470
|
if (styles.isUndefined() || !styles.isObject()) {
|
|
@@ -521,13 +480,19 @@ jsi::Object parser::Parser::parseVariants(jsi::Runtime& rt, Unistyle::Shared uni
|
|
|
521
480
|
}
|
|
522
481
|
|
|
523
482
|
// helpers function to support 'default' variants
|
|
524
|
-
jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, jsi::Object&& groupValue, std::optional<std::string> selectedVariant) {
|
|
483
|
+
jsi::Value parser::Parser::getStylesForVariant(jsi::Runtime& rt, const std::string groupName, jsi::Object&& groupValue, std::optional<std::string> selectedVariant, Variants& variants) {
|
|
525
484
|
// if there is no value, let's try 'default'
|
|
526
485
|
auto selectedVariantKey = selectedVariant.has_value()
|
|
527
486
|
? selectedVariant.value().c_str()
|
|
528
487
|
: "default";
|
|
488
|
+
auto hasKey = groupValue.hasProperty(rt, selectedVariantKey);
|
|
489
|
+
|
|
490
|
+
if (!hasKey || !selectedVariant.has_value()) {
|
|
491
|
+
// for no key, add 'default' selection to variants map
|
|
492
|
+
variants.emplace_back(groupName, selectedVariantKey);
|
|
493
|
+
}
|
|
529
494
|
|
|
530
|
-
if (
|
|
495
|
+
if (hasKey) {
|
|
531
496
|
return groupValue.getProperty(rt, selectedVariantKey);
|
|
532
497
|
}
|
|
533
498
|
|
|
@@ -567,28 +532,20 @@ bool parser::Parser::shouldApplyCompoundVariants(jsi::Runtime& rt, const Variant
|
|
|
567
532
|
return false;
|
|
568
533
|
}
|
|
569
534
|
|
|
570
|
-
jsi::Array propertyNames = compoundVariant.getPropertyNames(rt);
|
|
571
|
-
size_t length = propertyNames.size(rt);
|
|
572
|
-
size_t allConditions = compoundVariant.hasProperty(rt, "styles")
|
|
573
|
-
? length - 1
|
|
574
|
-
: length;
|
|
575
|
-
|
|
576
|
-
if (allConditions != variants.size()) {
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
535
|
for (auto it = variants.cbegin(); it != variants.cend(); ++it) {
|
|
581
536
|
auto variantKey = it->first;
|
|
582
537
|
auto variantValue = it->second;
|
|
583
538
|
|
|
584
539
|
if (!compoundVariant.hasProperty(rt, variantKey.c_str())) {
|
|
585
|
-
|
|
540
|
+
continue;
|
|
586
541
|
}
|
|
587
542
|
|
|
588
543
|
auto property = compoundVariant.getProperty(rt, variantKey.c_str());
|
|
589
544
|
auto propertyName = property.isBool()
|
|
590
545
|
? (property.asBool() ? "true" : "false")
|
|
591
|
-
: property.
|
|
546
|
+
: property.isString()
|
|
547
|
+
? property.asString(rt).utf8(rt)
|
|
548
|
+
: "";
|
|
592
549
|
|
|
593
550
|
if (propertyName != variantValue) {
|
|
594
551
|
return false;
|
|
@@ -666,41 +623,25 @@ jsi::Value parser::Parser::parseSecondLevel(jsi::Runtime &rt, Unistyle::Shared u
|
|
|
666
623
|
return parsedStyle;
|
|
667
624
|
}
|
|
668
625
|
|
|
669
|
-
//
|
|
670
|
-
|
|
671
|
-
Variants pairs{};
|
|
672
|
-
|
|
673
|
-
helpers::enumerateJSIObject(rt, variants, [&](const std::string& variantName, jsi::Value& variantValue){
|
|
674
|
-
if (variantValue.isUndefined() || variantValue.isNull()) {
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
if (variantValue.isBool()) {
|
|
679
|
-
pairs.emplace_back(std::make_pair(variantName, variantValue.asBool() ? "true" : "false"));
|
|
680
|
-
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
if (variantValue.isString()) {
|
|
685
|
-
pairs.emplace_back(std::make_pair(variantName, variantValue.asString(rt).utf8(rt)));
|
|
686
|
-
}
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
return pairs;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
// convert jsi::Object to RawValue with int colors
|
|
693
|
-
RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, jsi::Object& styles) {
|
|
626
|
+
// convert unistyles to RawValue with int colors
|
|
627
|
+
RawProps parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles) {
|
|
694
628
|
jsi::Object convertedStyles = jsi::Object(rt);
|
|
695
629
|
auto& state = core::UnistylesRegistry::get().getState(rt);
|
|
696
630
|
|
|
697
|
-
|
|
698
|
-
if (
|
|
699
|
-
|
|
631
|
+
for (const auto& unistyleData : unistyles) {
|
|
632
|
+
if (!unistyleData->parsedStyle.has_value()) {
|
|
633
|
+
// todo this something happens with large dataset, debug it
|
|
634
|
+
continue;
|
|
700
635
|
}
|
|
701
636
|
|
|
702
|
-
|
|
703
|
-
|
|
637
|
+
helpers::enumerateJSIObject(rt, unistyleData->parsedStyle.value(), [&](const std::string& propertyName, jsi::Value& propertyValue){
|
|
638
|
+
if (this->isColor(propertyName)) {
|
|
639
|
+
return convertedStyles.setProperty(rt, propertyName.c_str(), jsi::Value(state.parseColor(propertyValue)));
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
convertedStyles.setProperty(rt, propertyName.c_str(), propertyValue);
|
|
643
|
+
});
|
|
644
|
+
}
|
|
704
645
|
|
|
705
646
|
return RawProps(rt, std::move(convertedStyles));
|
|
706
647
|
}
|