react-native-unistyles 3.0.0-alpha.42 → 3.0.0-alpha.44

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/lib/commonjs/components/Pressable.js +15 -5
  2. package/lib/commonjs/components/Pressable.js.map +1 -1
  3. package/lib/commonjs/components/Pressable.web.js +35 -17
  4. package/lib/commonjs/components/Pressable.web.js.map +1 -1
  5. package/lib/commonjs/web/create.js +6 -1
  6. package/lib/commonjs/web/create.js.map +1 -1
  7. package/lib/commonjs/web/shadowRegistry.js +49 -48
  8. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  9. package/lib/commonjs/web/{variants/getVariants.js → variants.js} +2 -2
  10. package/lib/commonjs/web/variants.js.map +1 -0
  11. package/lib/module/components/Pressable.js +15 -5
  12. package/lib/module/components/Pressable.js.map +1 -1
  13. package/lib/module/components/Pressable.web.js +35 -17
  14. package/lib/module/components/Pressable.web.js.map +1 -1
  15. package/lib/module/web/create.js +7 -2
  16. package/lib/module/web/create.js.map +1 -1
  17. package/lib/module/web/shadowRegistry.js +49 -48
  18. package/lib/module/web/shadowRegistry.js.map +1 -1
  19. package/lib/module/web/{variants/getVariants.js → variants.js} +2 -2
  20. package/lib/module/web/variants.js.map +1 -0
  21. package/lib/typescript/src/components/Pressable.d.ts +2 -1
  22. package/lib/typescript/src/components/Pressable.d.ts.map +1 -1
  23. package/lib/typescript/src/components/Pressable.web.d.ts +2 -1
  24. package/lib/typescript/src/components/Pressable.web.d.ts.map +1 -1
  25. package/lib/typescript/src/web/create.d.ts.map +1 -1
  26. package/lib/typescript/src/web/shadowRegistry.d.ts +1 -1
  27. package/lib/typescript/src/web/{variants/getVariants.d.ts → variants.d.ts} +2 -2
  28. package/lib/typescript/src/web/variants.d.ts.map +1 -0
  29. package/package.json +1 -1
  30. package/plugin/index.js +1 -1
  31. package/plugin/ref.js +1 -1
  32. package/plugin/style.js +282 -99
  33. package/plugin/stylesheet.js +1 -1
  34. package/src/components/Pressable.tsx +24 -7
  35. package/src/components/Pressable.web.tsx +54 -28
  36. package/src/web/create.ts +7 -2
  37. package/src/web/shadowRegistry.ts +47 -47
  38. package/src/web/{variants/getVariants.ts → variants.ts} +2 -2
  39. package/lib/commonjs/web/variants/getVariants.js.map +0 -1
  40. package/lib/commonjs/web/variants/index.js +0 -28
  41. package/lib/commonjs/web/variants/index.js.map +0 -1
  42. package/lib/commonjs/web/variants/useVariants.js +0 -59
  43. package/lib/commonjs/web/variants/useVariants.js.map +0 -1
  44. package/lib/module/web/variants/getVariants.js.map +0 -1
  45. package/lib/module/web/variants/index.js +0 -5
  46. package/lib/module/web/variants/index.js.map +0 -1
  47. package/lib/module/web/variants/useVariants.js +0 -54
  48. package/lib/module/web/variants/useVariants.js.map +0 -1
  49. package/lib/typescript/src/web/variants/getVariants.d.ts.map +0 -1
  50. package/lib/typescript/src/web/variants/index.d.ts +0 -3
  51. package/lib/typescript/src/web/variants/index.d.ts.map +0 -1
  52. package/lib/typescript/src/web/variants/useVariants.d.ts +0 -3
  53. package/lib/typescript/src/web/variants/useVariants.d.ts.map +0 -1
  54. package/src/web/variants/index.ts +0 -2
  55. package/src/web/variants/useVariants.ts +0 -65
package/plugin/style.js CHANGED
@@ -1,4 +1,4 @@
1
- function getStyleMetadata(t, node, dynamicFunction = null) {
1
+ function getStyleMetadata(t, node, dynamicFunction = null, state) {
2
2
  // {styles.container}
3
3
  if (t.isMemberExpression(node)) {
4
4
  const members = t.isMemberExpression(node.object)
@@ -10,19 +10,20 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
10
10
  members: members.filter(Boolean),
11
11
  inlineStyle: undefined,
12
12
  dynamicFunction,
13
- conditionalExpression: undefined
13
+ conditionalExpression: undefined,
14
+ logicalExpression: undefined
14
15
  }
15
16
  ]
16
17
  }
