react-native-unistyles 3.3.0 → 3.4.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 (47) hide show
  1. package/README.md +3 -3
  2. package/cxx/core/UnistylesRegistry.cpp +135 -47
  3. package/cxx/core/UnistylesRegistry.h +23 -3
  4. package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -7
  5. package/cxx/parser/Parser.cpp +1 -2
  6. package/cxx/shadowTree/NativeProps.h +44 -0
  7. package/cxx/shadowTree/ShadowLeafUpdate.h +8 -0
  8. package/cxx/shadowTree/ShadowTrafficController.h +16 -37
  9. package/cxx/shadowTree/ShadowTreeManager.cpp +8 -148
  10. package/cxx/shadowTree/ShadowTreeManager.h +1 -5
  11. package/lib/commonjs/components/native/Animated.js +2 -0
  12. package/lib/commonjs/components/native/Animated.js.map +1 -1
  13. package/lib/commonjs/components/native/Pressable.js +2 -0
  14. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  15. package/lib/commonjs/components/native/Pressable.native.js +2 -0
  16. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  17. package/lib/commonjs/web/convert/object/boxShadow.js +2 -2
  18. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  19. package/lib/commonjs/web/index.js.map +1 -1
  20. package/lib/module/components/native/Animated.js +3 -0
  21. package/lib/module/components/native/Animated.js.map +1 -1
  22. package/lib/module/components/native/Pressable.js +2 -0
  23. package/lib/module/components/native/Pressable.js.map +1 -1
  24. package/lib/module/components/native/Pressable.native.js +2 -0
  25. package/lib/module/components/native/Pressable.native.js.map +1 -1
  26. package/lib/module/web/convert/object/boxShadow.js +2 -2
  27. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  28. package/lib/module/web/index.js.map +1 -1
  29. package/lib/typescript/src/components/native/Animated.d.ts +16 -36
  30. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  31. package/lib/typescript/src/components/native/Pressable.d.ts +4 -2
  32. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
  33. package/lib/typescript/src/components/native/Pressable.native.d.ts +5 -2
  34. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  35. package/lib/typescript/src/types/core.d.ts +7 -2
  36. package/lib/typescript/src/types/core.d.ts.map +1 -1
  37. package/lib/typescript/src/web/index.d.ts.map +1 -1
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +0 -2
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +0 -2
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +2 -0
  41. package/package.json +27 -26
  42. package/src/components/native/Animated.tsx +18 -1
  43. package/src/components/native/Pressable.native.tsx +10 -2
  44. package/src/components/native/Pressable.tsx +7 -1
  45. package/src/types/core.ts +7 -28
  46. package/src/web/convert/object/boxShadow.ts +2 -2
  47. package/src/web/index.ts +2 -1
@@ -10,7 +10,6 @@ package com.margelo.nitro.unistyles
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
- import dalvik.annotation.optimization.FastNative
14
13
 
15
14
 
