react-native-unistyles 3.1.0 → 3.2.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.
Files changed (57) hide show
  1. package/README.md +180 -0
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -5
  3. package/android/src/main/cxx/NativeUnistylesModule.h +1 -7
  4. package/android/src/main/java/com/unistyles/Equatable.kt +5 -1
  5. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +6 -1
  6. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +21 -3
  7. package/cxx/core/UnistyleWrapper.h +2 -2
  8. package/cxx/core/UnistylesRegistry.cpp +57 -48
  9. package/cxx/core/UnistylesRegistry.h +16 -14
  10. package/cxx/core/UnistylesState.cpp +22 -20
  11. package/cxx/core/UnistylesState.h +5 -6
  12. package/cxx/hybridObjects/HybridShadowRegistry.cpp +14 -3
  13. package/cxx/hybridObjects/HybridShadowRegistry.h +5 -0
  14. package/cxx/hybridObjects/HybridStyleSheet.cpp +71 -45
  15. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +22 -32
  16. package/cxx/hybridObjects/HybridUnistylesRuntime.h +3 -4
  17. package/cxx/parser/Parser.cpp +14 -14
  18. package/ios/UnistylesModuleOnLoad.mm +3 -10
  19. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +4 -1
  20. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  21. package/lib/commonjs/specs/ShadowRegistry/index.js +20 -1
  22. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  23. package/lib/commonjs/web/convert/style.js +6 -6
  24. package/lib/commonjs/web/convert/style.js.map +1 -1
  25. package/lib/commonjs/web/listener.js +6 -0
  26. package/lib/commonjs/web/listener.js.map +1 -1
  27. package/lib/commonjs/web/utils/createUnistylesRef.js +1 -1
  28. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  29. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +4 -1
  30. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  31. package/lib/module/specs/ShadowRegistry/index.js +20 -1
  32. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  33. package/lib/module/web/convert/style.js +6 -6
  34. package/lib/module/web/convert/style.js.map +1 -1
  35. package/lib/module/web/listener.js +6 -0
  36. package/lib/module/web/listener.js.map +1 -1
  37. package/lib/module/web/utils/createUnistylesRef.js +1 -1
  38. package/lib/module/web/utils/createUnistylesRef.js.map +1 -1
  39. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  40. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -1
  41. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  42. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  43. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  44. package/nitrogen/generated/android/c++/JDimensions.hpp +1 -1
  45. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  46. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  47. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +2 -2
  48. package/nitrogen/generated/android/c++/JInsets.hpp +1 -1
  49. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  50. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +1 -1
  51. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +1 -1
  52. package/package.json +3 -3
  53. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +4 -1
  54. package/src/specs/ShadowRegistry/index.ts +36 -2
  55. package/src/web/convert/style.ts +6 -6
  56. package/src/web/listener.ts +6 -0
  57. package/src/web/utils/createUnistylesRef.ts +1 -1