17
18
 
18
19
  // [styles.container]
19
20
  if (t.isArrayExpression(node)) {
20
- return node.elements.flatMap(element => getStyleMetadata(t, element))
21
+ return node.elements.flatMap(element => getStyleMetadata(t, element, null, state))
21
22
  }
22
23
 
23
24
  // [...styles.container]
24
25
  if (t.isSpreadElement(node)) {
25
- return getStyleMetadata(t, node.argument)
26
+ return getStyleMetadata(t, node.argument, null, state)
26
27
  }
27
28
 
28
29
  // {{ ...styles.container }}
@@ -36,18 +37,19 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
36
37
  members: [],
37
38
  inlineStyle: t.objectExpression([prop]),
38
39
  dynamicFunction: undefined,
39
- conditionalExpression: undefined
40
+ conditionalExpression: undefined,
41
+ logicalExpression: undefined
40
42
  }]
41
43
  }
42
44
 
43
- return getStyleMetadata(t, prop.argument)
45
+ return getStyleMetadata(t, prop.argument, null, state)
44
46
  })
45
47
  .filter(Boolean)
46
48
  }
47
49
 
48
50
  // {styles.container(arg1, arg2)}
49
51
  if (t.isCallExpression(node)) {
50
- return getStyleMetadata(t, node.callee, node)
52
+ return getStyleMetadata(t, node.callee, node, state)
51
53
  }
52
54
 
53
55
  if (t.isIdentifier(node)) {
@@ -55,7 +57,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
55
57
  members: [node.name],
56
58
  inlineStyle: undefined,
57
59
  dynamicFunction: undefined,
58
- conditionalExpression: undefined
60
+ conditionalExpression: undefined,
61
+ logicalExpression: undefined
59
62
  }]
60
63
  }
61
64
 
@@ -64,12 +67,33 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
64
67
  members: [],
65
68
  inlineStyle: undefined,
66
69
  dynamicFunction: undefined,
67
- conditionalExpression: node
70
+ conditionalExpression: node,
71
+ logicalExpression: undefined
68
72
  }]
69
73
  }
70
74
 
71
75
  if (t.isArrowFunctionExpression(node)) {
72
- return getStyleMetadata(t, node.body, node)
76
+ return getStyleMetadata(t, node.body, node, state)
77
+ }
78
+
79
+ // {condition && styles.container}
80
+ if (t.isLogicalExpression(node)) {
81
+ return [{
82
+ members: [],
83
+ inlineStyle: undefined,
84
+ dynamicFunction: undefined,
85
+ conditionalExpression: undefined,
86
+ logicalExpression: node
87
+ }]
88
+ }
89
+
90
+ // only when pressable is used
91
+ if (t.isBlockStatement(node) && state.file.shouldIncludePressable) {
92
+ const returnStatement = node.body.find(t.isReturnStatement)
93
+
94
+ return returnStatement
95
+ ? getStyleMetadata(t, returnStatement.argument, null, state)
96
+ : []
73
97
  }
74
98
 
75
99
  return []
@@ -117,73 +141,244 @@ function styleAttributeToArray(t, path) {
117
141
  styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
118
142
  }
119
143
 