16
15
  /**
@@ -59,7 +58,6 @@ class Func_void_UnistylesNativeMiniRuntime_cxx: Func_void_UnistylesNativeMiniRun
59
58
  override fun invoke(miniRuntime: UnistylesNativeMiniRuntime): Unit
60
59
  = invoke_cxx(miniRuntime)
61
60
 
62
- @FastNative
63
61
  private external fun invoke_cxx(miniRuntime: UnistylesNativeMiniRuntime): Unit
64
62
  }
65
63
 
@@ -10,7 +10,6 @@ package com.margelo.nitro.unistyles
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
- import dalvik.annotation.optimization.FastNative
14
13
 
15
14
 
16
15
  /**
@@ -59,7 +58,6 @@ class Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx:
59
58
  override fun invoke(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime): Unit
60
59
  = invoke_cxx(dependencies,miniRuntime)
61
60
 
62
- @FastNative
63
61
  private external fun invoke_cxx(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime): Unit
64
62
  }
65
63
 
@@ -10,6 +10,7 @@ package com.margelo.nitro.unistyles
10
10
  import androidx.annotation.Keep
11
11
  import com.facebook.jni.HybridData
12
12
  import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
13
14
  import com.margelo.nitro.core.HybridObject
14
15
 
15
16
  /**
@@ -120,6 +121,7 @@ abstract class HybridNativePlatformSpec: HybridObject() {
120
121
  @Keep
121
122
  protected open class CxxPart(javaPart: HybridNativePlatformSpec): HybridObject.CxxPart(javaPart) {
122
123
  // C++ JHybridNativePlatformSpec::CxxPart::initHybrid(...)
124
+ @FastNative
123
125
  external override fun initHybrid(): HybridData
124
126
  }
125
127
  override fun createCxxPart(): CxxPart {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "NODE_ENV=babel-test jest ./plugin ./src/__tests__",
@@ -128,39 +128,40 @@
128
128
  "registry": "https://registry.npmjs.org/"
129
129
  },
130
130
  "dependencies": {
131
- "@babel/types": "7.29.0"
131
+ "@babel/types": "7.29.8"
132
132
  },
133
133
  "devDependencies": {
134
- "@callstack/repack": "5.2.4",
135
- "@commitlint/config-conventional": "20.4.2",
136
- "@react-native/normalize-colors": "0.85.3",
137
- "@rspack/core": "1.7.6",
134
+ "@callstack/repack": "5.4.0",
135
+ "@commitlint/config-conventional": "21.2.3",
136
+ "@react-native/normalize-colors": "0.87.1",
137
+ "@rspack/core": "2.2.7",
138
138
  "@types/jest": "30.0.0",
139
- "@types/react": "19.2.14",
139
+ "@types/react": "19.2.18",
140
140
  "babel-plugin-tester": "12.0.0",
141
- "commitlint": "20.4.2",
142
- "concurrently": "9.2.1",
143
- "dpdm": "4.0.1",
144
- "esbuild": "0.27.3",
145
- "jest": "30.2.0",
146
- "@babel/plugin-syntax-jsx": "7.28.6",
147
- "@babel/runtime": "7.28.6",
148
- "@react-native/babel-preset": "0.85.3",
149
- "nitrogen": "0.36.1",
150
- "oxfmt": "0.35.0",
151
- "oxlint": "1.50.0",
141
+ "commitlint": "21.2.3",
142
+ "concurrently": "10.0.5",
143
+ "dpdm": "4.3.0",
144
+ "esbuild": "0.28.2",
145
+ "jest": "30.5.2",
146
+ "@babel/plugin-syntax-jsx": "7.29.7",
147
+ "@babel/runtime": "7.29.7",
148
+ "@react-native/babel-preset": "0.87.1",
149
+ "@react-native/jest-preset": "0.87.1",
150
+ "nitrogen": "0.37.1",
151
+ "oxfmt": "0.70.0",
152
+ "oxlint": "1.85.0",
152
153
  "react": "19.2.3",
153
- "react-native": "0.85.3",
154
- "react-native-builder-bob": "0.40.18",
155
- "react-native-nitro-modules": "0.36.1",
156
- "react-native-reanimated": "4.3.1",
157
- "react-native-web": "0.21.2",
158
- "typescript": "5.9.3"
154
+ "react-native": "0.87.1",
155
+ "react-native-builder-bob": "0.43.1",
156
+ "react-native-nitro-modules": "0.37.1",
157
+ "react-native-reanimated": "4.7.0",
158
+ "react-native-web": "0.21.3",
159
+ "typescript": "6.0.3"
159
160
  },
160
161
  "peerDependencies": {
161
162
  "@react-native/normalize-colors": "*",
162
163
  "react": "*",
163
- "react-native": ">=0.76.0",
164
+ "react-native": ">=0.81.0",
164
165
  "react-native-edge-to-edge": "*",
165
166
  "react-native-nitro-modules": "*",
166
167
  "react-native-reanimated": "*"
@@ -177,7 +178,7 @@
177
178
  "node": ">= 20.18.0"
178
179
  },
179
180
  "jest": {
180
- "preset": "react-native",
181
+ "preset": "@react-native/jest-preset",
181
182
  "modulePathIgnorePatterns": [
182
183
  "<rootDir>/lib/",
183
184
  "<rootDir>/cxx/tests"
@@ -7,7 +7,24 @@ import { SectionList } from './SectionList'
7
7
  import { Text } from './Text'
8
8
  import { View } from './View'
9
9
 
10
- export const Animated = {
10
+ type AnimatedComponent<T extends Parameters<typeof RNAnimated.createAnimatedComponent>[0]> = ReturnType<
11
+ typeof RNAnimated.createAnimatedComponent<T>
12
+ >
13
+
14
+ // explicit type keeps emitted declarations portable (RN 0.87+ Strict TypeScript API references private paths)
15
+ type UnistylesAnimated = Omit<
16
+ typeof RNAnimated,
17
+ 'View' | 'Text' | 'FlatList' | 'Image' | 'ScrollView' | 'SectionList'
18
+ > & {
19
+ View: AnimatedComponent<typeof View>
20
+ Text: AnimatedComponent<typeof Text>
21
+ FlatList: AnimatedComponent<typeof FlatList>
22
+ Image: AnimatedComponent<typeof Image>
23
+ ScrollView: AnimatedComponent<typeof ScrollView>
24
+ SectionList: AnimatedComponent<typeof SectionList>
25
+ }
26
+
27
+ export const Animated: UnistylesAnimated = {
11
28
  ...RNAnimated,
12
29
  View: RNAnimated.createAnimatedComponent(View),
13
30
  Text: RNAnimated.createAnimatedComponent(Text),
@@ -3,9 +3,14 @@ import type { PressableProps as Props, View } from 'react-native'
3
3
  import React, { forwardRef, useLayoutEffect, useRef } from 'react'
4
4
  import { Pressable as NativePressableReactNative } from 'react-native'
5
5
 
6
+ import type { Nullable } from '../../types'
7
+
6
8
  import { passForwardedRef } from '../../core'
7
9
  import { UnistylesShadowRegistry } from '../../specs'
8
10
 
11
+ // instance type of View for both legacy and Strict TypeScript API (RN 0.87+)
12
+ type ViewRef = React.ComponentRef<typeof View>
13
+
9
14
  type PressableProps = Props & {
10
15
  variants?: Record<string, string | boolean>
11
16
  }
@@ -24,8 +29,11 @@ const getStyles = (styleProps: Record<string, any> = {}) => {
24
29
  }
25
30
  }
26
31
 
27
- export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ...props }, forwardedRef) => {
28
- const storedRef = useRef<View | null>(null)
32
+ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<ViewRef>> = forwardRef<
33
+ ViewRef,
34
+ PressableProps
35
+ >(({ variants, style, ...props }, forwardedRef) => {
36
+ const storedRef = useRef<Nullable<ViewRef>>(null)
29
37
  const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
30
38
 
31
39
  useLayoutEffect(() => {
@@ -18,12 +18,18 @@ type WebPressableState = {
18
18
 
19
19
  type WebPressableStyle = ((state: WebPressableState) => UnistylesValues) | UnistylesValues
20
20
 
21
+ // instance type of View for both legacy and Strict TypeScript API (RN 0.87+)
22
+ type ViewRef = React.ComponentRef<typeof View>
23
+
21
24
  type PressableProps = Props & {
22
25
  variants?: Variants
23
26
  style?: WebPressableStyle
24
27
  }
25
28
 
26
- export const Pressable = forwardRef<View, PressableProps>(({ style, ...props }, forwardedRef) => {
29
+ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<ViewRef>> = forwardRef<
30
+ ViewRef,
31
+ PressableProps
32
+ >(({ style, ...props }, forwardedRef) => {
27
33
  const scopedTheme = UnistylesShadowRegistry.getScopedTheme()
28
34
  let storedRef: HTMLElement | null = null
29
35
  let classNames: ReturnType<typeof getClassName> | undefined = undefined
package/src/types/core.ts CHANGED
@@ -1,19 +1,4 @@
1
1
  import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
2
- import type {
3
- MatrixTransform,
4
- PerspectiveTransform,
5
- RotateTransform,
6
- RotateXTransform,
7
- RotateYTransform,
8
- RotateZTransform,
9
- ScaleTransform,
10
- ScaleXTransform,
11
- ScaleYTransform,
12
- SkewXTransform,
13
- SkewYTransform,
14
- TranslateXTransform,
15
- TranslateYTransform,
16
- } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
17
2
 
18
3
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
19
4
 
@@ -22,19 +7,13 @@ export type ShadowOffset = {
22
7
  height: number
23
8
  }
24
9
 
25
- export type TransformStyles = PerspectiveTransform &
26
- RotateTransform &
27
- RotateXTransform &
28
- RotateYTransform &
29
- RotateZTransform &
30
- ScaleTransform &
31
- ScaleXTransform &
32
- ScaleYTransform &
33
- TranslateXTransform &
34
- TranslateYTransform &
35
- SkewXTransform &
36
- SkewYTransform &
37
- MatrixTransform
10
+ type TransformEntry = Exclude<NonNullable<ViewStyle['transform']>, string>[number]
11
+ type TransformKeys<T> = T extends unknown ? keyof T : never
12
+ type TransformValue<T, K extends PropertyKey> = T extends unknown ? (K extends keyof T ? T[K] : never) : never
13
+
14
+ export type TransformStyles = {
15
+ [K in TransformKeys<TransformEntry>]: Exclude<TransformValue<TransformEntry, K>, void | undefined>
16
+ }
38
17
 
39
18
  export type ScreenSize = {
40
19
  width: number
@@ -17,7 +17,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
17
17
  const value = shadow[key as keyof BoxShadowValue]
18
18
 
19
19
  // Breakpoints
20
- if (typeof value === 'object') {
20
+ if (value !== null && typeof value === 'object') {
21
21
  Object.keys(value).forEach((breakpoint) => breakpoints.add(breakpoint))
22
22
  }
23
23
  })
@@ -41,7 +41,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
41
41
  const [key] = Object.keys(shadow)
42
42
  const value = shadow[key as keyof BoxShadowValue]
43
43
 
44
- if (typeof value === 'object' && keyInObject(value, breakpoint)) {
44
+ if (value !== null && typeof value === 'object' && keyInObject(value, breakpoint)) {
45
45
  return [key, value[breakpoint]]
46
46
  }
47
47
 
package/src/web/index.ts CHANGED
@@ -26,7 +26,8 @@ export const StyleSheet = {
26
26
  bottom: 0,
27
27
  },
28
28
  compose: (a: object, b: object) => RNStyleSheet.compose(a, b),
29
- flatten: (...styles: Array<object>) => RNStyleSheet.flatten(...styles),
29
+ flatten: (...styles: Array<object>) =>
30
+ (RNStyleSheet.flatten as unknown as (...styles: Array<object>) => object)(...styles),
30
31
  hairlineWidth: 1,
31
32
  } as unknown as typeof NativeStyleSheet
32
33