react-native-unistyles 3.0.22 → 3.0.23
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/README.md +5 -5
- package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +16 -2
- package/cxx/parser/Parser.cpp +166 -13
- package/nitrogen/generated/ios/swift/Dimensions.swift +0 -1
- package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +0 -1
- package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +0 -1
- package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +0 -1
- package/nitrogen/generated/ios/swift/Insets.swift +0 -1
- package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +0 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,14 +21,14 @@ yarn add react-native-unistyles
|
|
|
21
21
|
Install dependencies:
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
|
-
yarn add react-native-edge-to-edge react-native-nitro-modules@0.33.
|
|
24
|
+
yarn add react-native-edge-to-edge react-native-nitro-modules@0.33.8
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
> To avoid unexpected behavior, always use a fixed version of `react-native-nitro-modules`
|
|
28
28
|
|
|
29
29
|
| react-native-unistyles | react-native-nitro-modules |
|
|
30
30
|
|------------------------|----------------------------|
|
|
31
|
-
| 3.0.0 | 0.33.
|
|
31
|
+
| 3.0.0 | 0.33.8 |
|
|
32
32
|
|
|
33
33
|
Then follow [installation guides](https://unistyl.es/v3/start/getting-started) for your platform.
|
|
34
34
|
|
|
@@ -59,9 +59,6 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
59
59
|
<a href="https://galaxies.dev">
|
|
60
60
|
<img src="https://avatars.githubusercontent.com/u/118431096?s=200&v=4" height="70px" width="70px" alt="galaxies-dev" />
|
|
61
61
|
</a>
|
|
62
|
-
<a href="https://github.com/biw">
|
|
63
|
-
<img src="https://avatars.githubusercontent.com/u/6139501?v=4" height="70px" width="70px" alt="biw" />
|
|
64
|
-
</a>
|
|
65
62
|
<a href="https://github.com/ryanlanciaux">
|
|
66
63
|
<img src="https://avatars.githubusercontent.com/u/85041?v=4" height="70px" width="70px" alt="ryanlanciaux" />
|
|
67
64
|
</a>
|
|
@@ -147,6 +144,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
147
144
|
<a href="https://github.com/oliverloops">
|
|
148
145
|
<img src="https://avatars.githubusercontent.com/u/33361399?v=4" height="60px" width="60px" alt="oliverloops" />
|
|
149
146
|
</a>
|
|
147
|
+
<a href="https://github.com/biw">
|
|
148
|
+
<img src="https://avatars.githubusercontent.com/u/6139501?v=4" height="60px" width="60px" alt="biw" />
|
|
149
|
+
</a>
|
|
150
150
|
|
|
151
151
|
## Sponsor my work
|
|
152
152
|
|
|
@@ -91,13 +91,27 @@ class NativePlatformInsets(
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
val insets = insetsCompat.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
|
|
94
|
+
val imeInsetValue = insetsCompat.getInsets(WindowInsetsCompat.Type.ime()).bottom
|
|
95
|
+
|
|
96
|
+
// When a keyboard management library (e.g. react-native-keyboard-controller) is active,
|
|
97
|
+
// systemBars().bottom can get polluted with the IME height on certain interactions
|
|
98
|
+
// (like double-tapping to select text). Detect this by checking if systemBars bottom
|
|
99
|
+
// is >= IME bottom (normally systemBars bottom is just the nav bar, much smaller than IME).
|
|
100
|
+
// Fall back to getInsetsIgnoringVisibility which returns stable nav bar values.
|
|
101
|
+
val bottomInset = if (imeInsetValue > 0 && insets.bottom >= imeInsetValue) {
|
|
102
|
+
insetsCompat.getInsetsIgnoringVisibility(
|
|
103
|
+
WindowInsetsCompat.Type.navigationBars() or WindowInsetsCompat.Type.displayCutout()
|
|
104
|
+
).bottom
|
|
105
|
+
} else {
|
|
106
|
+
insets.bottom
|
|
107
|
+
}
|
|
94
108
|
|
|
95
109
|
// Android 10 and below - set bottom insets to 0 while keyboard is visible and use default bottom insets otherwise
|
|
96
110
|
// Android 11 and above - animate bottom insets while keyboard is appearing and disappearing
|
|
97
111
|
val imeInsets = when {
|
|
98
112
|
animatedBottomInsets != null && Build.VERSION.SDK_INT >= 30 -> animatedBottomInsets
|
|
99
113
|
Build.VERSION.SDK_INT < 30 -> {
|
|
100
|
-
val nextBottomInset =
|
|
114
|
+
val nextBottomInset = imeInsetValue - bottomInset
|
|
101
115
|
maxOf(nextBottomInset, 0).toDouble()
|
|
102
116
|
}
|
|
103
117
|
else -> 0.0
|
|
@@ -107,7 +121,7 @@ class NativePlatformInsets(
|
|
|
107
121
|
|
|
108
122
|
this._insets = Insets(
|
|
109
123
|
statusBarTopInset.toDouble(),
|
|
110
|
-
|
|
124
|
+
bottomInset.toDouble(),
|
|
111
125
|
insets.left.toDouble(),
|
|
112
126
|
insets.right.toDouble(),
|
|
113
127
|
imeInsets
|
package/cxx/parser/Parser.cpp
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#include "Parser.h"
|
|
2
2
|
#include "UnistyleWrapper.h"
|
|
3
|
+
#include <iomanip>
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <react/renderer/css/CSSFilter.h>
|
|
6
|
+
#include <react/renderer/css/CSSValueParser.h>
|
|
3
7
|
|
|
4
8
|
using namespace margelo::nitro::unistyles;
|
|
5
9
|
using namespace facebook;
|
|
@@ -7,6 +11,59 @@ using namespace facebook::react;
|
|
|
7
11
|
|
|
8
12
|
using Variants = std::vector<std::pair<std::string, std::string>>;
|
|
9
13
|
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
bool isSupportedLength(const CSSLength& length) {
|
|
17
|
+
return length.unit == CSSLengthUnit::Px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
std::string cssColorToRgbaString(const CSSColor& color) {
|
|
21
|
+
std::ostringstream stream;
|
|
22
|
+
|
|
23
|
+
stream << "rgba("
|
|
24
|
+
<< static_cast<int>(color.r) << ", "
|
|
25
|
+
<< static_cast<int>(color.g) << ", "
|
|
26
|
+
<< static_cast<int>(color.b) << ", "
|
|
27
|
+
<< std::fixed << std::setprecision(3)
|
|
28
|
+
<< (static_cast<float>(color.a) / 255.0f)
|
|
29
|
+
<< ")";
|
|
30
|
+
|
|
31
|
+
return stream.str();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
std::optional<jsi::Object> parseDropShadowString(jsi::Runtime& rt, const std::string& dropShadowString) {
|
|
35
|
+
auto maybeParsedDropShadow = parseCSSProperty<CSSDropShadowFilter>(std::string("drop-shadow(") + dropShadowString + ")");
|
|
36
|
+
|
|
37
|
+
if (!std::holds_alternative<CSSDropShadowFilter>(maybeParsedDropShadow)) {
|
|
38
|
+
return std::nullopt;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
auto parsedDropShadow = std::get<CSSDropShadowFilter>(maybeParsedDropShadow);
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
!isSupportedLength(parsedDropShadow.offsetX) ||
|
|
45
|
+
!isSupportedLength(parsedDropShadow.offsetY) ||
|
|
46
|
+
!isSupportedLength(parsedDropShadow.standardDeviation)
|
|
47
|
+
) {
|
|
48
|
+
return std::nullopt;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
jsi::Object shadowObject(rt);
|
|
52
|
+
|
|
53
|
+
shadowObject.setProperty(rt, "offsetX", parsedDropShadow.offsetX.value);
|
|
54
|
+
shadowObject.setProperty(rt, "offsetY", parsedDropShadow.offsetY.value);
|
|
55
|
+
shadowObject.setProperty(rt, "standardDeviation", parsedDropShadow.standardDeviation.value);
|
|
56
|
+
shadowObject.setProperty(
|
|
57
|
+
rt,
|
|
58
|
+
"color",
|
|
59
|
+
jsi::String::createFromUtf8(rt, cssColorToRgbaString(parsedDropShadow.color))
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return shadowObject;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
10
67
|
// called only once while processing StyleSheet.create
|
|
11
68
|
void parser::Parser::buildUnistyles(jsi::Runtime& rt, std::shared_ptr<StyleSheet> styleSheet) {
|
|
12
69
|
jsi::Object unwrappedStyleSheet = this->unwrapStyleSheet(rt, styleSheet, std::nullopt);
|
|
@@ -651,8 +708,42 @@ jsi::Value parser::Parser::parseFilters(jsi::Runtime &rt, Unistyle::Shared unist
|
|
|
651
708
|
|
|
652
709
|
auto parsedResult = this->parseSecondLevel(rt, unistyle, value);
|
|
653
710
|
|
|
711
|
+
if (!parsedResult.isObject()) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
auto parsedResultObject = parsedResult.asObject(rt);
|
|
716
|
+
auto filterPropertyNames = parsedResultObject.getPropertyNames(rt);
|
|
717
|
+
auto filterPropertyCount = filterPropertyNames.size(rt);
|
|
718
|
+
|
|
719
|
+
for (size_t index = 0; index < filterPropertyCount; index++) {
|
|
720
|
+
auto filterName = filterPropertyNames.getValueAtIndex(rt, index).asString(rt).utf8(rt);
|
|
721
|
+
|
|
722
|
+
if (filterName != "dropShadow") {
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
auto filterValue = parsedResultObject.getProperty(rt, filterName.c_str());
|
|
727
|
+
|
|
728
|
+
if (filterValue.isString()) {
|
|
729
|
+
auto maybeParsedDropShadow = parseDropShadowString(rt, filterValue.asString(rt).utf8(rt));
|
|
730
|
+
|
|
731
|
+
if (!maybeParsedDropShadow.has_value()) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
auto dropShadowObject = std::move(maybeParsedDropShadow.value());
|
|
736
|
+
parsedResultObject.setProperty(rt, filterName.c_str(), std::move(dropShadowObject));
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (!filterValue.isObject()) {
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
654
745
|
// take only one filter per object
|
|
655
|
-
jsi::Array propertyNames =
|
|
746
|
+
jsi::Array propertyNames = parsedResultObject.getPropertyNames(rt);
|
|
656
747
|
size_t length = propertyNames.size(rt);
|
|
657
748
|
|
|
658
749
|
// ignore no filters
|
|
@@ -660,7 +751,7 @@ jsi::Value parser::Parser::parseFilters(jsi::Runtime &rt, Unistyle::Shared unist
|
|
|
660
751
|
return;
|
|
661
752
|
}
|
|
662
753
|
|
|
663
|
-
parsedFilters.emplace_back(std::move(
|
|
754
|
+
parsedFilters.emplace_back(std::move(parsedResultObject));
|
|
664
755
|
});
|
|
665
756
|
|
|
666
757
|
// create jsi::Array result with correct filters
|
|
@@ -973,11 +1064,19 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
973
1064
|
unistyleData->parsedStyle.value(),
|
|
974
1065
|
[this, &rt, &state, &convertedStyles](const std::string& propertyName, jsi::Value& propertyValue) {
|
|
975
1066
|
if (this->isColor(propertyName)) {
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1067
|
+
if (propertyValue.isString()) {
|
|
1068
|
+
convertedStyles.setProperty(
|
|
1069
|
+
rt,
|
|
1070
|
+
propertyName.c_str(),
|
|
1071
|
+
jsi::Value(state.parseColor(propertyValue))
|
|
1072
|
+
);
|
|
1073
|
+
} else {
|
|
1074
|
+
convertedStyles.setProperty(
|
|
1075
|
+
rt,
|
|
1076
|
+
propertyName.c_str(),
|
|
1077
|
+
propertyValue
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
981
1080
|
|
|
982
1081
|
return;
|
|
983
1082
|
}
|
|
@@ -1021,10 +1120,60 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1021
1120
|
nestedValue.asObject(rt),
|
|
1022
1121
|
[this, &rt, &state, &obj](const std::string& nestedPropName, jsi::Value& nestedPropValue) {
|
|
1023
1122
|
if (this->isColor(nestedPropName)) {
|
|
1123
|
+
if (nestedPropValue.isString()) {
|
|
1124
|
+
obj.setProperty(
|
|
1125
|
+
rt,
|
|
1126
|
+
nestedPropName.c_str(),
|
|
1127
|
+
state.parseColor(nestedPropValue)
|
|
1128
|
+
);
|
|
1129
|
+
} else {
|
|
1130
|
+
obj.setProperty(
|
|
1131
|
+
rt,
|
|
1132
|
+
nestedPropName.c_str(),
|
|
1133
|
+
nestedPropValue
|
|
1134
|
+
);
|
|
1135
|
+
}
|
|
1136
|
+
} else if (nestedPropValue.isObject()) {
|
|
1137
|
+
auto nestedObj = nestedPropValue.asObject(rt);
|
|
1138
|
+
|
|
1139
|
+
if (nestedObj.isArray(rt) || nestedObj.isFunction(rt)) {
|
|
1140
|
+
obj.setProperty(
|
|
1141
|
+
rt,
|
|
1142
|
+
nestedPropName.c_str(),
|
|
1143
|
+
nestedPropValue
|
|
1144
|
+
);
|
|
1145
|
+
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
jsi::Object parsedNestedObj(rt);
|
|
1150
|
+
|
|
1151
|
+
helpers::enumerateJSIObject(
|
|
1152
|
+
rt,
|
|
1153
|
+
nestedObj,
|
|
1154
|
+
[this, &rt, &state, &parsedNestedObj](const std::string& secondLevelPropName, jsi::Value& secondLevelPropValue) {
|
|
1155
|
+
if (this->isColor(secondLevelPropName) && secondLevelPropValue.isString()) {
|
|
1156
|
+
parsedNestedObj.setProperty(
|
|
1157
|
+
rt,
|
|
1158
|
+
secondLevelPropName.c_str(),
|
|
1159
|
+
state.parseColor(secondLevelPropValue)
|
|
1160
|
+
);
|
|
1161
|
+
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
parsedNestedObj.setProperty(
|
|
1166
|
+
rt,
|
|
1167
|
+
secondLevelPropName.c_str(),
|
|
1168
|
+
secondLevelPropValue
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
);
|
|
1172
|
+
|
|
1024
1173
|
obj.setProperty(
|
|
1025
1174
|
rt,
|
|
1026
1175
|
nestedPropName.c_str(),
|
|
1027
|
-
|
|
1176
|
+
parsedNestedObj
|
|
1028
1177
|
);
|
|
1029
1178
|
} else {
|
|
1030
1179
|
obj.setProperty(
|
|
@@ -1042,11 +1191,15 @@ folly::dynamic parser::Parser::parseStylesToShadowTreeStyles(jsi::Runtime& rt, c
|
|
|
1042
1191
|
}
|
|
1043
1192
|
|
|
1044
1193
|
if (this->isColor(propertyName)) {
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1194
|
+
if (nestedValue.isString()) {
|
|
1195
|
+
parsedArray.setValueAtIndex(
|
|
1196
|
+
rt,
|
|
1197
|
+
i,
|
|
1198
|
+
jsi::Value(state.parseColor(nestedValue))
|
|
1199
|
+
);
|
|
1200
|
+
} else {
|
|
1201
|
+
parsedArray.setValueAtIndex(rt, i, nestedValue);
|
|
1202
|
+
}
|
|
1050
1203
|
} else {
|
|
1051
1204
|
parsedArray.setValueAtIndex(rt, i, nestedValue);
|
|
1052
1205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-unistyles",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.23",
|
|
4
4
|
"description": "Level up your React Native StyleSheet",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "NODE_ENV=babel-test jest ./plugin",
|
|
@@ -146,11 +146,11 @@
|
|
|
146
146
|
"husky": "9.1.7",
|
|
147
147
|
"jest": "29.7.0",
|
|
148
148
|
"metro-react-native-babel-preset": "0.77.0",
|
|
149
|
-
"nitrogen": "0.33.
|
|
149
|
+
"nitrogen": "0.33.8",
|
|
150
150
|
"react": "19.1.0",
|
|
151
151
|
"react-native": "0.79.2",
|
|
152
152
|
"react-native-builder-bob": "0.40.10",
|
|
153
|
-
"react-native-nitro-modules": "0.33.
|
|
153
|
+
"react-native-nitro-modules": "0.33.8",
|
|
154
154
|
"react-native-reanimated": "3.17.5",
|
|
155
155
|
"react-native-web": "0.20.0",
|
|
156
156
|
"react-test-renderer": "19.1.0",
|