react-native-unistyles 3.0.0-alpha.32 → 3.0.0-alpha.34
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/common/Helpers.h +24 -2
- package/cxx/core/HostStyle.cpp +1 -1
- package/cxx/core/UnistyleWrapper.h +31 -1
- package/cxx/core/UnistylesMountHook.cpp +1 -1
- package/cxx/core/UnistylesMountHook.h +4 -2
- package/cxx/core/UnistylesRegistry.cpp +7 -2
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +1 -2
- package/cxx/hybridObjects/HybridStyleSheet.cpp +4 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +12 -0
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +6 -6
- package/cxx/parser/Parser.h +1 -1
- package/cxx/shadowTree/ShadowTrafficController.h +5 -8
- package/lib/commonjs/components/Display.js +18 -0
- package/lib/commonjs/components/Display.js.map +1 -0
- package/lib/commonjs/components/Hide.js +18 -0
- package/lib/commonjs/components/Hide.js.map +1 -0
- package/lib/commonjs/components/index.js +20 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/components/useMedia.js +59 -0
- package/lib/commonjs/components/useMedia.js.map +1 -0
- package/lib/commonjs/core/createUnistylesComponent.js +2 -1
- package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
- package/lib/commonjs/core/createUnistylesComponent.native.js +43 -4
- package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -1
- package/lib/commonjs/core/index.js +0 -14
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/global.js +0 -4
- package/lib/commonjs/global.js.map +1 -1
- package/lib/commonjs/index.js +12 -14
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mq.js +25 -12
- package/lib/commonjs/mq.js.map +1 -1
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +4 -5
- package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
- package/lib/commonjs/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/types.js +0 -4
- package/lib/commonjs/specs/ShadowRegistry/types.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/UnistylesStatusBar.nitro.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js +4 -2
- package/lib/commonjs/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +1 -1
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js +3 -1
- package/lib/commonjs/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
- package/lib/commonjs/specs/types.js.map +0 -1
- package/lib/commonjs/types/accessibility.js +1 -1
- package/lib/commonjs/types/accessibility.js.map +0 -1
- package/lib/commonjs/types/common.js +0 -3
- package/lib/commonjs/types/stylesheet.js +2 -1
- package/lib/commonjs/web/convert/index.js +7 -1
- package/lib/commonjs/web/convert/index.js.map +1 -2
- package/lib/commonjs/web/convert/pseudo.js.map +1 -2
- package/lib/commonjs/web/convert/shadow.js +5 -1
- package/lib/commonjs/web/convert/shadow.js.map +1 -2
- package/lib/commonjs/web/convert/style.js.map +1 -2
- package/lib/commonjs/web/convert/textShadow.js +4 -1
- package/lib/commonjs/web/convert/textShadow.js.map +1 -2
- package/lib/commonjs/web/convert/transform.js.map +1 -2
- package/lib/commonjs/web/convert/types.js.map +1 -1
- package/lib/commonjs/web/convert/utils.js +2 -1
- package/lib/commonjs/web/convert/utils.js.map +1 -2
- package/lib/commonjs/web/listener.js.map +1 -2
- package/lib/commonjs/web/mock.js.map +1 -2
- package/lib/commonjs/web/shadowRegistry.js +9 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -2
- package/lib/commonjs/web/utils/unistyle.js +1 -1
- package/lib/commonjs/web/variants/index.js.map +1 -1
- package/lib/commonjs/web/variants/useVariants.js +2 -1
- package/lib/commonjs/web/variants/useVariants.js.map +1 -2
- package/lib/module/common.js.map +1 -1
- package/lib/module/components/Display.js +13 -0
- package/lib/module/components/Display.js.map +1 -0
- package/lib/module/components/Hide.js +13 -0
- package/lib/module/components/Hide.js.map +1 -0
- package/lib/module/components/index.js +5 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/components/useMedia.js +54 -0
- package/lib/module/components/useMedia.js.map +1 -0
- package/lib/module/core/createUnistylesComponent.js +2 -1
- package/lib/module/core/createUnistylesComponent.js.map +1 -1
- package/lib/module/core/createUnistylesComponent.native.js +41 -3
- package/lib/module/core/createUnistylesComponent.native.js.map +1 -1
- package/lib/module/core/index.js +0 -2
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/global.js +1 -1
- package/lib/module/global.js.map +0 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mq.js +21 -11
- package/lib/module/mq.js.map +1 -1
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +6 -5
- package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +0 -1
- package/lib/module/specs/NavigtionBar/UnistylesNavigationBar.nitro.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/ShadowRegistry.nitro.js.map +0 -1
- package/lib/module/specs/ShadowRegistry/types.js +0 -2
- package/lib/module/specs/ShadowRegistry/types.js.map +0 -1
- package/lib/module/specs/StatusBar/UnistylesStatusBar.nitro.js.map +0 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js +1 -1
- package/lib/module/specs/StyleSheet/UnistylesStyleSheet.nitro.js.map +0 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -2
- package/lib/module/specs/TurboUnistyles/NativeTurboUnistyles.js.map +1 -2
- package/lib/module/specs/UnistylesRuntime/UnistylesRuntime.nitro.js.map +0 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -2
- package/lib/module/specs/types.js.map +0 -1
- package/lib/module/types/accessibility.js +9 -9
- package/lib/module/types/accessibility.js.map +1 -1
- package/lib/module/types/breakpoints.js.map +0 -1
- package/lib/module/types/common.js +0 -2
- package/lib/module/types/common.js.map +1 -1
- package/lib/module/types/core.js.map +1 -1
- package/lib/module/types/stylesheet.js +2 -2
- package/lib/module/types/variants.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +4 -1
- package/lib/module/web/convert/boxShadow.js.map +1 -2
- package/lib/module/web/convert/pseudo.js.map +1 -2
- package/lib/module/web/convert/textShadow.js +4 -1
- package/lib/module/web/convert/transform.js.map +1 -2
- package/lib/module/web/convert/types.js.map +1 -1
- package/lib/module/web/convert/utils.js +2 -1
- package/lib/module/web/registry.js +3 -1
- package/lib/module/web/registry.js.map +1 -2
- package/lib/module/web/runtime.js.map +1 -2
- package/lib/module/web/shadowRegistry.js +9 -1
- package/lib/module/web/utils/common.js +3 -1
- package/lib/module/web/utils/common.js.map +1 -2
- package/lib/module/web/utils/index.js.map +1 -1
- package/lib/module/web/utils/unistyle.js +1 -1
- package/lib/module/web/utils/unistyle.js.map +1 -1
- package/lib/module/web/variants/index.js.map +1 -1
- package/lib/module/web/variants/useVariants.js +2 -1
- package/lib/module/web/variants/useVariants.js.map +1 -2
- package/lib/typescript/src/components/Display.d.ts +7 -0
- package/lib/typescript/src/components/Display.d.ts.map +1 -0
- package/lib/typescript/src/components/Hide.d.ts +7 -0
- package/lib/typescript/src/components/Hide.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts +3 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/components/useMedia.d.ts +6 -0
- package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesComponent.d.ts +3 -2
- package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +3 -2
- package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -1
- package/lib/typescript/src/core/index.d.ts +0 -2
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/mq.d.ts +8 -0
- package/lib/typescript/src/mq.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -0
- package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
- package/package.json +1 -1
- package/plugin/ref.js +4 -4
- package/plugin/style.js +15 -3
- package/src/components/Display.tsx +12 -0
- package/src/components/Hide.tsx +12 -0
- package/src/components/index.ts +2 -0
- package/src/components/useMedia.ts +64 -0
- package/src/core/createUnistylesComponent.native.tsx +48 -4
- package/src/core/createUnistylesComponent.tsx +4 -2
- package/src/core/index.ts +0 -2
- package/src/index.ts +2 -1
- package/src/mq.ts +27 -9
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -0
- package/src/web/utils/unistyle.ts +1 -1
- package/lib/commonjs/core/useBreakpoint.js +0 -22
- package/lib/commonjs/core/useBreakpoint.js.map +0 -1
- package/lib/commonjs/core/useBreakpoint.native.js +0 -24
- package/lib/commonjs/core/useBreakpoint.native.js.map +0 -2
- package/lib/commonjs/core/useTheme.js +0 -22
- package/lib/commonjs/core/useTheme.js.map +0 -1
- package/lib/commonjs/core/useTheme.native.js +0 -24
- package/lib/commonjs/core/useTheme.native.js.map +0 -2
- package/lib/commonjs/web/mq.js +0 -23
- package/lib/commonjs/web/mq.js.map +0 -1
- package/lib/module/core/useBreakpoint.js +0 -17
- package/lib/module/core/useBreakpoint.js.map +0 -1
- package/lib/module/core/useBreakpoint.native.js +0 -19
- package/lib/module/core/useBreakpoint.native.js.map +0 -1
- package/lib/module/core/useTheme.js +0 -17
- package/lib/module/core/useTheme.js.map +0 -2
- package/lib/module/core/useTheme.native.js +0 -19
- package/lib/module/core/useTheme.native.js.map +0 -1
- package/lib/module/web/mq.js +0 -17
- package/lib/module/web/mq.js.map +0 -1
- package/lib/typescript/src/core/useBreakpoint.d.ts +0 -2
- package/lib/typescript/src/core/useBreakpoint.d.ts.map +0 -1
- package/lib/typescript/src/core/useBreakpoint.native.d.ts +0 -2
- package/lib/typescript/src/core/useBreakpoint.native.d.ts.map +0 -1
- package/lib/typescript/src/core/useTheme.d.ts +0 -3
- package/lib/typescript/src/core/useTheme.d.ts.map +0 -1
- package/lib/typescript/src/core/useTheme.native.d.ts +0 -3
- package/lib/typescript/src/core/useTheme.native.d.ts.map +0 -1
- package/lib/typescript/src/web/mq.d.ts +0 -8
- package/lib/typescript/src/web/mq.d.ts.map +0 -1
- package/src/common.js +0 -4
- package/src/core/createUnistylesComponent.js +0 -6
- package/src/core/createUnistylesComponent.native.js +0 -31
- package/src/core/index.js +0 -3
- package/src/core/useBreakpoint.js +0 -14
- package/src/core/useBreakpoint.native.js +0 -16
- package/src/core/useBreakpoint.native.ts +0 -21
- package/src/core/useBreakpoint.ts +0 -18
- package/src/core/useTheme.js +0 -14
- package/src/core/useTheme.native.js +0 -16
- package/src/core/useTheme.native.ts +0 -22
- package/src/core/useTheme.ts +0 -19
- package/src/global.js +0 -1
- package/src/index.js +0 -3
- package/src/mq.js +0 -38
- package/src/specs/NativePlatform/NativePlatform.nitro.js +0 -19
- package/src/specs/NativePlatform/index.js +0 -1
- package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.js +0 -1
- package/src/specs/NavigtionBar/index.js +0 -9
- package/src/specs/ShadowRegistry/ShadowRegistry.nitro.js +0 -1
- package/src/specs/ShadowRegistry/index.js +0 -26
- package/src/specs/ShadowRegistry/types.js +0 -1
- package/src/specs/StatusBar/UnistylesStatusBar.nitro.js +0 -1
- package/src/specs/StatusBar/index.js +0 -25
- package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.js +0 -1
- package/src/specs/StyleSheet/index.js +0 -13
- package/src/specs/TurboUnistyles/NativeTurboUnistyles.js +0 -2
- package/src/specs/TurboUnistyles/index.js +0 -1
- package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.js +0 -1
- package/src/specs/UnistylesRuntime/index.js +0 -20
- package/src/specs/index.js +0 -8
- package/src/specs/index.web.js +0 -2
- package/src/specs/types.js +0 -17
- package/src/types/accessibility.js +0 -30
- package/src/types/breakpoints.js +0 -1
- package/src/types/common.js +0 -1
- package/src/types/core.js +0 -1
- package/src/types/index.js +0 -1
- package/src/types/stylesheet.js +0 -2
- package/src/types/variants.js +0 -1
- package/src/web/convert/boxShadow.js +0 -59
- package/src/web/convert/index.js +0 -56
- package/src/web/convert/pseudo.js +0 -131
- package/src/web/convert/shadow.js +0 -50
- package/src/web/convert/style.js +0 -137
- package/src/web/convert/textShadow.js +0 -56
- package/src/web/convert/transform.js +0 -65
- package/src/web/convert/types.js +0 -2
- package/src/web/convert/utils.js +0 -39
- package/src/web/create.js +0 -36
- package/src/web/index.js +0 -22
- package/src/web/listener.js +0 -26
- package/src/web/mock.js +0 -21
- package/src/web/mq.js +0 -14
- package/src/web/mq.ts +0 -17
- package/src/web/registry.js +0 -165
- package/src/web/runtime.js +0 -160
- package/src/web/shadowRegistry.js +0 -96
- package/src/web/state.js +0 -68
- package/src/web/utils/common.js +0 -79
- package/src/web/utils/index.js +0 -2
- package/src/web/utils/unistyle.js +0 -72
- package/src/web/variants/getVariants.js +0 -26
- package/src/web/variants/index.js +0 -2
- package/src/web/variants/useVariants.js +0 -50
package/cxx/common/Helpers.h
CHANGED
@@ -96,7 +96,7 @@ inline bool isPlatformColor(jsi::Runtime& rt, jsi::Object& maybePlatformColor) {
|
|
96
96
|
maybePlatformColor.getProperty(rt, "dynamic").isObject() &&
|
97
97
|
maybePlatformColor.getProperty(rt, "dynamic").asObject(rt).hasProperty(rt, "dark") &&
|
98
98
|
maybePlatformColor.getProperty(rt, "dynamic").asObject(rt).hasProperty(rt, "light");
|
99
|
-
|
99
|
+
|
100
100
|
if (isIOSDynamicColor) {
|
101
101
|
return true;
|
102
102
|
}
|
@@ -127,6 +127,16 @@ inline Variants variantsToPairs(jsi::Runtime& rt, jsi::Object&& variants) {
|
|
127
127
|
return pairs;
|
128
128
|
}
|
129
129
|
|
130
|
+
inline jsi::Object pairsToVariantsValue(jsi::Runtime& rt, Variants& pairs) {
|
131
|
+
auto variantsValue = jsi::Object(rt);
|
132
|
+
|
133
|
+
std::for_each(pairs.begin(), pairs.end(), [&rt, &variantsValue](std::pair<std::string, std::string>& pair){
|
134
|
+
variantsValue.setProperty(rt, jsi::PropNameID::forUtf8(rt, pair.first), jsi::String::createFromUtf8(rt, pair.second));
|
135
|
+
});
|
136
|
+
|
137
|
+
return variantsValue;
|
138
|
+
}
|
139
|
+
|
130
140
|
inline jsi::Object variantsToValue(jsi::Runtime& rt, Variants& variants) {
|
131
141
|
jsi::Object rawVariants = jsi::Object(rt);
|
132
142
|
|
@@ -137,7 +147,7 @@ inline jsi::Object variantsToValue(jsi::Runtime& rt, Variants& variants) {
|
|
137
147
|
return rawVariants;
|
138
148
|
}
|
139
149
|
|
140
|
-
inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array
|
150
|
+
inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& rt, jsi::Array&& arguments) {
|
141
151
|
std::vector<folly::dynamic> parsedArgument{};
|
142
152
|
size_t count = arguments.size(rt);
|
143
153
|
|
@@ -193,6 +203,18 @@ inline std::vector<folly::dynamic> parseDynamicFunctionArguments(jsi::Runtime& r
|
|
193
203
|
return parsedArgument;
|
194
204
|
}
|
195
205
|
|
206
|
+
inline jsi::Array functionArgumentsToArray(jsi::Runtime& rt, const jsi::Value* args, size_t count) {
|
207
|
+
auto arr = jsi::Array(rt, count);
|
208
|
+
|
209
|
+
for (size_t i = 0; i < count; i++) {
|
210
|
+
const jsi::Value& arg = args[i];
|
211
|
+
|
212
|
+
arr.setValueAtIndex(rt, i, arg);
|
213
|
+
}
|
214
|
+
|
215
|
+
return arr;
|
216
|
+
}
|
217
|
+
|
196
218
|
inline static jsi::Array dependenciesToJSIArray(jsi::Runtime& rt, const std::vector<UnistyleDependency>& vec) {
|
197
219
|
jsi::Array result(rt, vec.size());
|
198
220
|
|
package/cxx/core/HostStyle.cpp
CHANGED
@@ -28,7 +28,7 @@ jsi::Value HostStyle::get(jsi::Runtime& rt, const jsi::PropNameID& propNameId) {
|
|
28
28
|
}
|
29
29
|
|
30
30
|
if (this->_styleSheet->unistyles.contains(propertyName)) {
|
31
|
-
return valueFromUnistyle(rt, this->_styleSheet->unistyles[propertyName], this->_styleSheet->tag);
|
31
|
+
return valueFromUnistyle(rt, this->_unistylesRuntime, this->_styleSheet->unistyles[propertyName], this->_styleSheet->tag);
|
32
32
|
}
|
33
33
|
|
34
34
|
if (propertyName == helpers::STYLE_VARIANTS) {
|
@@ -4,7 +4,9 @@
|
|
4
4
|
#include "Unistyle.h"
|
5
5
|
#include "UnistylesRegistry.h"
|
6
6
|
#include "Helpers.h"
|
7
|
+
#include "HybridUnistylesRuntime.h"
|
7
8
|
#include "Constants.h"
|
9
|
+
#include "Parser.h"
|
8
10
|
|
9
11
|
namespace margelo::nitro::unistyles::core {
|
10
12
|
|
@@ -57,6 +59,32 @@ customStyleProp={[styles.container, styles.otherProp]}
|
|
57
59
|
Copying a Unistyle style outside of a JSX element will remove its internal C++ state, leading to unexpected behavior.)");
|
58
60
|
}
|
59
61
|
|
62
|
+
inline static jsi::Object generateUnistylesPrototype(
|
63
|
+
jsi::Runtime& rt,
|
64
|
+
std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime,
|
65
|
+
Unistyle::Shared unistyle,
|
66
|
+
std::optional<Variants> variants,
|
67
|
+
std::optional<jsi::Array> arguments
|
68
|
+
) {
|
69
|
+
// add prototype metadata for createUnistylesComponent
|
70
|
+
auto proto = jsi::Object(rt);
|
71
|
+
auto hostFn = jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forUtf8(rt, "getStyle"), 0, [unistyle, unistylesRuntime](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count){
|
72
|
+
auto variants = helpers::variantsToPairs(rt, thisValue.asObject(rt).getProperty(rt, "variants").asObject(rt));
|
73
|
+
auto arguments = helpers::parseDynamicFunctionArguments(rt, thisValue.asObject(rt).getProperty(rt, "arguments").asObject(rt).asArray(rt));
|
74
|
+
|
75
|
+
parser::Parser(unistylesRuntime).rebuildUnistyle(rt, unistyle->parent, unistyle, variants, std::make_optional<std::vector<folly::dynamic>>(arguments));
|
76
|
+
|
77
|
+
return jsi::Value(rt, unistyle->parsedStyle.value()).asObject(rt);
|
78
|
+
});
|
79
|
+
|
80
|
+
proto.setProperty(rt, "getStyle", std::move(hostFn));
|
81
|
+
proto.setProperty(rt, "arguments", arguments.has_value() ? std::move(arguments.value()) : jsi::Array(rt, 0));
|
82
|
+
proto.setProperty(rt, "variants", variants.has_value() ? helpers::pairsToVariantsValue(rt, variants.value()) : jsi::Object(rt));
|
83
|
+
proto.setProperty(rt, helpers::STYLE_DEPENDENCIES.c_str(), helpers::dependenciesToJSIArray(rt, unistyle->dependencies));
|
84
|
+
|
85
|
+
return proto;
|
86
|
+
}
|
87
|
+
|
60
88
|
inline static std::vector<Unistyle::Shared> unistyleFromValue(jsi::Runtime& rt, const jsi::Value& value) {
|
61
89
|
if (value.isNull()) {
|
62
90
|
return {};
|
@@ -72,7 +100,7 @@ inline static std::vector<Unistyle::Shared> unistyleFromValue(jsi::Runtime& rt,
|
|
72
100
|
return {value.getObject(rt).getNativeState<UnistyleWrapper>(rt)->unistyle};
|
73
101
|
}
|
74
102
|
|
75
|
-
inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared unistyle, int tag) {
|
103
|
+
inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime, Unistyle::Shared unistyle, int tag) {
|
76
104
|
auto wrappedUnistyle = std::make_shared<UnistyleWrapper>(unistyle);
|
77
105
|
|
78
106
|
if (unistyle->type == UnistyleType::Object) {
|
@@ -84,6 +112,8 @@ inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared un
|
|
84
112
|
helpers::defineHiddenProperty(rt, obj, helpers::STYLE_DEPENDENCIES.c_str(), helpers::dependenciesToJSIArray(rt, unistyle->dependencies));
|
85
113
|
helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
|
86
114
|
|
115
|
+
obj.setProperty(rt, "__proto__", generateUnistylesPrototype(rt, unistylesRuntime, unistyle, std::nullopt, std::nullopt));
|
116
|
+
|
87
117
|
return obj;
|
88
118
|
}
|
89
119
|
|
@@ -23,6 +23,6 @@ void core::UnistylesMountHook::shadowTreeDidMount(RootShadowNode::Shared const &
|
|
23
23
|
auto& registry = core::UnistylesRegistry::get();
|
24
24
|
|
25
25
|
if (!registry.trafficController.shouldStop()) {
|
26
|
-
shadow::ShadowTreeManager::updateShadowTree(
|
26
|
+
shadow::ShadowTreeManager::updateShadowTree(this->_unistylesRuntime->getRuntime());
|
27
27
|
}
|
28
28
|
}
|
@@ -3,13 +3,15 @@
|
|
3
3
|
#include <react/renderer/uimanager/UIManager.h>
|
4
4
|
#include <react/renderer/uimanager/UIManagerMountHook.h>
|
5
5
|
#include "ShadowTreeManager.h"
|
6
|
+
#include "HybridUnistylesRuntime.h"
|
6
7
|
|
7
8
|
namespace margelo::nitro::unistyles::core {
|
8
9
|
|
9
10
|
using namespace facebook::react;
|
10
11
|
|
11
12
|
struct UnistylesMountHook : public UIManagerMountHook {
|
12
|
-
UnistylesMountHook(std::shared_ptr<UIManager> uiManager,
|
13
|
+
UnistylesMountHook(std::shared_ptr<UIManager> uiManager, std::shared_ptr<HybridUnistylesRuntime> unistylesRuntime)
|
14
|
+
: _uiManager{uiManager}, _unistylesRuntime{unistylesRuntime} {
|
13
15
|
_uiManager->registerMountHook(*this);
|
14
16
|
}
|
15
17
|
|
@@ -19,7 +21,7 @@ struct UnistylesMountHook : public UIManagerMountHook {
|
|
19
21
|
|
20
22
|
private:
|
21
23
|
std::shared_ptr<UIManager> _uiManager;
|
22
|
-
|
24
|
+
std::shared_ptr<HybridUnistylesRuntime> _unistylesRuntime;
|
23
25
|
};
|
24
26
|
|
25
27
|
}
|
@@ -88,7 +88,13 @@ void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
88
88
|
// add or update node for shadow leaf updates
|
89
89
|
// dynamic functions are parsed later
|
90
90
|
if (unistyle->type == UnistyleType::Object) {
|
91
|
-
|
91
|
+
for (const auto& [family, unistyles] : this->_shadowRegistry[&rt]) {
|
92
|
+
for (const auto& unistyleData : unistyles) {
|
93
|
+
if (unistyleData->unistyle == unistyle && family == shadowNodeFamily) {
|
94
|
+
updates[family] = parser.parseStylesToShadowTreeStyles(rt, {unistyleData});
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
92
98
|
}
|
93
99
|
});
|
94
100
|
|
@@ -97,7 +103,6 @@ void core::UnistylesRegistry::linkShadowNodeWithUnistyle(
|
|
97
103
|
}
|
98
104
|
|
99
105
|
void core::UnistylesRegistry::unlinkShadowNodeWithUnistyles(jsi::Runtime& rt, const ShadowNodeFamily* shadowNodeFamily) {
|
100
|
-
this->trafficController.removeFromUpdates(shadowNodeFamily);
|
101
106
|
this->_shadowRegistry[&rt].erase(shadowNodeFamily);
|
102
107
|
}
|
103
108
|
|
@@ -9,8 +9,7 @@ jsi::Value HybridShadowRegistry::link(jsi::Runtime &rt, const jsi::Value &thisVa
|
|
9
9
|
ShadowNode::Shared shadowNodeWrapper = shadowNodeFromValue(rt, args[0]);
|
10
10
|
std::vector<core::Unistyle::Shared> unistyleWrappers = core::unistyleFromValue(rt, args[1]);
|
11
11
|
core::Variants variants = helpers::variantsToPairs(rt, args[2].asObject(rt));
|
12
|
-
|
13
|
-
std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, rawArguments);
|
12
|
+
std::vector<folly::dynamic> arguments = helpers::parseDynamicFunctionArguments(rt, args[3].asObject(rt).asArray(rt));
|
14
13
|
|
15
14
|
auto& registry = core::UnistylesRegistry::get();
|
16
15
|
|
@@ -230,8 +230,11 @@ void HybridStyleSheet::loadExternalMethods(const jsi::Value& thisValue, jsi::Run
|
|
230
230
|
}
|
231
231
|
|
232
232
|
void HybridStyleSheet::registerHooks(jsi::Runtime& rt) {
|
233
|
+
// cleanup Shadow updates
|
234
|
+
core::UnistylesRegistry::get().trafficController.restore();
|
235
|
+
|
233
236
|
this->_unistylesCommitHook = std::make_shared<core::UnistylesCommitHook>(this->_uiManager);
|
234
|
-
this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager,
|
237
|
+
this->_unistylesMountHook = std::make_shared<core::UnistylesMountHook>(this->_uiManager, this->_unistylesRuntime);
|
235
238
|
}
|
236
239
|
|
237
240
|
void HybridStyleSheet::onPlatformDependenciesChange(std::vector<UnistyleDependency> unistylesDependencies) {
|
@@ -57,6 +57,18 @@ double HybridUnistylesRuntime::getFontScale() {
|
|
57
57
|
return this->_nativePlatform.getFontScale();
|
58
58
|
};
|
59
59
|
|
60
|
+
std::unordered_map<std::string, double> HybridUnistylesRuntime::getBreakpoints() {
|
61
|
+
auto& state = core::UnistylesRegistry::get().getState(*_rt);
|
62
|
+
auto sortedBreakpointPairs = state.getSortedBreakpointPairs();
|
63
|
+
std::unordered_map<std::string, double> breakpoints{};
|
64
|
+
|
65
|
+
std::for_each(sortedBreakpointPairs.begin(), sortedBreakpointPairs.end(), [&breakpoints](std::pair<std::string, double>& pair){
|
66
|
+
breakpoints[pair.first] = pair.second;
|
67
|
+
});
|
68
|
+
|
69
|
+
return breakpoints;
|
70
|
+
}
|
71
|
+
|
60
72
|
void HybridUnistylesRuntime::setTheme(const std::string &themeName) {
|
61
73
|
helpers::assertThat(*_rt, !this->getHasAdaptiveThemes(), "Unistyles: You're trying to set theme to: '" + themeName + "', but adaptiveThemes are enabled.");
|
62
74
|
|
@@ -64,6 +64,8 @@ struct HybridUnistylesRuntime: public HybridUnistylesRuntimeSpec {
|
|
64
64
|
void setImmersiveMode(bool isEnabled) override;
|
65
65
|
void setRootViewBackgroundColor(double color) override;
|
66
66
|
UnistylesCxxMiniRuntime getMiniRuntime() override;
|
67
|
+
std::unordered_map<std::string, double> getBreakpoints() override;
|
68
|
+
|
67
69
|
jsi::Value getMiniRuntimeAsValue(jsi::Runtime& rt);
|
68
70
|
jsi::Runtime& getRuntime();
|
69
71
|
void includeDependenciesForColorSchemeChange(std::vector<UnistyleDependency>& deps);
|
package/cxx/parser/Parser.cpp
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#include "Parser.h"
|
2
|
+
#include "UnistyleWrapper.h"
|
2
3
|
|
3
4
|
using namespace margelo::nitro::unistyles;
|
4
5
|
using namespace facebook;
|
@@ -107,7 +108,7 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
|
|
107
108
|
parsedStyleSheets.emplace(styleSheet, this->unwrapStyleSheet(rt, styleSheet));
|
108
109
|
}
|
109
110
|
|
110
|
-
// then parse all visible Unistyles
|
111
|
+
// then parse all visible Unistyles managed by Unistyle
|
111
112
|
for (auto& [shadowNode, unistyles] : dependencyMap) {
|
112
113
|
auto styleSheet = unistyles.begin()->get()->unistyle->parent;
|
113
114
|
|
@@ -155,13 +156,12 @@ void parser::Parser::rebuildUnistylesInDependencyMap(jsi::Runtime& rt, Dependenc
|
|
155
156
|
}
|
156
157
|
}
|
157
158
|
|
158
|
-
// parse whatever left in StyleSheets
|
159
|
+
// parse whatever left in StyleSheets to be later accessible
|
160
|
+
// for createUnistylesComponent
|
159
161
|
for (auto styleSheet : styleSheets) {
|
160
162
|
for (auto& [_, unistyle] : styleSheet->unistyles) {
|
161
163
|
if (!parsedUnistyles.contains(unistyle)) {
|
162
|
-
parsedUnistyles.emplace(unistyle, true);
|
163
164
|
unistyle->rawValue = parsedStyleSheets[styleSheet].asObject(rt).getProperty(rt, unistyle->styleKey.c_str()).asObject(rt);
|
164
|
-
this->rebuildUnistyle(rt, styleSheet, unistyle, {}, std::nullopt);
|
165
165
|
}
|
166
166
|
}
|
167
167
|
}
|
@@ -367,10 +367,10 @@ jsi::Function parser::Parser::createDynamicFunctionProxy(jsi::Runtime& rt, Unist
|
|
367
367
|
unistyleFn->parsedStyle = this->parseFirstLevel(rt, unistyleFn, variants);
|
368
368
|
unistyleFn->seal();
|
369
369
|
|
370
|
-
// include dependencies for createUnistylesComponent
|
371
370
|
jsi::Object style = jsi::Value(rt, unistyleFn->parsedStyle.value()).asObject(rt);
|
372
371
|
|
373
|
-
|
372
|
+
// include dependencies for createUnistylesComponent
|
373
|
+
style.setProperty(rt, "__proto__", generateUnistylesPrototype(rt, unistylesRuntime, unistyle, variants, helpers::functionArgumentsToArray(rt, args, count)));
|
374
374
|
|
375
375
|
// update shadow leaf updates to indicate newest changes
|
376
376
|
auto& registry = core::UnistylesRegistry::get();
|
package/cxx/parser/Parser.h
CHANGED
@@ -28,9 +28,9 @@ struct Parser {
|
|
28
28
|
void rebuildShadowLeafUpdates(core::DependencyMap& dependencyMap);
|
29
29
|
folly::dynamic parseUnistyleToShadowTreeStyles(jsi::Runtime& rt, const Unistyle::Shared unistyle);
|
30
30
|
folly::dynamic parseStylesToShadowTreeStyles(jsi::Runtime& rt, const std::vector<std::shared_ptr<UnistyleData>>& unistyles);
|
31
|
+
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>>);
|
31
32
|
|
32
33
|
private:
|
33
|
-
void rebuildUnistyle(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet, Unistyle::Shared unistyle, const Variants& variants, std::optional<std::vector<folly::dynamic>>);
|
34
34
|
jsi::Object unwrapStyleSheet(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet);
|
35
35
|
jsi::Object parseFirstLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, std::optional<Variants> variants);
|
36
36
|
jsi::Value parseSecondLevel(jsi::Runtime& rt, Unistyle::Shared unistyle, jsi::Value& nestedObject);
|
@@ -48,14 +48,11 @@ struct ShadowTrafficController {
|
|
48
48
|
});
|
49
49
|
}
|
50
50
|
|
51
|
-
inline void
|
52
|
-
|
53
|
-
|
54
|
-
}
|
55
|
-
|
56
|
-
if (it != _unistylesUpdates.end()) {
|
57
|
-
_unistylesUpdates.erase(it);
|
58
|
-
}
|
51
|
+
inline void restore() {
|
52
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
53
|
+
|
54
|
+
_unistylesUpdates = {};
|
55
|
+
_canCommit = false;
|
59
56
|
}
|
60
57
|
|
61
58
|
private:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Display = void 0;
|
7
|
+
var _useMedia = require("./useMedia");
|
8
|
+
const Display = ({
|
9
|
+
children,
|
10
|
+
...props
|
11
|
+
}) => {
|
12
|
+
const {
|
13
|
+
isVisible
|
14
|
+
} = (0, _useMedia.useMedia)(props);
|
15
|
+
return isVisible ? children : null;
|
16
|
+
};
|
17
|
+
exports.Display = Display;
|
18
|
+
//# sourceMappingURL=Display.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_useMedia","require","Display","children","props","isVisible","useMedia","exports"],"sourceRoot":"../../../src","sources":["components/Display.tsx"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAIO,MAAMC,OAA8C,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,KAAK;EACtF,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,kBAAQ,EAACF,KAAK,CAAC;EAErC,OAAOC,SAAS,GACVF,QAAQ,GACR,IAAI;AACd,CAAC;AAAAI,OAAA,CAAAL,OAAA,GAAAA,OAAA","ignoreList":[]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Hide = void 0;
|
7
|
+
var _useMedia = require("./useMedia");
|
8
|
+
const Hide = ({
|
9
|
+
children,
|
10
|
+
...props
|
11
|
+
}) => {
|
12
|
+
const {
|
13
|
+
isVisible
|
14
|
+
} = (0, _useMedia.useMedia)(props);
|
15
|
+
return !isVisible ? children : null;
|
16
|
+
};
|
17
|
+
exports.Hide = Hide;
|
18
|
+
//# sourceMappingURL=Hide.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_useMedia","require","Hide","children","props","isVisible","useMedia","exports"],"sourceRoot":"../../../src","sources":["components/Hide.tsx"],"mappings":";;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AAIO,MAAMC,IAAwC,GAAGA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,KAAK;EAChF,MAAM;IAAEC;EAAU,CAAC,GAAG,IAAAC,kBAAQ,EAACF,KAAK,CAAC;EAErC,OAAO,CAACC,SAAS,GACXF,QAAQ,GACR,IAAI;AACd,CAAC;AAAAI,OAAA,CAAAL,IAAA,GAAAA,IAAA","ignoreList":[]}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "Display", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _Display.Display;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "Hide", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _Hide.Hide;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
var _Hide = require("./Hide");
|
19
|
+
var _Display = require("./Display");
|
20
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_Hide","require","_Display"],"sourceRoot":"../../../src","sources":["components/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA","ignoreList":[]}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useMedia = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
var _specs = require("../specs");
|
9
|
+
var _mq = require("../mq");
|
10
|
+
const useMedia = config => {
|
11
|
+
const computeIsVisible = () => {
|
12
|
+
const maybeMq = config.mq;
|
13
|
+
if (!(0, _mq.isUnistylesMq)(maybeMq)) {
|
14
|
+
console.error(`🦄 Unistyles: Received invalid mq: ${maybeMq}`);
|
15
|
+
return false;
|
16
|
+
}
|
17
|
+
const parsedMq = (0, _mq.parseMq)(maybeMq);
|
18
|
+
if (!(0, _mq.isValidMq)(parsedMq)) {
|
19
|
+
console.error(`🦄 Unistyles: Received invalid mq where min is greater than max: ${maybeMq}`);
|
20
|
+
return false;
|
21
|
+
}
|
22
|
+
const {
|
23
|
+
width,
|
24
|
+
height
|
25
|
+
} = _specs.UnistylesRuntime.screen;
|
26
|
+
if (parsedMq.minWidth !== undefined && width < parsedMq.minWidth) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
if (parsedMq.maxWidth !== undefined && width > parsedMq.maxWidth) {
|
30
|
+
return false;
|
31
|
+
}
|
32
|
+
if (parsedMq.minHeight !== undefined && height < parsedMq.minHeight) {
|
33
|
+
return false;
|
34
|
+
}
|
35
|
+
if (parsedMq.maxHeight !== undefined && height > parsedMq.maxHeight) {
|
36
|
+
return false;
|
37
|
+
}
|
38
|
+
return true;
|
39
|
+
};
|
40
|
+
const [isVisible, setIsVisible] = (0, _react.useState)(computeIsVisible());
|
41
|
+
(0, _react.useEffect)(() => {
|
42
|
+
setIsVisible(computeIsVisible());
|
43
|
+
}, [config.mq]);
|
44
|
+
(0, _react.useLayoutEffect)(() => {
|
45
|
+
const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
|
46
|
+
if (dependencies.includes(_specs.UnistyleDependency.Breakpoints)) {
|
47
|
+
setIsVisible(computeIsVisible());
|
48
|
+
}
|
49
|
+
});
|
50
|
+
return () => {
|
51
|
+
removeChangeListener();
|
52
|
+
};
|
53
|
+
}, [config.mq]);
|
54
|
+
return {
|
55
|
+
isVisible
|
56
|
+
};
|
57
|
+
};
|
58
|
+
exports.useMedia = useMedia;
|
59
|
+
//# sourceMappingURL=useMedia.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","require","_specs","_mq","useMedia","config","computeIsVisible","maybeMq","mq","isUnistylesMq","console","error","parsedMq","parseMq","isValidMq","width","height","UnistylesRuntime","screen","minWidth","undefined","maxWidth","minHeight","maxHeight","isVisible","setIsVisible","useState","useEffect","useLayoutEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","includes","UnistyleDependency","Breakpoints","exports"],"sourceRoot":"../../../src","sources":["components/useMedia.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,GAAA,GAAAF,OAAA;AAEO,MAAMG,QAAQ,GAAIC,MAAsB,IAAK;EAChD,MAAMC,gBAAgB,GAAGA,CAAA,KAAe;IACpC,MAAMC,OAAO,GAAGF,MAAM,CAACG,EAAuB;IAE9C,IAAI,CAAC,IAAAC,iBAAa,EAACF,OAAO,CAAC,EAAE;MACzBG,OAAO,CAACC,KAAK,CAAC,sCAAsCJ,OAAO,EAAE,CAAC;MAE9D,OAAO,KAAK;IAChB;IAEA,MAAMK,QAAQ,GAAI,IAAAC,WAAO,EAACN,OAAO,CAAC;IAElC,IAAI,CAAC,IAAAO,aAAS,EAACF,QAAQ,CAAC,EAAE;MACtBF,OAAO,CAACC,KAAK,CAAC,oEAAoEJ,OAAO,EAAE,CAAC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L,CAAC;AAAAY,OAAA,CAAAhC,QAAA,GAAAA,QAAA","ignoreList":[]}
|
@@ -7,7 +7,8 @@ exports.createUnistylesComponent = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
8
8
|
var _jsxRuntime = require("react/jsx-runtime");
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
10
|
-
const
|
10
|
+
const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'];
|
11
|
+
const createUnistylesComponent = (Component, _ = () => ({})) => {
|
11
12
|
return props => {
|
12
13
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
13
14
|
...props
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireDefault","require","_jsxRuntime","e","__esModule","default","createUnistylesComponent","Component","_","props","jsx","exports"],"sourceRoot":"../../../src","sources":["core/createUnistylesComponent.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAsE,IAAAC,WAAA,GAAAD,OAAA;AAAA,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_jsxRuntime","e","__esModule","default","SUPPORTED_STYLE_PROPS","createUnistylesComponent","Component","_","props","jsx","exports"],"sourceRoot":"../../../src","sources":["core/createUnistylesComponent.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAsE,IAAAC,WAAA,GAAAD,OAAA;AAAA,SAAAD,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAKtE,MAAMG,qBAAqB,GAAG,CAAC,OAAO,EAAE,uBAAuB,CAAU;AAElE,MAAMC,wBAAwB,GAAGA,CAA+BC,SAAY,EAAEC,CAAc,GAAGA,CAAA,MAAO,CAAC,CAAC,CAAC,KAAK;EACjH,OAAQC,KAAwB,IAAK;IACjC,oBAAO,IAAAR,WAAA,CAAAS,GAAA,EAACH,SAAS;MAAA,GAAKE;IAAK,CAAG,CAAC;EACnC,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAL,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
@@ -6,17 +6,48 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.createUnistylesComponent = void 0;
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
8
8
|
var _specs = require("../specs");
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
9
10
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
10
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
11
|
-
const
|
12
|
+
const SUPPORTED_STYLE_PROPS = ['style', 'contentContainerStyle'];
|
13
|
+
const createUnistylesComponent = (Component, mappings = () => ({})) => {
|
12
14
|
return props => {
|
13
15
|
const [theme, setTheme] = (0, _react.useState)(_specs.UnistylesRuntime.getTheme());
|
14
16
|
const [, setRt] = (0, _react.useState)(0);
|
17
|
+
const stylesRef = (0, _react.useRef)({});
|
18
|
+
const isForcedRef = (0, _react.useRef)(false);
|
19
|
+
if (!isForcedRef.current) {
|
20
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
21
|
+
if (props?.[propName]) {
|
22
|
+
if (Array.isArray(props[propName])) {
|
23
|
+
console.error(`🦄 Unistyles: createUnistylesComponent requires ${propName} to be an object. Please check props for component: ${Component.displayName}`);
|
24
|
+
}
|
25
|
+
if (props[propName].__unistyles_name && !props[propName].__proto__?.getStyle) {
|
26
|
+
console.error(`🦄 Unistyles: createUnistylesComponent received style that is not bound. You likely used the spread operator on a Unistyle style. Please check props for component: ${Component.displayName}`);
|
27
|
+
}
|
28
|
+
stylesRef.current = {
|
29
|
+
...stylesRef.current,
|
30
|
+
[propName]: props[propName]
|
31
|
+
};
|
32
|
+
}
|
33
|
+
});
|
34
|
+
}
|
15
35
|
(0, _react.useEffect)(() => {
|
16
36
|
const removeChangeListener = _specs.StyleSheet.addChangeListener(dependencies => {
|
17
|
-
const componentDependencies = props.style?.uni__dependencies || mappings(theme).style?.uni__dependencies;
|
37
|
+
const componentDependencies = props.style?.__proto__.uni__dependencies || mappings(theme).style?.__proto__.uni__dependencies;
|
18
38
|
if (dependencies.includes(_specs.UnistyleDependency.Theme) && (!componentDependencies || componentDependencies.includes(_specs.UnistyleDependency.Theme))) {
|
19
39
|
setTheme(_specs.UnistylesRuntime.getTheme());
|
40
|
+
|
41
|
+
// override with Unistyles styles
|
42
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
43
|
+
if (props?.[propName]) {
|
44
|
+
stylesRef.current = {
|
45
|
+
...stylesRef.current,
|
46
|
+
[propName]: props[propName].__proto__?.getStyle() || props[propName]
|
47
|
+
};
|
48
|
+
}
|
49
|
+
});
|
50
|
+
isForcedRef.current = true;
|
20
51
|
}
|
21
52
|
if (dependencies.some(dependency => dependency >= 2) && (!componentDependencies || componentDependencies.some(dependency => dependency >= 2))) {
|
22
53
|
setRt(prevState => prevState + 1);
|
@@ -36,10 +67,18 @@ const createUnistylesComponent = (Component, mappings) => {
|
|
36
67
|
}
|
37
68
|
mergedProps[key] = props[key];
|
38
69
|
});
|
39
|
-
|
70
|
+
|
71
|
+
// override with Unistyles styles
|
72
|
+
SUPPORTED_STYLE_PROPS.forEach(propName => {
|
73
|
+
if (mergedProps[propName]) {
|
74
|
+
mergedProps[propName] = stylesRef.current[propName];
|
75
|
+
}
|
76
|
+
});
|
77
|
+
isForcedRef.current = false;
|
78
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
40
79
|
...mergedProps
|
41
80
|
});
|
42
81
|
};
|
43
82
|
};
|
44
83
|
exports.createUnistylesComponent = createUnistylesComponent;
|
45
|
-
//# sourceMappingURL=createUnistylesComponent.native.js.
|
84
|
+
//# sourceMappingURL=createUnistylesComponent.native.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_specs","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","createUnistylesComponent","Component","mappings","props","theme","setTheme","useState","UnistylesRuntime","getTheme","setRt","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","componentDependencies","style","uni__dependencies","includes","UnistyleDependency","Theme","some","dependency","prevState","mergedProps","keys","
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_specs","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","SUPPORTED_STYLE_PROPS","createUnistylesComponent","Component","mappings","props","theme","setTheme","useState","UnistylesRuntime","getTheme","setRt","stylesRef","useRef","isForcedRef","current","forEach","propName","Array","isArray","console","error","displayName","__unistyles_name","getStyle","useEffect","removeChangeListener","StyleSheet","addChangeListener","dependencies","componentDependencies","style","uni__dependencies","includes","UnistyleDependency","Theme","some","dependency","prevState","mergedProps","keys","key","assign","jsx","exports"],"sourceRoot":"../../../src","sources":["core/createUnistylesComponent.native.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uB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AAIF,WAAW,EAAE;QACpBA,WAAW,CAACE,GAAG,CAAC,GAAGhD,MAAM,CAACiD,MAAM,CAACrC,KAAK,CAACoC,GAAG,CAAC,EAAEF,WAAW,CAACE,GAAG,CAAC,CAAC;QAE9D;MACJ;MAEAF,WAAW,CAACE,GAAG,CAAC,GAAGpC,KAAK,CAACoC,GAAG,CAAC;IACjC,CAAC,CAAC;;IAEF;IACAxC,qBAAqB,CAACe,OAAO,CAACC,QAAQ,IAAI;MACtC,IAAIsB,WAAW,CAACtB,QAAQ,CAAC,EAAE;QACvBsB,WAAW,CAACtB,QAAQ,CAAC,GAAGL,SAAS,CAACG,OAAO,CAACE,QAAQ,CAAC;MACvD;IACJ,CAAC,CAAC;IAEFH,WAAW,CAACC,OAAO,GAAG,KAAK;IAE3B,oBAAO,IAAAnC,WAAA,CAAA+D,GAAA,EAACxC,SAAS;MAAA,GAAKoC;IAAW,CAAG,CAAC;EACzC,CAAC;AACL,CAAC;AAAAK,OAAA,CAAA1C,wBAAA,GAAAA,wBAAA","ignoreList":[]}
|
@@ -9,19 +9,5 @@ Object.defineProperty(exports, "createUnistylesComponent", {
|
|
9
9
|
return _createUnistylesComponent.createUnistylesComponent;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
Object.defineProperty(exports, "useBreakpoint", {
|
13
|
-
enumerable: true,
|
14
|
-
get: function () {
|
15
|
-
return _useBreakpoint.useBreakpoint;
|
16
|
-
}
|
17
|
-
});
|
18
|
-
Object.defineProperty(exports, "useTheme", {
|
19
|
-
enumerable: true,
|
20
|
-
get: function () {
|
21
|
-
return _useTheme.useTheme;
|
22
|
-
}
|
23
|
-
});
|
24
|
-
var _useBreakpoint = require("./useBreakpoint");
|
25
|
-
var _useTheme = require("./useTheme");
|
26
12
|
var _createUnistylesComponent = require("./createUnistylesComponent");
|
27
13
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_createUnistylesComponent","require"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,yBAAA,GAAAC,OAAA","ignoreList":[]}
|
package/lib/commonjs/global.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["global.
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["global.ts"],"mappings":"","ignoreList":[]}
|