react-native-unistyles 3.0.0-alpha.20 → 3.0.0-alpha.21
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/cxx/common/Constants.h +1 -0
- package/cxx/core/UnistyleWrapper.h +21 -41
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
- package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+html.d.ts +4 -0
- package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
- package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
- package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
- package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
- package/package.json +1 -1
package/cxx/common/Constants.h
CHANGED
@@ -8,5 +8,6 @@ static const std::string STYLE_DEPENDENCIES = "uni__dependencies";
|
|
8
8
|
static const std::string STYLE_VARIANTS = "uni__variants";
|
9
9
|
static const std::string WEB_STYLE_KEY = "_web";
|
10
10
|
static const std::string EXOTIC_STYLE_KEY = "_exotic";
|
11
|
+
static const std::string NAME_STYLE_KEY = "__unistyles_name";
|
11
12
|
|
12
13
|
}
|
@@ -17,34 +17,6 @@ struct UnistyleWrapper: public jsi::NativeState {
|
|
17
17
|
Unistyle::Shared unistyle;
|
18
18
|
};
|
19
19
|
|
20
|
-
inline static std::string generateStyleKey(std::string& key, int tag) {
|
21
|
-
return std::string("__unid_").append(std::to_string(tag)).append("_").append(key).c_str();
|
22
|
-
}
|
23
|
-
|
24
|
-
inline static Unistyle::Shared unistyleFromKey(jsi::Runtime& rt, const std::string& key) {
|
25
|
-
std::string prefix = "__unid_";
|
26
|
-
|
27
|
-
if (key.substr(0, prefix.length()) != prefix) {
|
28
|
-
return nullptr;
|
29
|
-
}
|
30
|
-
|
31
|
-
std::string remaining = key.substr(prefix.length());
|
32
|
-
|
33
|
-
size_t underscorePos = remaining.find('_');
|
34
|
-
|
35
|
-
if (underscorePos == std::string::npos) {
|
36
|
-
return nullptr;
|
37
|
-
}
|
38
|
-
|
39
|
-
std::string tagStr = remaining.substr(0, underscorePos);
|
40
|
-
|
41
|
-
auto& registry = UnistylesRegistry::get();
|
42
|
-
auto tag = std::stoi(tagStr);
|
43
|
-
auto styleKey = remaining.substr(underscorePos + 1);
|
44
|
-
|
45
|
-
return registry.findUnistyleFromKey(rt, styleKey, tag);
|
46
|
-
}
|
47
|
-
|
48
20
|
inline static Unistyle::Shared unistyleFromStaticStyleSheet(jsi::Runtime& rt, jsi::Object& value) {
|
49
21
|
auto exoticUnistyle = std::make_shared<Unistyle>(
|
50
22
|
UnistyleType::Object,
|
@@ -60,21 +32,29 @@ inline static Unistyle::Shared unistyleFromStaticStyleSheet(jsi::Runtime& rt, js
|
|
60
32
|
|
61
33
|
|
62
34
|
inline static std::vector<Unistyle::Shared> unistylesFromNonExistentNativeState(jsi::Runtime& rt, jsi::Object& value) {
|
63
|
-
|
64
|
-
|
65
|
-
helpers::enumerateJSIObject(rt, value, [&](const std::string& key, jsi::Value& value){
|
66
|
-
auto maybeUnistyle = unistyleFromKey(rt, key);
|
35
|
+
auto hasUnistyleName = value.hasProperty(rt, helpers::NAME_STYLE_KEY.c_str());
|
67
36
|
|
68
|
-
|
69
|
-
|
70
|
-
}
|
71
|
-
});
|
72
|
-
|
73
|
-
if (foundUnistyles.size() == 0) {
|
37
|
+
// return wrapped RN/inline style
|
38
|
+
if (!hasUnistyleName) {
|
74
39
|
return {unistyleFromStaticStyleSheet(rt, value)};
|
75
40
|
}
|
76
41
|
|
77
|
-
|
42
|
+
throw jsi::JSError(rt, R"(Unistyles: Style is not bound!
|
43
|
+
|
44
|
+
Potential reasons:
|
45
|
+
- You likely used the spread operator on a Unistyle style outside of a JSX component
|
46
|
+
|
47
|
+
If you need to merge styles, do it within the style prop of your JSX component:
|
48
|
+
|
49
|
+
style={{...styles.container, ...styles.otherProp}}
|
50
|
+
or
|
51
|
+
style={[styles.container, styles.otherProp]}
|
52
|
+
|
53
|
+
If you pass computed style prop to component use array syntax:
|
54
|
+
|
55
|
+
customStyleProp={[styles.container, styles.otherProp]}
|
56
|
+
|
57
|
+
Copying a Unistyle style outside of a JSX element will remove its internal C++ state, leading to unexpected behavior.)");
|
78
58
|
}
|
79
59
|
|
80
60
|
inline static std::vector<Unistyle::Shared> unistyleFromValue(jsi::Runtime& rt, const jsi::Value& value) {
|
@@ -99,7 +79,7 @@ inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared un
|
|
99
79
|
jsi::Object obj = jsi::Object(rt);
|
100
80
|
|
101
81
|
obj.setNativeState(rt, std::move(wrappedUnistyle));
|
102
|
-
obj.setProperty(rt,
|
82
|
+
obj.setProperty(rt, helpers::NAME_STYLE_KEY.c_str(), jsi::String::createFromUtf8(rt, unistyle->styleKey));
|
103
83
|
|
104
84
|
helpers::mergeJSIObjects(rt, obj, unistyle->parsedStyle.value());
|
105
85
|
|
@@ -110,7 +90,7 @@ inline static jsi::Value valueFromUnistyle(jsi::Runtime& rt, Unistyle::Shared un
|
|
110
90
|
auto hostFn = jsi::Value(rt, unistyleFn->proxiedFunction.value()).asObject(rt).asFunction(rt);
|
111
91
|
|
112
92
|
hostFn.setNativeState(rt, std::move(wrappedUnistyle));
|
113
|
-
hostFn.setProperty(rt,
|
93
|
+
hostFn.setProperty(rt, helpers::NAME_STYLE_KEY.c_str(), jsi::String::createFromUtf8(rt, unistyleFn->styleKey));
|
114
94
|
|
115
95
|
return std::move(hostFn);
|
116
96
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"_layout.d.ts","sourceRoot":"","sources":["../../../../../expo-example/app/(tabs)/_layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,CAAC,OAAO,UAAU,SAAS,sBAqBhC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"explore.d.ts","sourceRoot":"","sources":["../../../../../expo-example/app/(tabs)/explore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,CAAC,OAAO,UAAU,YAAY,sBAQnC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../expo-example/app/(tabs)/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,MAAM,CAAC,OAAO,UAAU,UAAU,sBAQjC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"+html.d.ts","sourceRoot":"","sources":["../../../../expo-example/app/+html.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAE9C,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,qBAqB3D"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"+not-found.d.ts","sourceRoot":"","sources":["../../../../expo-example/app/+not-found.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,CAAC,OAAO,UAAU,cAAc,sBAIrC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"_layout.d.ts","sourceRoot":"","sources":["../../../../expo-example/app/_layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,MAAM,CAAC,OAAO,UAAU,UAAU,sBAMjC"}
|