react-native-unistyles 3.3.0 → 3.5.0
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 +26 -10
- package/android/build.gradle +12 -1
- package/android/src/main/cxx/NativeUnistylesModule.cpp +8 -4
- package/android/src/main/cxx/NativeUnistylesModule.h +5 -1
- package/components/native/ActivityIndicator/package.json +1 -1
- package/cxx/common/UnistylesConstants.h +1 -0
- package/cxx/converters/TransformOriginConverter.cpp +106 -0
- package/cxx/core/StyleSheetRegistry.cpp +9 -9
- package/cxx/core/StyleSheetRegistry.h +3 -3
- package/cxx/core/UnistyleWrapper.h +13 -1
- package/cxx/core/UnistylesRegistry.cpp +226 -54
- package/cxx/core/UnistylesRegistry.h +64 -7
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +128 -11
- package/cxx/hybridObjects/HybridShadowRegistry.h +20 -0
- package/cxx/hybridObjects/HybridStyleSheet.cpp +20 -12
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +11 -1
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +4 -2
- package/cxx/parser/Parser.cpp +30 -3
- package/cxx/parser/Parser.h +1 -0
- package/cxx/shadowTree/NativeProps.h +88 -0
- package/cxx/shadowTree/ShadowLeafUpdate.h +8 -0
- package/cxx/shadowTree/ShadowTrafficController.h +18 -35
- package/cxx/shadowTree/ShadowTreeDiagnostics.cpp +339 -0
- package/cxx/shadowTree/ShadowTreeDiagnostics.h +18 -0
- package/cxx/shadowTree/ShadowTreeManager.cpp +14 -148
- package/cxx/shadowTree/ShadowTreeManager.h +2 -6
- package/diagnostics/package.json +6 -0
- package/ios/UnistylesModuleOnLoad.mm +9 -3
- package/lib/commonjs/components/native/ActivityIndicator.native.js +10 -0
- package/lib/commonjs/components/native/ActivityIndicator.native.js.map +1 -0
- package/lib/commonjs/components/native/Animated.js +2 -0
- package/lib/commonjs/components/native/Animated.js.map +1 -1
- package/lib/commonjs/components/native/NativeText.js +6 -0
- package/lib/commonjs/components/native/NativeText.js.map +1 -1
- package/lib/commonjs/components/native/NativeText.native.js +17 -1
- package/lib/commonjs/components/native/NativeText.native.js.map +1 -1
- package/lib/commonjs/components/native/NativeView.js +6 -0
- package/lib/commonjs/components/native/NativeView.js.map +1 -1
- package/lib/commonjs/components/native/NativeView.native.js +22 -3
- package/lib/commonjs/components/native/NativeView.native.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.js +9 -3
- package/lib/commonjs/components/native/Pressable.js.map +1 -1
- package/lib/commonjs/components/native/Pressable.native.js +2 -0
- package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
- package/lib/commonjs/components/native/TouchableHighlight.native.js +10 -0
- package/lib/commonjs/components/native/TouchableHighlight.native.js.map +1 -0
- package/lib/commonjs/core/createUnistylesActivityIndicator.js +41 -0
- package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -0
- package/lib/commonjs/core/createUnistylesElement.js +59 -14
- package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js +58 -0
- package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -0
- package/lib/commonjs/core/index.js +14 -0
- package/lib/commonjs/core/index.js.map +1 -1
- package/lib/commonjs/diagnostics/index.js +13 -0
- package/lib/commonjs/diagnostics/index.js.map +1 -0
- package/lib/commonjs/diagnostics/types.js +2 -0
- package/lib/commonjs/diagnostics/types.js.map +1 -0
- package/lib/commonjs/diagnostics/verify.js +19 -0
- package/lib/commonjs/diagnostics/verify.js.map +1 -0
- package/lib/commonjs/diagnostics/verify.native.js +12 -0
- package/lib/commonjs/diagnostics/verify.native.js.map +1 -0
- package/lib/commonjs/index.js +38 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mocks.js +41 -0
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +8 -0
- package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +97 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js +5 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/commonjs/web/convert/object/boxShadow.js +2 -2
- package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/commonjs/web/registry.js +3 -0
- package/lib/commonjs/web/registry.js.map +1 -1
- package/lib/module/components/native/ActivityIndicator.native.js +6 -0
- package/lib/module/components/native/ActivityIndicator.native.js.map +1 -0
- package/lib/module/components/native/Animated.js +3 -0
- package/lib/module/components/native/Animated.js.map +1 -1
- package/lib/module/components/native/NativeText.js +1 -1
- package/lib/module/components/native/NativeText.js.map +1 -1
- package/lib/module/components/native/NativeText.native.js +15 -1
- package/lib/module/components/native/NativeText.native.js.map +1 -1
- package/lib/module/components/native/NativeView.js +1 -0
- package/lib/module/components/native/NativeView.js.map +1 -1
- package/lib/module/components/native/NativeView.native.js +19 -2
- package/lib/module/components/native/NativeView.native.js.map +1 -1
- package/lib/module/components/native/Pressable.js +9 -3
- package/lib/module/components/native/Pressable.js.map +1 -1
- package/lib/module/components/native/Pressable.native.js +2 -0
- package/lib/module/components/native/Pressable.native.js.map +1 -1
- package/lib/module/components/native/TouchableHighlight.native.js +6 -0
- package/lib/module/components/native/TouchableHighlight.native.js.map +1 -0
- package/lib/module/core/createUnistylesActivityIndicator.js +35 -0
- package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -0
- package/lib/module/core/createUnistylesElement.js +58 -13
- package/lib/module/core/createUnistylesElement.js.map +1 -1
- package/lib/module/core/createUnistylesTouchableHighlight.js +52 -0
- package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -0
- package/lib/module/core/index.js +2 -0
- package/lib/module/core/index.js.map +1 -1
- package/lib/module/diagnostics/index.js +5 -0
- package/lib/module/diagnostics/index.js.map +1 -0
- package/lib/module/diagnostics/types.js +2 -0
- package/lib/module/diagnostics/types.js.map +1 -0
- package/lib/module/diagnostics/verify.js +14 -0
- package/lib/module/diagnostics/verify.js.map +1 -0
- package/lib/module/diagnostics/verify.native.js +8 -0
- package/lib/module/diagnostics/verify.native.js.map +1 -0
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks.js +41 -0
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +9 -1
- package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +97 -1
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js +6 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
- package/lib/module/web/convert/object/boxShadow.js +2 -2
- package/lib/module/web/convert/object/boxShadow.js.map +1 -1
- package/lib/module/web/index.js.map +1 -1
- package/lib/module/web/registry.js +3 -0
- package/lib/module/web/registry.js.map +1 -1
- package/lib/typescript/src/components/native/ActivityIndicator.native.d.ts +2 -0
- package/lib/typescript/src/components/native/ActivityIndicator.native.d.ts.map +1 -0
- package/lib/typescript/src/components/native/Animated.d.ts +16 -36
- package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeText.d.ts +1 -1
- package/lib/typescript/src/components/native/NativeText.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeText.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeView.d.ts +1 -0
- package/lib/typescript/src/components/native/NativeView.d.ts.map +1 -1
- package/lib/typescript/src/components/native/NativeView.native.d.ts +2 -2
- package/lib/typescript/src/components/native/NativeView.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.d.ts +4 -2
- package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/components/native/Pressable.native.d.ts +5 -2
- package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
- package/lib/typescript/src/components/native/TouchableHighlight.native.d.ts +2 -0
- package/lib/typescript/src/components/native/TouchableHighlight.native.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts +3 -0
- package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -0
- package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
- package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts +3 -0
- package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -0
- package/lib/typescript/src/core/index.d.ts +2 -0
- package/lib/typescript/src/core/index.d.ts.map +1 -1
- package/lib/typescript/src/core/useUnistyles.d.ts +1 -1
- package/lib/typescript/src/diagnostics/index.d.ts +3 -0
- package/lib/typescript/src/diagnostics/index.d.ts.map +1 -0
- package/lib/typescript/src/diagnostics/types.d.ts +19 -0
- package/lib/typescript/src/diagnostics/types.d.ts.map +1 -0
- package/lib/typescript/src/diagnostics/verify.d.ts +3 -0
- package/lib/typescript/src/diagnostics/verify.d.ts.map +1 -0
- package/lib/typescript/src/diagnostics/verify.native.d.ts +3 -0
- package/lib/typescript/src/diagnostics/verify.native.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +5 -1
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +3 -0
- package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +4 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +2 -2
- package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +7 -2
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +3 -3
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/index.d.ts.map +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +0 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +0 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +2 -0
- package/package.json +35 -26
- package/plugin/index.d.ts +4 -4
- package/plugin/index.js +21 -5
- package/src/components/native/ActivityIndicator.native.tsx +5 -0
- package/src/components/native/Animated.tsx +18 -1
- package/src/components/native/NativeText.native.tsx +18 -1
- package/src/components/native/NativeText.tsx +1 -1
- package/src/components/native/NativeView.native.tsx +22 -2
- package/src/components/native/NativeView.tsx +2 -0
- package/src/components/native/Pressable.native.tsx +10 -2
- package/src/components/native/Pressable.tsx +15 -4
- package/src/components/native/TouchableHighlight.native.tsx +5 -0
- package/src/core/createUnistylesActivityIndicator.tsx +47 -0
- package/src/core/createUnistylesElement.tsx +45 -14
- package/src/core/createUnistylesTouchableHighlight.tsx +69 -0
- package/src/core/index.ts +2 -0
- package/src/diagnostics/index.ts +3 -0
- package/src/diagnostics/types.ts +25 -0
- package/src/diagnostics/verify.native.ts +7 -0
- package/src/diagnostics/verify.ts +13 -0
- package/src/index.ts +4 -1
- package/src/mocks.ts +41 -0
- package/src/reanimated/variant/useUpdateVariantColor.native.ts +7 -1
- package/src/specs/ShadowRegistry/index.ts +128 -1
- package/src/specs/ShadowRegistry/types.ts +3 -0
- package/src/specs/StyleSheet/index.ts +10 -2
- package/src/specs/UnistylesRuntime/index.ts +7 -2
- package/src/types/breakpoints.ts +5 -3
- package/src/types/core.ts +7 -28
- package/src/types/stylesheet.ts +3 -3
- package/src/web/convert/object/boxShadow.ts +2 -2
- package/src/web/index.ts +2 -1
- package/src/web/registry.ts +3 -0
package/README.md
CHANGED
|
@@ -12,16 +12,18 @@
|
|
|
12
12
|
[](https://nextjs.org/)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Requirements
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
- React Native 0.81+ with the New Architecture
|
|
18
|
+
- React 19+
|
|
19
|
+
- Expo SDK 54+ (if you use Expo, development builds only, Expo Go is not supported)
|
|
20
|
+
|
|
21
|
+
Need support for older React Native versions or the Old Architecture? Use [Unistyles 2.0](https://v2.unistyl.es).
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
## Installation
|
|
22
24
|
|
|
23
25
|
```shell
|
|
24
|
-
yarn add react-native-nitro-modules
|
|
26
|
+
yarn add react-native-unistyles react-native-nitro-modules
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
| react-native-unistyles | Minimum react-native-nitro-modules |
|
|
@@ -29,6 +31,8 @@ yarn add react-native-nitro-modules
|
|
|
29
31
|
| >= 3.0.0 | >= 0.33.9 |
|
|
30
32
|
| >= 3.1.0 | >= 0.35.0 |
|
|
31
33
|
| >= 3.2.0 | >= 0.35.2 |
|
|
34
|
+
| >= 3.3.0 | >= 0.36.1 |
|
|
35
|
+
| >= 3.4.0 | >= 0.37.1 |
|
|
32
36
|
|
|
33
37
|
> **Note:** Since v3.1.0, `react-native-edge-to-edge` is an **optional** dependency. We strongly recommend setting `edgeToEdgeEnabled=true` in your `android/gradle.properties` — it enforces translucent system bars on modals, disables legacy StatusBar hacks, and enables additional React Native core fixes. **Expo SDK 54+** enables this automatically. You can still install `react-native-edge-to-edge` for ecosystem compatibility with libraries like `react-native-bootsplash` or `react-native-permissions`.
|
|
34
38
|
|
|
@@ -39,7 +43,19 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
39
43
|
- [Migration from Unistyles 2.0](https://unistyl.es/v3/start/migration-guide)
|
|
40
44
|
- [Learn how Unistyles 3.0 works](https://unistyl.es/v3/start/how-unistyles-works)
|
|
41
45
|
- [API](https://unistyl.es/v3/references/stylesheet)
|
|
42
|
-
- [
|
|
46
|
+
- [Tutorial](https://unistyl.es/v3/tutorial/intro)
|
|
47
|
+
- [LLMs](https://unistyl.es/v3/llms/info)
|
|
48
|
+
|
|
49
|
+
## AI agent skills
|
|
50
|
+
|
|
51
|
+
This repository ships skills for AI coding agents (Claude Code, Codex, Cursor and others):
|
|
52
|
+
|
|
53
|
+
- `react-native-unistyles-v3` - setup, theming, responsive styles, variants, web and 3rd party integrations
|
|
54
|
+
- `unistyles-v2-to-v3-migration` - step by step migration from Unistyles 2.0
|
|
55
|
+
|
|
56
|
+
```shell
|
|
57
|
+
npx skills add jpudysz/react-native-unistyles
|
|
58
|
+
```
|
|
43
59
|
|
|
44
60
|
## Features
|
|
45
61
|
- 🚀 Shared core with C++ and JSI bindings
|
|
@@ -58,9 +74,6 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
58
74
|
<a href="https://codemask.com">
|
|
59
75
|
<img src="https://avatars.githubusercontent.com/u/51229884?s=200&v=4" height="70px" width="70px" alt="codemask" />
|
|
60
76
|
</a>
|
|
61
|
-
<a href="https://galaxies.dev">
|
|
62
|
-
<img src="https://avatars.githubusercontent.com/u/118431096?s=200&v=4" height="70px" width="70px" alt="galaxies-dev" />
|
|
63
|
-
</a>
|
|
64
77
|
<a href="https://github.com/ryanlanciaux">
|
|
65
78
|
<img src="https://avatars.githubusercontent.com/u/85041?v=4" height="70px" width="70px" alt="ryanlanciaux" />
|
|
66
79
|
</a>
|
|
@@ -155,6 +168,9 @@ Then follow [installation guides](https://unistyl.es/v3/start/getting-started) f
|
|
|
155
168
|
<a href="https://github.com/AdiRishi">
|
|
156
169
|
<img src="https://avatars.githubusercontent.com/u/8351234?v=4" height="60px" width="60px" alt="AdiRishi" />
|
|
157
170
|
</a>
|
|
171
|
+
<a href="https://galaxies.dev">
|
|
172
|
+
<img src="https://avatars.githubusercontent.com/u/118431096?s=200&v=4" height="60px" width="60px" alt="galaxies-dev" />
|
|
173
|
+
</a>
|
|
158
174
|
|
|
159
175
|
## Sponsor my work
|
|
160
176
|
|
package/android/build.gradle
CHANGED
|
@@ -18,9 +18,20 @@ def reactNativeArchitectures() {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
apply plugin: 'com.android.library'
|
|
21
|
-
|
|
21
|
+
// AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
|
|
22
|
+
// itself. Applying the Kotlin plugin on top of it fails configuration with
|
|
23
|
+
// "Cannot add extension with name 'kotlin'". Only apply it when nothing has
|
|
24
|
+
// registered that extension yet.
|
|
25
|
+
if (project.extensions.findByName('kotlin') == null) {
|
|
26
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
27
|
+
}
|
|
28
|
+
|
|
22
29
|
apply from: '../nitrogen/generated/android/unistyles+autolinking.gradle'
|
|
23
30
|
|
|
31
|
+
// Nitrogen adds its generated Kotlin files to java.srcDirs, which AGP 9 built-in Kotlin
|
|
32
|
+
// doesn't compile. It only compiles Kotlin directories from the kotlin source set.
|
|
33
|
+
android.sourceSets.main.kotlin.srcDirs += ["${project.projectDir}/../nitrogen/generated/android/kotlin"]
|
|
34
|
+
|
|
24
35
|
def resolveBuildType() {
|
|
25
36
|
Gradle gradle = getGradle()
|
|
26
37
|
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
|
|
@@ -31,11 +31,15 @@ void UnistylesModule::registerNatives() {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
jni::local_ref<BindingsInstallerHolder::javaobject> UnistylesModule::getBindingsInstaller(jni::alias_ref<UnistylesModule::javaobject> jobj) {
|
|
34
|
-
auto
|
|
35
|
-
auto&
|
|
34
|
+
auto* self = jobj->cthis();
|
|
35
|
+
auto& runtimeExecutor = self->_runtimeExecutor;
|
|
36
|
+
auto& nativePlatform = self->_nativePlatform;
|
|
36
37
|
|
|
37
|
-
return BindingsInstallerHolder::newObjectCxxArgs([&runtimeExecutor, &nativePlatform](jsi::Runtime& rt) {
|
|
38
|
+
return BindingsInstallerHolder::newObjectCxxArgs([self, &runtimeExecutor, &nativePlatform](jsi::Runtime& rt) {
|
|
38
39
|
// function is called on: first init and every live reload
|
|
40
|
+
// newest runtime owns the registry, previous runtime's state is kept until it releases ownership
|
|
41
|
+
self->_generation = core::UnistylesRegistry::get().takeOwnership();
|
|
42
|
+
|
|
39
43
|
// check if this is live reload, if so let's replace UnistylesRuntime with new runtime
|
|
40
44
|
auto hasUnistylesRuntime = HybridObjectRegistry::hasHybridObject("UnistylesRuntime");
|
|
41
45
|
|
|
@@ -52,7 +56,7 @@ jni::local_ref<BindingsInstallerHolder::javaobject> UnistylesModule::getBindings
|
|
|
52
56
|
};
|
|
53
57
|
|
|
54
58
|
// init hybrids
|
|
55
|
-
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, runOnJSThread);
|
|
59
|
+
auto unistylesRuntime = std::make_shared<HybridUnistylesRuntime>(nativePlatform, runOnJSThread, self->_generation);
|
|
56
60
|
auto styleSheet = std::make_shared<HybridStyleSheet>(unistylesRuntime);
|
|
57
61
|
|
|
58
62
|
HybridObjectRegistry::registerHybridObjectConstructor("UnistylesRuntime", [unistylesRuntime]() -> std::shared_ptr<HybridObject>{
|
|
@@ -29,7 +29,10 @@ struct UnistylesModule : public jni::HybridClass<UnistylesModule> {
|
|
|
29
29
|
jni::alias_ref<JHybridNativePlatformSpec::JavaPart> nativePlatform
|
|
30
30
|
);
|
|
31
31
|
static void invalidateNative(jni::alias_ref<jhybridobject> jThis) {
|
|
32
|
-
|
|
32
|
+
auto* self = jThis->cthis();
|
|
33
|
+
|
|
34
|
+
// releases this runtime's state, also when a newer runtime already replaced it
|
|
35
|
+
core::UnistylesRegistry::get().releaseOwnership(self->_generation);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static jni::local_ref<BindingsInstallerHolder::javaobject> getBindingsInstaller(jni::alias_ref<UnistylesModule::javaobject> jThis);
|
|
@@ -37,6 +40,7 @@ struct UnistylesModule : public jni::HybridClass<UnistylesModule> {
|
|
|
37
40
|
private:
|
|
38
41
|
RuntimeExecutor _runtimeExecutor;
|
|
39
42
|
std::shared_ptr<HybridNativePlatformSpec> _nativePlatform;
|
|
43
|
+
uint64_t _generation = 0;
|
|
40
44
|
};
|
|
41
45
|
|
|
42
46
|
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
"main": "../../../lib/commonjs/components/native/ActivityIndicator.js",
|
|
3
3
|
"module": "../../../lib/module/components/native/ActivityIndicator.js",
|
|
4
4
|
"browser": "../../../lib/module/components/native/ActivityIndicator.js",
|
|
5
|
-
"react-native": "../../../src/components/native/ActivityIndicator.tsx"
|
|
5
|
+
"react-native": "../../../src/components/native/ActivityIndicator.native.tsx"
|
|
6
6
|
}
|
|
@@ -12,5 +12,6 @@ static const std::string EXOTIC_STYLE_KEY = "_exotic";
|
|
|
12
12
|
static const std::string ARGUMENTS = "__uni__args";
|
|
13
13
|
static const std::string GET_STYLES = "uni__getStyles";
|
|
14
14
|
static const std::string UNDEFINED_MARKER = "__unistyles_undefined__";
|
|
15
|
+
static const std::string RUNTIME_REPLACED_ERROR = "Unistyles: this runtime was replaced (reload in progress)";
|
|
15
16
|
|
|
16
17
|
}
|
|
@@ -1,13 +1,117 @@
|
|
|
1
1
|
#include "TransformOriginConverter.h"
|
|
2
2
|
|
|
3
|
+
#include <cxxreact/ReactNativeVersion.h>
|
|
4
|
+
|
|
5
|
+
// facebook::react::parseUnprocessedTransformOriginString was introduced in
|
|
6
|
+
// React Native 0.85, while conversions.h is available in every supported
|
|
7
|
+
// version, so the include alone is not enough to detect the parser.
|
|
3
8
|
#if defined(RN_SERIALIZABLE_STATE) && \
|
|
9
|
+
(REACT_NATIVE_VERSION_MAJOR > 0 || REACT_NATIVE_VERSION_MINOR >= 85) && \
|
|
4
10
|
__has_include(<react/renderer/components/view/conversions.h>)
|
|
5
11
|
#include <react/renderer/components/view/conversions.h>
|
|
6
12
|
#define UNISTYLES_HAS_RN_TRANSFORM_ORIGIN_PARSER 1
|
|
13
|
+
#elif defined(RN_SERIALIZABLE_STATE)
|
|
14
|
+
#include <algorithm>
|
|
15
|
+
#include <cctype>
|
|
16
|
+
#include <cstdlib>
|
|
17
|
+
#include <regex>
|
|
18
|
+
#define UNISTYLES_HAS_TRANSFORM_ORIGIN_FALLBACK 1
|
|
7
19
|
#endif
|
|
8
20
|
|
|
9
21
|
namespace margelo::nitro::unistyles::converters {
|
|
10
22
|
|
|
23
|
+
#ifdef UNISTYLES_HAS_TRANSFORM_ORIGIN_FALLBACK
|
|
24
|
+
namespace {
|
|
25
|
+
|
|
26
|
+
// Port of React Native's processTransformOrigin.js. Android forwards raw props
|
|
27
|
+
// to the view manager, which expects the processed [x, y, z] array, so a string
|
|
28
|
+
// must not reach it. Returns null (default origin) for an invalid value.
|
|
29
|
+
folly::dynamic processTransformOriginString(const std::string &value) {
|
|
30
|
+
static const std::regex tokenRegex(
|
|
31
|
+
"(top|bottom|left|right|center|\\d+(?:%|px)|0)", std::regex::icase);
|
|
32
|
+
constexpr size_t INDEX_X = 0;
|
|
33
|
+
constexpr size_t INDEX_Y = 1;
|
|
34
|
+
constexpr size_t INDEX_Z = 2;
|
|
35
|
+
|
|
36
|
+
auto toLower = [](std::string token) {
|
|
37
|
+
std::transform(token.begin(), token.end(), token.begin(),
|
|
38
|
+
[](unsigned char c) { return std::tolower(c); });
|
|
39
|
+
|
|
40
|
+
return token;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
folly::dynamic result = folly::dynamic::array("50%", "50%", 0);
|
|
44
|
+
size_t index = INDEX_X;
|
|
45
|
+
auto it = std::sregex_iterator(value.begin(), value.end(), tokenRegex);
|
|
46
|
+
const auto end = std::sregex_iterator();
|
|
47
|
+
|
|
48
|
+
for (; it != end; ++it) {
|
|
49
|
+
if (index > INDEX_Z) {
|
|
50
|
+
return nullptr;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
auto token = toLower(it->str());
|
|
54
|
+
auto nextIndex = index + 1;
|
|
55
|
+
|
|
56
|
+
if (token == "left" || token == "right") {
|
|
57
|
+
if (index != INDEX_X) {
|
|
58
|
+
return nullptr;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
result[INDEX_X] = token == "left" ? folly::dynamic(0) : folly::dynamic("100%");
|
|
62
|
+
} else if (token == "top" || token == "bottom") {
|
|
63
|
+
if (index == INDEX_Z) {
|
|
64
|
+
return nullptr;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
result[INDEX_Y] = token == "top" ? folly::dynamic(0) : folly::dynamic("100%");
|
|
68
|
+
|
|
69
|
+
// [ center | left | right ] after a vertical keyword in the first place
|
|
70
|
+
if (index == INDEX_X) {
|
|
71
|
+
if (++it == end) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
auto horizontal = toLower(it->str());
|
|
76
|
+
|
|
77
|
+
if (horizontal == "left") {
|
|
78
|
+
result[INDEX_X] = 0;
|
|
79
|
+
} else if (horizontal == "right") {
|
|
80
|
+
result[INDEX_X] = "100%";
|
|
81
|
+
} else if (horizontal == "center") {
|
|
82
|
+
result[INDEX_X] = "50%";
|
|
83
|
+
} else {
|
|
84
|
+
return nullptr;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
nextIndex = INDEX_Z;
|
|
88
|
+
}
|
|
89
|
+
} else if (token == "center") {
|
|
90
|
+
if (index == INDEX_Z) {
|
|
91
|
+
return nullptr;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
result[index] = "50%";
|
|
95
|
+
} else if (token.back() == '%') {
|
|
96
|
+
if (index == INDEX_Z) {
|
|
97
|
+
return nullptr;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
result[index] = token;
|
|
101
|
+
} else {
|
|
102
|
+
// 0 or <digits>px
|
|
103
|
+
result[index] = std::strtod(token.c_str(), nullptr);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
index = nextIndex;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
} // namespace
|
|
113
|
+
#endif
|
|
114
|
+
|
|
11
115
|
bool isTransformOriginPropName(const std::string &propertyName) {
|
|
12
116
|
return propertyName == "transformOrigin";
|
|
13
117
|
}
|
|
@@ -25,6 +129,8 @@ parseTransformOriginString(const std::string &transformOriginString) {
|
|
|
25
129
|
}
|
|
26
130
|
|
|
27
131
|
return static_cast<folly::dynamic>(transformOrigin);
|
|
132
|
+
#elif defined(UNISTYLES_HAS_TRANSFORM_ORIGIN_FALLBACK)
|
|
133
|
+
return processTransformOriginString(transformOriginString);
|
|
28
134
|
#else
|
|
29
135
|
return std::nullopt;
|
|
30
136
|
#endif
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
using namespace margelo::nitro::unistyles::core;
|
|
5
5
|
using namespace facebook;
|
|
6
6
|
|
|
7
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet) {
|
|
7
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addStyleSheetFromValue(jsi::Runtime& rt, uint64_t generation, jsi::Object rawStyleSheet) {
|
|
8
8
|
if (rawStyleSheet.isFunction(rt)) {
|
|
9
|
-
return this->addFromFunction(rt, rawStyleSheet.asFunction(rt));
|
|
9
|
+
return this->addFromFunction(rt, generation, rawStyleSheet.asFunction(rt));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
return this->addFromObject(rt, std::move(rawStyleSheet));
|
|
12
|
+
return this->addFromObject(rt, generation, std::move(rawStyleSheet));
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt, jsi::Function styleSheetFn) {
|
|
15
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt, uint64_t generation, jsi::Function styleSheetFn) {
|
|
16
16
|
auto numberOfArgs = styleSheetFn.getProperty(rt, "length").getNumber();
|
|
17
17
|
|
|
18
18
|
helpers::assertThat(rt, numberOfArgs <= 2, "StyleSheet.create expected up to 2 arguments.");
|
|
@@ -23,20 +23,20 @@ std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromFunction(jsi::Runtime& rt
|
|
|
23
23
|
if (numberOfArgs == 0) {
|
|
24
24
|
auto staticStyleSheet = styleSheetFn.call(rt).asObject(rt);
|
|
25
25
|
|
|
26
|
-
return registry.addStyleSheet(rt, core::StyleSheetType::Static, std::move(staticStyleSheet));
|
|
26
|
+
return registry.addStyleSheet(rt, generation, core::StyleSheetType::Static, std::move(staticStyleSheet));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// stylesheet depends only on theme
|
|
30
30
|
if (numberOfArgs == 1) {
|
|
31
|
-
return registry.addStyleSheet(rt, core::StyleSheetType::Themable, std::move(styleSheetFn));
|
|
31
|
+
return registry.addStyleSheet(rt, generation, core::StyleSheetType::Themable, std::move(styleSheetFn));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// stylesheet depends on theme and mini runtime
|
|
35
|
-
return registry.addStyleSheet(rt, core::StyleSheetType::ThemableWithMiniRuntime, std::move(styleSheetFn));
|
|
35
|
+
return registry.addStyleSheet(rt, generation, core::StyleSheetType::ThemableWithMiniRuntime, std::move(styleSheetFn));
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt, jsi::Object rawStyleSheet) {
|
|
38
|
+
std::shared_ptr<StyleSheet> StyleSheetRegistry::addFromObject(jsi::Runtime& rt, uint64_t generation, jsi::Object rawStyleSheet) {
|
|
39
39
|
auto& registry = UnistylesRegistry::get();
|
|
40
40
|
|
|
41
|
-
return registry.addStyleSheet(rt, core::StyleSheetType::Static, std::move(rawStyleSheet));
|
|
41
|
+
return registry.addStyleSheet(rt, generation, core::StyleSheetType::Static, std::move(rawStyleSheet));
|
|
42
42
|
}
|
|
@@ -16,11 +16,11 @@ struct StyleSheetRegistry {
|
|
|
16
16
|
StyleSheetRegistry(const StyleSheetRegistry&) = delete;
|
|
17
17
|
StyleSheetRegistry(StyleSheetRegistry&&) = delete;
|
|
18
18
|
|
|
19
|
-
virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, jsi::Object rawStyleSheet);
|
|
19
|
+
virtual std::shared_ptr<StyleSheet> addStyleSheetFromValue(jsi::Runtime& rt, uint64_t generation, jsi::Object rawStyleSheet);
|
|
20
20
|
|
|
21
21
|
private:
|
|
22
|
-
virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt, jsi::Function styleSheetFn);
|
|
23
|
-
virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt, jsi::Object rawStyleSheet);
|
|
22
|
+
virtual std::shared_ptr<StyleSheet> addFromFunction(jsi::Runtime& rt, uint64_t generation, jsi::Function styleSheetFn);
|
|
23
|
+
virtual std::shared_ptr<StyleSheet> addFromObject(jsi::Runtime& rt, uint64_t generation, jsi::Object rawStyleSheet);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
}
|
|
@@ -157,7 +157,19 @@ inline static jsi::Value objectFromUnistyle(jsi::Runtime& rt, std::shared_ptr<Hy
|
|
|
157
157
|
[unistyleID = unistyle->unid, unistylesRuntime, variants, parsedArguments](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count
|
|
158
158
|
) {
|
|
159
159
|
auto& registry = UnistylesRegistry::get();
|
|
160
|
-
|
|
160
|
+
// ids repeat across runtimes, so a replaced runtime can't look up its unistyle anymore
|
|
161
|
+
auto unistyle = unistylesRuntime->ownsRegistry()
|
|
162
|
+
? registry.getUnistyleById(unistyleID)
|
|
163
|
+
: nullptr;
|
|
164
|
+
|
|
165
|
+
// the unistyle may have been unregistered while this call was in flight,
|
|
166
|
+
// eg. during a reload while the outgoing runtime still executes queued work
|
|
167
|
+
if (unistyle == nullptr) {
|
|
168
|
+
throw jsi::JSError(rt, R"(Unistyles: Style is no longer registered!
|
|
169
|
+
|
|
170
|
+
You likely accessed a style while the runtime was being torn down (eg. during a reload).)");
|
|
171
|
+
}
|
|
172
|
+
|
|
161
173
|
auto scopedTheme = registry.getScopedTheme();
|
|
162
174
|
parser::Parser parser(unistylesRuntime);
|
|
163
175
|
|