@@ -19,7 +19,7 @@ namespace margelo::nitro::unistyles {
19
19
  */
20
20
  struct JColorScheme final: public jni::JavaClass<JColorScheme> {
21
21
  public:
22
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/ColorScheme;";
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/ColorScheme;";
23
23
 
24
24
  public:
25
25
  /**
@@ -21,7 +21,7 @@ namespace margelo::nitro::unistyles {
21
21
  */
22
22
  struct JDimensions final: public jni::JavaClass<JDimensions> {
23
23
  public:
24
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Dimensions;";
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Dimensions;";
25
25
 
26
26
  public:
27
27
  /**
@@ -32,7 +32,7 @@ namespace margelo::nitro::unistyles {
32
32
  */
33
33
  struct JFunc_void_UnistylesNativeMiniRuntime: public jni::JavaClass<JFunc_void_UnistylesNativeMiniRuntime> {
34
34
  public:
35
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime;";
35
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime;";
36
36
 
37
37
  public:
38
38
  /**
@@ -68,7 +68,7 @@ namespace margelo::nitro::unistyles {
68
68
  }
69
69
 
70
70
  public:
71
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime_cxx;";
71
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime_cxx;";
72
72
  static void registerNatives() {
73
73
  registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_UnistylesNativeMiniRuntime_cxx::invoke_cxx)});
74
74
  }
@@ -35,7 +35,7 @@ namespace margelo::nitro::unistyles {
35
35
  */
36
36
  struct JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime: public jni::JavaClass<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime> {
37
37
  public:
38
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime;";
38
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime;";
39
39
 
40
40
  public:
41
41
  /**
@@ -89,7 +89,7 @@ namespace margelo::nitro::unistyles {
89
89
  }
90
90
 
91
91
  public:
92
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx;";
92
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx;";
93
93
  static void registerNatives() {
94
94
  registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx::invoke_cxx)});
95
95
  }
@@ -21,11 +21,11 @@ namespace margelo::nitro::unistyles {
21
21
  class JHybridNativePlatformSpec: public virtual HybridNativePlatformSpec, public virtual JHybridObject {
22
22
  public:
23
23
  struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
24
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/HybridNativePlatformSpec;";
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/HybridNativePlatformSpec;";
25
25
  std::shared_ptr<JHybridNativePlatformSpec> getJHybridNativePlatformSpec();
26
26
  };
27
27
  struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
28
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/HybridNativePlatformSpec$CxxPart;";
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/HybridNativePlatformSpec$CxxPart;";
29
29
  static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
30
30
  static void registerNatives();
31
31
  using HybridBase::HybridBase;
@@ -21,7 +21,7 @@ namespace margelo::nitro::unistyles {
21
21
  */
22
22
  struct JInsets final: public jni::JavaClass<JInsets> {
23
23
  public:
24
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Insets;";
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Insets;";
25
25
 
26
26
  public:
27
27
  /**
@@ -19,7 +19,7 @@ namespace margelo::nitro::unistyles {
19
19
  */
20
20
  struct JOrientation final: public jni::JavaClass<JOrientation> {
21
21
  public:
22
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Orientation;";
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Orientation;";
23
23
 
24
24
  public:
25
25
  /**
@@ -19,7 +19,7 @@ namespace margelo::nitro::unistyles {
19
19
  */
20
20
  struct JUnistyleDependency final: public jni::JavaClass<JUnistyleDependency> {
21
21
  public:
22
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/UnistyleDependency;";
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/UnistyleDependency;";
23
23
 
24
24
  public:
25
25
  /**
@@ -27,7 +27,7 @@ namespace margelo::nitro::unistyles {
27
27
  */
28
28
  struct JUnistylesNativeMiniRuntime final: public jni::JavaClass<JUnistylesNativeMiniRuntime> {
29
29
  public:
30
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/UnistylesNativeMiniRuntime;";
30
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/unistyles/UnistylesNativeMiniRuntime;";
31
31
 
32
32
  public:
33
33
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin ./src/__tests__",
@@ -145,13 +145,13 @@
145
145
  "@babel/plugin-syntax-jsx": "7.28.6",
146
146
  "@babel/runtime": "7.28.6",
147
147
  "@react-native/babel-preset": "0.83.2",
148
- "nitrogen": "0.35.0",
148
+ "nitrogen": "0.35.2",
149
149
  "oxfmt": "0.35.0",
150
150
  "oxlint": "1.50.0",
151
151
  "react": "19.2.0",
152
152
  "react-native": "0.83.2",
153
153
  "react-native-builder-bob": "0.40.18",
154
- "react-native-nitro-modules": "0.35.0",
154
+ "react-native-nitro-modules": "0.35.2",
155
155
  "react-native-reanimated": "4.2.2",
156
156
  "react-native-web": "0.21.2",
157
157
  "typescript": "5.9.3"
@@ -62,7 +62,10 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
62
62
  }
63
63
 
64
64
  useEffect(() => {
65
- return () => disposeRef.current?.()
65
+ return () => {
66
+ disposeRef.current?.()
67
+ syncedDependenciesSizeRef.current = -1
68
+ }
66
69
  }, [disposeRef])
67
70
 
68
71
  const maybeNewScopedTheme = UnistylesShadowRegistry.getScopedTheme() as UnistylesTheme
@@ -10,6 +10,7 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
10
10
  // JSI
11
11
  link(node: ShadowNode, styles?: Array<Unistyle>): void
12
12
  unlink(node: ShadowNode): void
13
+ suspend(node: ShadowNode): void
13
14
  flush(): void
14
15
  setScopedTheme(themeName?: string): void
15
16
  getScopedTheme(): string | undefined
@@ -17,6 +18,33 @@ interface ShadowRegistry extends UnistylesShadowRegistrySpec {
17
18
 
18
19
  const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
19
20
 
21
+ const SUSPENSE_TAG = 13
22
+
23
+ const isInsideSuspendedBoundary = (fiber: any): boolean => {
24
+ let current = fiber?.return
25
+
26
+ while (current) {
27
+ if (current.tag === SUSPENSE_TAG && current.memoizedState !== null) {
28
+ return true
29
+ }
30
+
31
+ current = current.return
32
+ }
33
+
34
+ return false
35
+ }
36
+
37
+ const findFiberForHandle = (handle: ViewHandle) => {
38
+ return (
39
+ handle?.__internalInstanceHandle ??
40
+ handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle ??
41
+ handle?.getNativeScrollRef?.()?.__internalInstanceHandle ??
42
+ handle?._viewRef?.__internalInstanceHandle ??
43
+ handle?.viewRef?.current?.__internalInstanceHandle ??
44
+ handle?._nativeRef?.__internalInstanceHandle
45
+ )
46
+ }
47
+
20
48
  const findShadowNodeForHandle = (handle: ViewHandle) => {
21
49
  const node =
22
50
  handle?.__internalInstanceHandle?.stateNode?.node ??
@@ -71,10 +99,16 @@ HybridShadowRegistry.remove = (handle) => {
71
99
  const maybeNode = findShadowNodeForHandle(handle)
72
100
 
73
101
  if (maybeNode) {
74
- HybridShadowRegistry.unlink(maybeNode)
102
+ const fiber = findFiberForHandle(handle)
103
+
104
+ if (fiber && isInsideSuspendedBoundary(fiber)) {
105
+ HybridShadowRegistry.suspend(maybeNode)
106
+ } else {
107
+ HybridShadowRegistry.unlink(maybeNode)
108
+ }
75
109
  }
76
110
  }
77
111
 
78
- type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink'
112
+ type PrivateMethods = 'add' | 'remove' | 'link' | 'unlink' | 'suspend'
79
113
 
80
114
  export const UnistylesShadowRegistry = HybridShadowRegistry as Omit<ShadowRegistry, PrivateMethods>
@@ -98,22 +98,22 @@ const convertMap = {
98
98
  borderInlineStartWidth: value,
99
99
  }),
100
100
  end: (value: number) => ({
101
- right: value,
101
+ insetInlineEnd: value,
102
102
  }),
103
103
  start: (value: number) => ({
104
- left: value,
104
+ insetInlineStart: value,
105
105
  }),
106
106
  marginEnd: (value: number) => ({
107
- marginRight: value,
107
+ marginInlineEnd: value,
108
108
  }),
109
109
  marginStart: (value: number) => ({
110
- marginLeft: value,
110
+ marginInlineStart: value,
111
111
  }),
112
112
  paddingEnd: (value: number) => ({
113
- paddingRight: value,
113
+ paddingInlineEnd: value,
114
114
  }),
115
115
  paddingStart: (value: number) => ({
116
- paddingLeft: value,
116
+ paddingInlineStart: value,
117
117
  }),
118
118
  transformMatrix: (value: Array<number>) => ({
119
119
  transform: `matrix(${value.join(', ')})`,
@@ -92,6 +92,12 @@ export class UnistylesListener {
92
92
 
93
93
  window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
94
94
  window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
95
+ new MutationObserver(() => {
96
+ this.emitChange(UnistyleDependency.Rtl)
97
+ }).observe(document.documentElement, {
98
+ attributes: true,
99
+ attributeFilter: ['dir'],
100
+ })
95
101
  }
96
102
 
97
103
  addListeners = (dependencies: Array<UnistyleDependency>, listener: Listener) => {
@@ -20,7 +20,7 @@ export const createUnistylesRef = <T>(styles?: Styles, forwardedRef?: React.Forw
20
20
  ? undefined
21
21
  : (ref: Nullable<T>) => {
22
22
  if (!ref) {
23
- unistyles.services.shadowRegistry.remove(storedRef, classNames?.hash)
23
+ unistyles.services.shadowRegistry.remove(storedRef.current, classNames?.hash)
24
24
  }
25
25
 
26
26
  storedRef.current = ref