120
- function handlePressable(t, path, styleAttr, metadata, state) {
121
- if (state.file.hasVariants) {
122
- const variants = t.jsxAttribute(
123
- t.jsxIdentifier('variants'),
124
- t.jsxExpressionContainer(t.identifier('__uni__variants'))
125
- )
144
+ function metadataToRawStyle(t, metadata, styleExpression) {
145
+ const expressions = []
126
146
 
127
- path.node.openingElement.attributes.push(variants)
128
- }
147
+ metadata.forEach(meta => {
148
+ if (meta.inlineStyle) {
149
+ return meta.inlineStyle.properties.forEach(prop => {
150
+ if (t.isObjectProperty(prop)) {
151
+ expressions.push(t.objectExpression([prop]))
152
+ }
153
+ })
154
+ }
129
155
 
130
- // add raw C++ style as prop to be bound
131
- const props = metadata
132
- .map(meta => meta.members)
133
- .filter(members => members.length > 0)
134
- .flatMap(members => t.memberExpression(...members.map(member => t.identifier(member))))
156
+ if (meta.members.length > 0) {
157
+ return expressions.push(t.memberExpression(...meta.members.map(member => t.identifier(member))))
158
+ }
159
+
160
+ if (meta.logicalExpression) {
161
+ const expression = t.cloneNode(meta.logicalExpression)
162
+
163
+ if (t.isIdentifier(expression.left)) {
164
+ if (t.isCallExpression(expression.right)) {
165
+ expression.right = expression.right.callee
166
+ }
167
+
168
+ expressions.push(expression)
169
+ }
170
+ }
171
+
172
+ if (meta.conditionalExpression) {
173
+ const expression = t.cloneNode(meta.conditionalExpression)
174
+
175
+ if (t.isCallExpression(expression.alternate)) {
176
+ expression.alternate = expression.alternate.callee
177
+ }
178
+
179
+ if (t.isCallExpression(expression.consequent)) {
180
+ expression.consequent = expression.consequent.callee
181
+ }
182
+
183
+ expressions.push(expression)
184
+ }
185
+ })
186
+
187
+ if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 1) {
188
+ return t.jsxAttribute(
189
+ t.jsxIdentifier('rawStyle'),
190
+ t.jsxExpressionContainer(
191
+ t.arrowFunctionExpression(styleExpression.params, t.arrayExpression([
192
+ ...expressions
193
+ ])
194
+ ))
195
+ )
196
+ }
135
197
 
136
- const rawStyles = t.jsxAttribute(
198
+ return t.jsxAttribute(
137
199
  t.jsxIdentifier('rawStyle'),
138
200
  t.jsxExpressionContainer(t.arrayExpression([
139
- ...props
201
+ ...expressions
140
202
  ]))
141
203
  )
204
+ }
142
205
 
143
- path.node.openingElement.attributes.push(rawStyles)
206
+ function wrapInGetBoundArgs(t, toWrap, extraArgs) {
207
+ const expression = t.callExpression(
208
+ t.identifier('getBoundArgs'),
209
+ [toWrap]
210
+ )
144
211
 
145
- const styleExpression = styleAttr.value.expression
146
- // {style.pressable}
147
- if (t.isMemberExpression(styleExpression)) {
148
- // user may care about state, but didn't pass any arguments
149
- const members = metadata.at(0).members
212
+ return t.callExpression(
213
+ t.memberExpression(expression, t.identifier('bind')),
214
+ [t.identifier('undefined'), ...extraArgs].filter(Boolean)
215
+ )
216
+ }
150
217
 
151
- if (members.length === 0) {
152
- return
153
- }
218
+ function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunction) {
219
+ let expression = undefined
220
+ let args = []
154
221
 
155
- const stylePath = members.slice(1).reduce(
222
+ const members = metadata.at(0).members
223
+
224
+ if (members) {
225
+ expression = members.slice(1).reduce(
156
226
  (acc, property) => t.memberExpression(acc, t.identifier(property)),
157
- t.identifier(members[0])
158
- )
159
- const expression = t.callExpression(
160
- t.identifier('getBoundArgs'),
161
- [stylePath]
162
- )
163
- const bindCall = t.callExpression(
164
- t.memberExpression(expression, t.identifier('bind')),
165
- [t.identifier('undefined'), t.identifier("state")]
227
+ t.identifier(members[0]))
228
+ }
229
+
230
+ if (t.isMemberExpression(metadata.at(0))) {
231
+ expression = metadata.at(0)
232
+ }
233
+
234
+ if (t.isCallExpression(metadata.at(0))) {
235
+ expression = metadata.at(0).callee
236
+ args = metadata.at(0).arguments
237
+ }
238
+
239
+ if (!expression) {
240
+ return
241
+ }
242
+
243
+ const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : args)
244
+
245
+ if (t.isCallExpression(metadata.at(0))) {
246
+ return bindCall
247
+ }
248
+
249
+ if (!wrapInArrowFunction) {
250
+ return t.conditionalExpression(
251
+ t.binaryExpression(
252
+ "===",
253
+ t.unaryExpression(
254
+ "typeof",
255
+ expression
256
+ ),
257
+ t.stringLiteral("function")
258
+ ),
259
+ bindCall,
260
+ expression
166
261
  )
262
+ }
167
263
 
168
- // state => typeof style.pressable === 'function'
169
- // ? getBoundArgs(style.pressable).bind(undefined, state)
170
- // : style.pressable
171
- styleAttr.value.expression = t.arrowFunctionExpression(
172
- [t.identifier("state")],
173
- t.conditionalExpression(
174
- t.binaryExpression(
175
- "===",
176
- t.unaryExpression(
177
- "typeof",
178
- stylePath
179
- ),
180
- t.stringLiteral("function")
264
+ // state => typeof style.pressable === 'function'
265
+ // ? getBoundArgs(style.pressable).bind(undefined, state)
266
+ // : style.pressable
267
+ return t.arrowFunctionExpression(
268
+ [t.identifier("state")],
269
+ t.conditionalExpression(
270
+ t.binaryExpression(
271
+ "===",
272
+ t.unaryExpression(
273
+ "typeof",
274
+ expression
181
275
  ),
182
- bindCall,
183
- stylePath
184
- )
276
+ t.stringLiteral("function")
277
+ ),
278
+ bindCall,
279
+ expression
280
+ )
281
+ )
282
+ }
283
+
284
+ function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index) {
285
+ if (t.isObjectExpression(wrapper)) {
286
+ return
287
+ }
288
+
289
+ if (t.isMemberExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
290
+ parentWrapper.elements[index] = handlePressableFromMemberExpression(t, path, [metadata[index]])
291
+
292
+ return
293
+ }
294
+
295
+ if (t.isMemberExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
296
+ parentWrapper = handlePressableFromMemberExpression(t, path, metadata)
297
+
298
+ return
299
+ }
300
+
301
+ if (t.isLogicalExpression(wrapper)) {
302
+ if (t.isIdentifier(wrapper.left) && t.isMemberExpression(wrapper.right)) {
303
+ parentWrapper.elements[index].right = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].right])
304
+
305
+ return
306
+ }
307
+
308
+ return
309
+ }
310
+
311
+ if (t.isConditionalExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
312
+ if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
313
+ parentWrapper.elements[index].alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].alternate])
314
+ }
315
+
316
+ if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
317
+ parentWrapper.elements[index].consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].consequent])
318
+ }
319
+
320
+ return
321
+ }
322
+
323
+ if (t.isConditionalExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
324
+ if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
325
+ parentWrapper.alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.alternate])
326
+ }
327
+
328
+ if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
329
+ parentWrapper.consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.consequent])
330
+ }
331
+
332
+ return
333
+ }
334
+
335
+ const pressableArgs = t.isCallExpression(wrapper)
336
+ ? wrapper.arguments
337
+ : wrapper.argument.arguments
338
+ const callee = t.isCallExpression(wrapper)
339
+ ? wrapper.callee
340
+ : wrapper.argument.callee
341
+
342
+ const getBoundArgsCall = t.callExpression(
343
+ t.identifier('getBoundArgs'),
344
+ [callee]
345
+ )
346
+ const bindCall = t.callExpression(
347
+ t.memberExpression(getBoundArgsCall, t.identifier('bind')),
348
+ [t.identifier('undefined'), ...pressableArgs]
349
+ )
350
+
351
+ if (t.isCallExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
352
+ parentWrapper.elements[index] = bindCall
353
+
354
+ return
355
+ }
356
+
357
+ if (t.isCallExpression(wrapper)) {
358
+ styleExpression.body = bindCall
359
+ }
360
+ }
361
+
362
+ function handlePressable(t, path, styleAttr, metadata, state) {
363
+ // add variants
364
+ if (state.file.hasVariants) {
365
+ const variants = t.jsxAttribute(
366
+ t.jsxIdentifier('variants'),
367
+ t.jsxExpressionContainer(t.identifier('__uni__variants'))
185
368
  )
186
369
 
370
+ path.node.openingElement.attributes.push(variants)
371
+ }
372
+
373
+ // add raw C++ style as prop to be bound
374
+ path.node.openingElement.attributes.push(metadataToRawStyle(t, metadata, styleAttr.value.expression))
375
+
376
+ const styleExpression = styleAttr.value.expression
377
+
378
+ // {style.pressable}
379
+ if (t.isMemberExpression(styleExpression)) {
380
+ styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
381
+
187
382
  return
188
383
  }
189
384
 
@@ -212,20 +407,30 @@ function handlePressable(t, path, styleAttr, metadata, state) {
212
407
 
213
408
  // {() => style.pressable(1, 2)}
214
409
  if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
215
- const wrapper = t.isBlockStatement(styleExpression.body)
410
+ let parentWrapper = t.isBlockStatement(styleExpression.body)
216
411
  ? styleExpression.body.body.find(node => t.isReturnStatement(node))
217
412
  : styleExpression.body
218
413
 
219
- if (t.isMemberExpression(wrapper)) {
414
+ if (t.isMemberExpression(parentWrapper)) {
220
415
  return
221
416
  }
222
417
 
223
- const pressableArgs = t.isCallExpression(wrapper)
224
- ? wrapper.arguments
225
- : wrapper.argument.arguments
226
- const callee = t.isCallExpression(wrapper)
227
- ? wrapper.callee
228
- : wrapper.argument.callee
418
+ if (t.isArrayExpression(parentWrapper)) {
419
+ return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
420
+ }
421
+
422
+ if (t.isReturnStatement(parentWrapper)) {
423
+ parentWrapper = parentWrapper.argument
424
+
425
+ return handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
426
+ }
427
+
428
+ const pressableArgs = t.isCallExpression(parentWrapper)
429
+ ? parentWrapper.arguments
430
+ : parentWrapper.argument.arguments
431
+ const callee = t.isCallExpression(parentWrapper)
432
+ ? parentWrapper.callee
433
+ : parentWrapper.argument.callee
229
434
  const getBoundArgsCall = t.callExpression(
230
435
  t.identifier('getBoundArgs'),
231
436
  [callee]
@@ -235,14 +440,14 @@ function handlePressable(t, path, styleAttr, metadata, state) {
235
440
  [t.identifier('undefined'), ...pressableArgs]
236
441
  )
237
442
 
238
- if (t.isCallExpression(wrapper)) {
443
+ if (t.isCallExpression(parentWrapper)) {
239
444
  styleExpression.body = bindCall
240
445
 
241
446
  return
242
447
  }
243
448
 
244
- if (wrapper) {
245
- wrapper.argument = bindCall
449
+ if (parentWrapper) {
450
+ parentWrapper.argument = bindCall
246
451
  }
247
452
 
248
453
  return
@@ -252,41 +457,19 @@ function handlePressable(t, path, styleAttr, metadata, state) {
252
457
  if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
253
458
  // user used state with custom args we need to getBoundArgs
254
459
  // detect between arrow function with body and arrow function
255
- const wrapper = t.isBlockStatement(styleExpression.body)
460
+ let parentWrapper = t.isBlockStatement(styleExpression.body)
256
461
  ? styleExpression.body.body.find(node => t.isReturnStatement(node))
257
462
  : styleExpression.body
258
463
 
259
- if (t.isMemberExpression(wrapper)) {
260
- return
464
+ if (t.isArrayExpression(parentWrapper)) {
465
+ return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
261
466
  }
262
467
 
263
- const pressableArgs = t.isCallExpression(wrapper)
264
- ? wrapper.arguments
265
- : wrapper.argument.arguments
266
- const callee = t.isCallExpression(wrapper)
267
- ? wrapper.callee
268
- : wrapper.argument.callee
269
-
270
- const getBoundArgsCall = t.callExpression(
271
- t.identifier('getBoundArgs'),
272
- [callee]
273
- )
274
- const bindCall = t.callExpression(
275
- t.memberExpression(getBoundArgsCall, t.identifier('bind')),
276
- [t.identifier('undefined'), ...pressableArgs]
277
- )
278
-
279
- // arrow function
280
- if (t.isCallExpression(wrapper)) {
281
- styleExpression.body = bindCall
282
-
283
- return
468
+ if (t.isReturnStatement(parentWrapper)) {
469
+ parentWrapper = parentWrapper.argument
284
470
  }
285
471
 
286
- // arrow function with body
287
- if (wrapper) {
288
- wrapper.argument = bindCall
289
- }
472
+ handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
290
473
  }
291
474
  }
292
475
 
@@ -44,7 +44,7 @@ function isUnistylesStyleSheet(t, path, state) {
44
44
 
45
45
  function addStyleSheetTag(t, path, state) {
46
46
  const callee = path.get('callee')
47
- const uniqueId = stringToUniqueId(state.filename) + ++state.file.tagNumber
47
+ const uniqueId = stringToUniqueId(state.filename.replace(state.cwd, '')) + ++state.file.tagNumber
48
48
 
49
49
  callee.container.arguments.push(t.numericLiteral(uniqueId))
50
50
  }
@@ -1,11 +1,11 @@
1
1
  import React, { forwardRef, useRef } from 'react'
2
- import { Pressable as NativePressableReactNative } from 'react-native'
2
+ import { Pressable as NativePressableReactNative, type PressableStateCallbackType } from 'react-native'
3
3
  import type { PressableProps as Props, View } from 'react-native'
4
4
  import { UnistylesShadowRegistry } from '../specs'
5
5
  import { getId } from '../core'
6
6
 
7
7
  type PressableProps = Props & {
8
- rawStyle?: Array<any>
8
+ rawStyle?: Array<any> | ((event: PressableStateCallbackType) => Array<any>)
9
9
  variants?: Record<string, string | boolean>
10
10
  }
11
11
 
@@ -23,7 +23,11 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
23
23
  const fnArgs = typeof styleResult === 'function'
24
24
  // @ts-expect-error - this is hidden from TS
25
25
  ? styleResult.getBoundArgs()
26
- : []
26
+ : Array.isArray(styleResult)
27
+ ? styleResult
28
+ // @ts-expect-error - this is hidden from TS
29
+ .map(style => typeof style === 'function' ? style.getBoundArgs() : [])
30
+ : []
27
31
 
28
32
  if (typeof passedRef === 'object' && passedRef !== null) {
29
33
  passedRef.current = ref
@@ -32,9 +36,12 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
32
36
  const returnFn = typeof passedRef === 'function'
33
37
  ? passedRef(ref)
34
38
  : () => {}
39
+ const unistyles = typeof rawStyle === 'function'
40
+ ? rawStyle({ pressed: false })
41
+ : (rawStyle ?? [])
35
42
 
36
43
  // @ts-expect-error - this is hidden from TS
37
- UnistylesShadowRegistry.add(ref, rawStyle ?? [], variants, [fnArgs])
44
+ UnistylesShadowRegistry.add(ref, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs])
38
45
 
39
46
  return () => {
40
47
  // @ts-expect-error - this is hidden from TS
@@ -52,20 +59,30 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
52
59
  const fnArgs = typeof styleResult === 'function'
53
60
  // @ts-expect-error - this is hidden from TS
54
61
  ? styleResult.getBoundArgs()
55
- : []
62
+ : Array.isArray(styleResult)
63
+ ? styleResult
64
+ // @ts-expect-error - this is hidden from TS
65
+ .map(style => typeof style === 'function' ? style.getBoundArgs() : [])
66
+ : []
56
67
  const pressId = getId()
68
+ const unistyles = typeof rawStyle === 'function'
69
+ ? rawStyle(state)
70
+ : (rawStyle ?? [])
57
71
 
58
72
  if (storedRef.current) {
59
73
  // @ts-expect-error - this is hidden from TS
60
74
  UnistylesShadowRegistry.remove(storedRef.current)
61
75
  // @ts-expect-error - this is hidden from TS
62
- UnistylesShadowRegistry.add(storedRef.current, rawStyle ?? [], variants, [fnArgs], pressId)
76
+ UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, Array.isArray(styleResult) ? fnArgs : [fnArgs], pressId)
63
77
  }
64
78
 
65
79
  return typeof styleResult === 'function'
66
80
  // @ts-expect-error - this is hidden from TS
67
81
  ? styleResult(pressId)
68
- : styleResult
82
+ : Array.isArray(styleResult)
83
+ // @ts-expect-error - this is hidden from TS
84
+ ? styleResult.map(style => typeof style === 'function' ? style(pressId) : style)
85
+ : styleResult
69
86
  }}
70
87
  />
71
88
  )