react-native-unistyles 3.0.0-nightly-20250505 → 3.0.0-nightly-20250508

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/src/mocks.ts CHANGED
@@ -11,16 +11,6 @@ type Registry = {
11
11
  breakpoints: UnistylesBreakpoints
12
12
  }
13
13
 
14
- jest.mock('react-native', () => ({
15
- TurboModuleRegistry: {
16
- get: () => ({})
17
- },
18
- StyleSheet: {},
19
- Platform: {
20
- OS: 'headless'
21
- }
22
- }))
23
-
24
14
  jest.mock('react-native-nitro-modules', () => ({
25
15
  NitroModules: {
26
16
  createHybridObject: () => ({
@@ -35,6 +25,7 @@ jest.mock('react-native-nitro-modules', () => ({
35
25
  }))
36
26
 
37
27
  jest.mock('react-native-unistyles', () => {
28
+ const React = require('react')
38
29
  const _REGISTRY: Registry = {
39
30
  themes: {},
40
31
  breakpoints: {}
@@ -70,8 +61,101 @@ jest.mock('react-native-unistyles', () => {
70
61
  height: 0
71
62
  }
72
63
  }
64
+ const unistylesRuntime = {
65
+ colorScheme: 'unspecified' as ColorScheme,
66
+ contentSizeCategory: 'Medium' as IOSContentSizeCategory,
67
+ orientation: 'portrait' as Orientation,
68
+ breakpoints: {},
69
+ dispose: () => { },
70
+ equals: () => false,
71
+ name: 'UnistylesRuntimeMock',
72
+ miniRuntime: miniRuntime,
73
+ statusBar: {
74
+ height: 0,
75
+ width: 0,
76
+ name: 'StatusBarMock',
77
+ equals: () => false,
78
+ setHidden: () => { },
79
+ setStyle: () => { }
80
+ },
81
+ navigationBar: {
82
+ height: 0,
83
+ width: 0,
84
+ name: 'NavigationBarMock',
85
+ equals: () => false,
86
+ setHidden: () => { },
87
+ dispose: () => { }
88
+ },
89
+ fontScale: 1,
90
+ hasAdaptiveThemes: false,
91
+ pixelRatio: 0,
92
+ rtl: false,
93
+ getTheme: () => {
94
+ return {} as UnistylesTheme
95
+ },
96
+ setTheme: () => {},
97
+ updateTheme: () => {},
98
+ setRootViewBackgroundColor: () => {},
99
+ _setRootViewBackgroundColor: () => {},
100
+ createHybridStatusBar: () => {
101
+ return {} as UnistylesStatusBar
102
+ },
103
+ createHybridNavigationBar: () => {
104
+ return {} as UnistylesNavigationBar
105
+ },
106
+ setAdaptiveThemes: () => {},
107
+ setImmersiveMode: () => {},
108
+ insets: {
109
+ top: 0,
110
+ left: 0,
111
+ right: 0,
112
+ bottom: 0,
113
+ ime: 0
114
+ },
115
+ screen: {
116
+ width: 0,
117
+ height: 0
118
+ },
119
+ breakpoint: undefined
120
+ } satisfies UnistylesRuntimePrivate
73
121
 
74
122
  return {
123
+ Hide: () => null,
124
+ Display: () => null,
125
+ ScopedTheme: () => null,
126
+ withUnistyles: <TComponent,>(Component: TComponent, mapper?: (theme: UnistylesTheme, runtime: typeof miniRuntime) => TComponent) => (props: any) =>
127
+ React.createElement(Component, {
128
+ ...mapper?.((Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme, miniRuntime),
129
+ ...props
130
+ }),
131
+ mq: {
132
+ only: {
133
+ width: () => ({
134
+ and: {
135
+ height: () => ({})
136
+ }
137
+ }),
138
+ height: () => ({
139
+ and: {
140
+ width: () => ({})
141
+ }
142
+ })
143
+ },
144
+ width: () => ({
145
+ and: {
146
+ height: () => ({})
147
+ }
148
+ }),
149
+ height: () => ({
150
+ and: {
151
+ width: () => ({})
152
+ }
153
+ })
154
+ },
155
+ useUnistyles: () => ({
156
+ theme: Object.values(_REGISTRY.themes).at(0) ?? {},
157
+ rt: unistylesRuntime
158
+ }),
75
159
  StyleSheet: {
76
160
  absoluteFillObject: {
77
161
  position: 'absolute',
@@ -95,10 +179,8 @@ jest.mock('react-native-unistyles', () => {
95
179
  },
96
180
  create: (styles: any) => {
97
181
  if (typeof styles === 'function') {
98
- const firstTheme = Object.values(_REGISTRY.themes).at(0) ?? {}
99
-
100
182
  return {
101
- ...styles(firstTheme, miniRuntime),
183
+ ...styles(Object.values(_REGISTRY.themes).at(0) ?? {}, miniRuntime),
102
184
  useVariants: () => {}
103
185
  }
104
186
  }
@@ -128,63 +210,7 @@ jest.mock('react-native-unistyles', () => {
128
210
  dispose: () => {},
129
211
  equals: () => false
130
212
  } satisfies UnistylesStyleSheet,
131
- UnistylesRuntime: {
132
- colorScheme: 'unspecified' as ColorScheme,
133
- contentSizeCategory: 'Medium' as IOSContentSizeCategory,
134
- orientation: 'portrait' as Orientation,
135
- breakpoints: {},
136
- dispose: () => { },
137
- equals: () => false,
138
- name: 'UnistylesRuntimeMock',
139
- miniRuntime: miniRuntime,
140
- statusBar: {
141
- height: 0,
142
- width: 0,
143
- name: 'StatusBarMock',
144
- equals: () => false,
145
- setHidden: () => { },
146
- setStyle: () => { }
147
- },
148
- navigationBar: {
149
- height: 0,
150
- width: 0,
151
- name: 'NavigationBarMock',
152
- equals: () => false,
153
- setHidden: () => { },
154
- dispose: () => { }
155
- },
156
- fontScale: 1,
157
- hasAdaptiveThemes: false,
158
- pixelRatio: 0,
159
- rtl: false,
160
- getTheme: () => {
161
- return {} as UnistylesTheme
162
- },
163
- setTheme: () => {},
164
- updateTheme: () => {},
165
- setRootViewBackgroundColor: () => {},
166
- _setRootViewBackgroundColor: () => {},
167
- createHybridStatusBar: () => {
168
- return {} as UnistylesStatusBar
169
- },
170
- createHybridNavigationBar: () => {
171
- return {} as UnistylesNavigationBar
172
- },
173
- setAdaptiveThemes: () => {},
174
- setImmersiveMode: () => {},
175
- insets: {
176
- top: 0,
177
- left: 0,
178
- right: 0,
179
- bottom: 0,
180
- ime: 0
181
- },
182
- screen: {
183
- width: 0,
184
- height: 0
185
- },
186
- breakpoint: undefined
187
- } satisfies UnistylesRuntimePrivate
213
+ UnistylesRuntime: unistylesRuntime
188
214
  }
189
215
  })
190
216
 
@@ -1,8 +1,8 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform/NativePlatform.nitro'
2
2
  import type { UnistylesTheme, UnistylesValues } from '../types'
3
3
  import { deepMergeObjects } from '../utils'
4
- import type { UnistylesServices } from './types'
5
- import { extractSecrets, extractUnistyleDependencies } from './utils'
4
+ import type { UniGeneratedStyle, UnistylesServices } from './types'
5
+ import { extractSecrets, extractUnistyleDependencies, isGeneratedUnistyle } from './utils'
6
6
  import { getVariants } from './variants'
7
7
 
8
8
  export class UnistylesShadowRegistry {
@@ -28,6 +28,13 @@ export class UnistylesShadowRegistry {
28
28
  }
29
29
 
30
30
  addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
31
+ const [firstStyle] = unistyles
32
+
33
+ // If it is already a generated style, return it
34
+ if (firstStyle && isGeneratedUnistyle(firstStyle)) {
35
+ return firstStyle as UniGeneratedStyle
36
+ }
37
+
31
38
  const getParsedStyles = () => {
32
39
  const allStyles = unistyles.map(unistyle => {
33
40
  const secrets = extractSecrets(unistyle)
package/src/web/types.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { UnistylesListener } from './listener'
2
- import type{ UnistylesRegistry } from './registry'
3
- import type{ UnistylesRuntime } from './runtime'
4
- import type{ UnistylesShadowRegistry } from './shadowRegistry'
5
- import type{ UnistylesState } from './state'
2
+ import type { UnistylesRegistry } from './registry'
3
+ import type { UnistylesRuntime } from './runtime'
4
+ import type { UnistylesShadowRegistry } from './shadowRegistry'
5
+ import type { UnistylesState } from './state'
6
6
 
7
7
  export type UnistylesServices = {
8
8
  runtime: UnistylesRuntime,
@@ -11,3 +11,8 @@ export type UnistylesServices = {
11
11
  state: UnistylesState,
12
12
  listener: UnistylesListener
13
13
  }
14
+
15
+ export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
16
+ export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
17
+
18
+ export type UniGeneratedStyle = Record<UniGeneratedKey, string>
@@ -5,6 +5,7 @@ import { ColorScheme, Orientation } from '../../specs/types'
5
5
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
6
6
  import { isUnistylesMq, parseMq } from '../../utils'
7
7
  import * as unistyles from '../services'
8
+ import { UNI_GENERATED_KEYS, type UniGeneratedKey, type UniGeneratedStyle } from '../types'
8
9
  import { keyInObject, reduceObject } from './common'
9
10
 
10
11
  export const schemeToTheme = (scheme: ColorScheme) => {
@@ -139,3 +140,7 @@ export const checkForAnimated = (value: any): boolean => {
139
140
 
140
141
  return false
141
142
  }
143
+
144
+ export const isGeneratedUnistyle = (value: Record<string, any>): value is UniGeneratedStyle => {
145
+ return Object.keys(value).every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
146
+ }