@tamagui/web 1.43.15 → 1.43.17

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 (43) hide show
  1. package/dist/cjs/createComponent.js +1 -1
  2. package/dist/cjs/createComponent.js.map +1 -1
  3. package/dist/cjs/helpers/createPropMapper.js +38 -86
  4. package/dist/cjs/helpers/createPropMapper.js.map +1 -1
  5. package/dist/cjs/helpers/expandStyles.js +7 -4
  6. package/dist/cjs/helpers/expandStyles.js.map +1 -1
  7. package/dist/cjs/helpers/getSplitStyles.js +21 -33
  8. package/dist/cjs/helpers/getSplitStyles.js.map +1 -1
  9. package/dist/cjs/helpers/getVariantExtras.js +11 -13
  10. package/dist/cjs/helpers/getVariantExtras.js.map +1 -1
  11. package/dist/cjs/hooks/useTheme.js +3 -3
  12. package/dist/cjs/hooks/useTheme.js.map +1 -1
  13. package/dist/esm/createComponent.js +1 -1
  14. package/dist/esm/createComponent.js.map +1 -1
  15. package/dist/esm/helpers/createPropMapper.js +39 -87
  16. package/dist/esm/helpers/createPropMapper.js.map +1 -1
  17. package/dist/esm/helpers/expandStyles.js +6 -3
  18. package/dist/esm/helpers/expandStyles.js.map +1 -1
  19. package/dist/esm/helpers/getSplitStyles.js +21 -33
  20. package/dist/esm/helpers/getSplitStyles.js.map +1 -1
  21. package/dist/esm/helpers/getVariantExtras.js +11 -13
  22. package/dist/esm/helpers/getVariantExtras.js.map +1 -1
  23. package/dist/esm/hooks/useTheme.js +3 -3
  24. package/dist/esm/hooks/useTheme.js.map +1 -1
  25. package/package.json +9 -9
  26. package/src/createComponent.tsx +7 -6
  27. package/src/helpers/createPropMapper.ts +57 -125
  28. package/src/helpers/expandStyles.ts +8 -2
  29. package/src/helpers/getSplitStyles.tsx +20 -48
  30. package/src/helpers/getVariantExtras.tsx +16 -22
  31. package/src/hooks/useTheme.tsx +2 -2
  32. package/src/types.tsx +23 -16
  33. package/types/createComponent.d.ts.map +1 -1
  34. package/types/helpers/createPropMapper.d.ts.map +1 -1
  35. package/types/helpers/expandStyles.d.ts +1 -1
  36. package/types/helpers/expandStyles.d.ts.map +1 -1
  37. package/types/helpers/getSplitStyles.d.ts +3 -17
  38. package/types/helpers/getSplitStyles.d.ts.map +1 -1
  39. package/types/helpers/getVariantExtras.d.ts +2 -2
  40. package/types/helpers/getVariantExtras.d.ts.map +1 -1
  41. package/types/styled.d.ts +1 -1
  42. package/types/types.d.ts +20 -3
  43. package/types/types.d.ts.map +1 -1
@@ -1,19 +1,18 @@
1
1
  import { isAndroid, isWeb } from '@tamagui/constants'
2
2
 
3
- import { getConfig } from '../config'
4
3
  import { isDevTools } from '../constants/isDevTools'
5
4
  import { Variable, getVariableValue, isVariable } from '../createVariable'
6
5
  import type {
7
6
  DebugProp,
7
+ GetStyleState,
8
8
  PropMapper,
9
9
  StaticConfigParsed,
10
10
  StyleResolver,
11
11
  TamaguiInternalConfig,
12
12
  VariantSpreadFunction,
13
13
  } from '../types'
14
- import type { LanguageContextType } from '../views/FontLanguage.types'
15
14
  import { expandStyle } from './expandStyle'
16
- import { expandStyles } from './expandStyles'
15
+ import { expandStylesAndRemoveNullishValues } from './expandStyles'
17
16
  import { getFontsForLanguage, getVariantExtras } from './getVariantExtras'
18
17
  import { isObj } from './isObj'
19
18
  import { mergeProps } from './mergeProps'
@@ -27,70 +26,55 @@ export type ResolveVariableTypes =
27
26
  | 'non-color-value'
28
27
 
29
28
  export const createPropMapper = (staticConfig: StaticConfigParsed) => {
30
- const variants = staticConfig.variants || {}
31
-
32
29
  // temp remove classnames
33
30
  const defaultProps = mergeProps(staticConfig.defaultProps || {}, {}, false)[0]
34
31
 
35
- let conf: TamaguiInternalConfig
36
-
37
32
  const mapper: PropMapper = (
38
33
  key,
39
34
  value,
40
- theme,
41
- propsIn,
42
- state,
43
- fontFamily,
44
- languageContext,
45
- avoidDefaultProps = false,
46
- debug
35
+ styleStateIn,
36
+ subPropsIn,
37
+ avoidDefaultProps = false
47
38
  ) => {
48
- conf ||= getConfig()
49
-
50
39
  if (!(process.env.TAMAGUI_TARGET === 'native' && isAndroid)) {
51
- if (key === 'elevationAndroid') {
52
- return
53
- }
40
+ if (key === 'elevationAndroid') return
54
41
  }
55
42
 
56
- const props = state.fallbackProps || propsIn
43
+ // we use this for the sub-props like pseudos so we need to overwrite the "props" in styleState
44
+ // fallbackProps is awkward thanks to static
45
+ // also we need to override the props here because subStyles pass in a sub-style props object
46
+ const subProps = styleStateIn.state.fallbackProps || subPropsIn
47
+ const styleState = subProps
48
+ ? {
49
+ ...styleStateIn,
50
+ curProps: subProps,
51
+ }
52
+ : styleStateIn
53
+
54
+ const { conf, state, fontFamily } = styleState
57
55
  const returnVariablesAs = state.resolveVariablesAs === 'value' ? 'value' : 'auto'
58
56
 
59
- if (
60
- process.env.NODE_ENV === 'development' &&
61
- fontFamily &&
62
- fontFamily[0] === '$' &&
63
- !(fontFamily in conf.fontsParsed)
64
- ) {
65
- console.warn(
66
- `Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(
67
- conf.fontsParsed
68
- ).join(', ')}`
69
- )
57
+ // prettier-ignore
58
+ if (process.env.NODE_ENV === 'development' && fontFamily && fontFamily[0] === '$' && !(fontFamily in conf.fontsParsed)) {
59
+ // prettier-ignore
60
+ console.warn(`Warning: no fontFamily "${fontFamily}" found in config: ${Object.keys(conf.fontsParsed).join(', ')}`)
70
61
  }
71
62
 
72
63
  const variantValue = resolveVariants(
73
64
  key,
74
65
  value,
75
- props,
66
+ styleState,
76
67
  defaultProps,
77
- theme,
78
- variants,
79
- fontFamily,
80
- conf,
81
68
  returnVariablesAs,
82
- staticConfig,
83
69
  '',
84
- languageContext,
85
- avoidDefaultProps,
86
- debug
70
+ avoidDefaultProps
87
71
  )
88
72
 
89
73
  if (variantValue) {
90
74
  return variantValue
91
75
  }
92
76
 
93
- let shouldReturn = value != null
77
+ let shouldReturn = false
94
78
 
95
79
  // handle shorthands
96
80
  if (key in conf.shorthands) {
@@ -100,22 +84,13 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
100
84
 
101
85
  if (value) {
102
86
  if (value[0] === '$') {
103
- value = getToken(
104
- key,
105
- value,
106
- conf,
107
- theme,
108
- fontFamily,
109
- languageContext,
110
- returnVariablesAs,
111
- debug
112
- )
87
+ value = getToken(key, value, styleState, returnVariablesAs)
113
88
  } else if (isVariable(value)) {
114
89
  value = resolveVariableValue(key, value, returnVariablesAs)
115
90
  }
116
91
  }
117
92
 
118
- if (shouldReturn) {
93
+ if (shouldReturn || value != null) {
119
94
  return expandStyle(key, value) || [[key, value]]
120
95
  }
121
96
  }
@@ -126,20 +101,16 @@ export const createPropMapper = (staticConfig: StaticConfigParsed) => {
126
101
  const resolveVariants: StyleResolver = (
127
102
  key,
128
103
  value,
129
- props,
104
+ styleState,
130
105
  defaultProps,
131
- theme,
132
- variants,
133
- fontFamily,
134
- conf,
135
106
  returnVariablesAs,
136
- staticConfig,
137
107
  parentVariantKey,
138
- languageContext,
139
- avoidDefaultProps = false,
140
- debug
108
+ avoidDefaultProps = false
141
109
  ) => {
142
- if (!(key in variants) || value === undefined) {
110
+ const { staticConfig, conf, debug } = styleState
111
+ const { variants } = staticConfig
112
+
113
+ if (!variants || !(key in variants) || value == null) {
143
114
  return
144
115
  }
145
116
 
@@ -169,14 +140,7 @@ const resolveVariants: StyleResolver = (
169
140
  const fn = variantValue as VariantSpreadFunction<any>
170
141
  variantValue = fn(
171
142
  value,
172
- getVariantExtras(
173
- props,
174
- languageContext,
175
- theme,
176
- defaultProps,
177
- avoidDefaultProps,
178
- fontFamily
179
- )
143
+ getVariantExtras(styleState, defaultProps, avoidDefaultProps)
180
144
  )
181
145
 
182
146
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
@@ -187,6 +151,12 @@ const resolveVariants: StyleResolver = (
187
151
  }
188
152
  }
189
153
 
154
+ // update curProps for variants expanded:
155
+ styleState.curProps = {
156
+ ...styleState.curProps,
157
+ ...variantValue,
158
+ }
159
+
190
160
  let fontFamilyResult: any
191
161
 
192
162
  if (isObj(variantValue)) {
@@ -194,29 +164,22 @@ const resolveVariants: StyleResolver = (
194
164
  variantValue.fontFamily || variantValue[conf.inverseShorthands.fontFamily]
195
165
 
196
166
  if (fontFamilyUpdate) {
197
- fontFamilyResult = getFontFamilyFromNameOrVariable(fontFamilyUpdate, conf)
167
+ styleState.fontFamily = getFontFamilyFromNameOrVariable(fontFamilyUpdate, conf)
198
168
  }
199
169
 
200
170
  variantValue = resolveTokensAndVariants(
201
171
  key,
202
172
  variantValue,
203
- props,
173
+ styleState,
204
174
  defaultProps,
205
- theme,
206
- variants,
207
- fontFamilyResult || fontFamily,
208
- conf,
209
175
  returnVariablesAs,
210
- staticConfig,
211
176
  parentVariantKey,
212
- languageContext,
213
- avoidDefaultProps,
214
- debug
177
+ avoidDefaultProps
215
178
  )
216
179
  }
217
180
 
218
181
  if (variantValue) {
219
- const expanded = expandStyles(variantValue)
182
+ const expanded = expandStylesAndRemoveNullishValues(variantValue)
220
183
 
221
184
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
222
185
  console.groupCollapsed('completing variant', key)
@@ -278,19 +241,14 @@ export const getPropMappedFontFamily = (expanded?: any) => {
278
241
  const resolveTokensAndVariants: StyleResolver<Object> = (
279
242
  key, // we dont use key assume value is object instead
280
243
  value,
281
- props,
244
+ styleState,
282
245
  defaultProps,
283
- theme,
284
- variants,
285
- fontFamily,
286
- conf,
287
246
  returnVariablesAs,
288
- staticConfig,
289
247
  parentVariantKey,
290
- languageContext,
291
- avoidDefaultProps,
292
- debug
248
+ avoidDefaultProps
293
249
  ) => {
250
+ const { conf, staticConfig, debug, theme } = styleState
251
+ const { variants } = staticConfig
294
252
  const res = {}
295
253
 
296
254
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
@@ -302,7 +260,7 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
302
260
  const fKey = conf.shorthands[rKey] || rKey
303
261
  const val = value[rKey]
304
262
 
305
- if (fKey in variants) {
263
+ if (variants && fKey in variants) {
306
264
  // avoids infinite loop if variant is matching a style prop
307
265
  // eg: { variants: { flex: { true: { flex: 2 } } } }
308
266
  if (parentVariantKey && parentVariantKey === key) {
@@ -311,18 +269,11 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
311
269
  const variantOut = resolveVariants(
312
270
  fKey,
313
271
  val,
314
- props,
272
+ styleState,
315
273
  defaultProps,
316
- theme,
317
- variants,
318
- fontFamily,
319
- conf,
320
274
  returnVariablesAs,
321
- staticConfig,
322
275
  key,
323
- languageContext,
324
- avoidDefaultProps,
325
- debug
276
+ avoidDefaultProps
326
277
  )
327
278
 
328
279
  // apply, merging sub-styles
@@ -353,18 +304,7 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
353
304
 
354
305
  if (typeof val === 'string') {
355
306
  const fVal =
356
- val[0] === '$'
357
- ? getToken(
358
- fKey,
359
- val,
360
- conf,
361
- theme,
362
- fontFamily,
363
- languageContext,
364
- returnVariablesAs,
365
- debug
366
- )
367
- : val
307
+ val[0] === '$' ? getToken(fKey, val, styleState, returnVariablesAs) : val
368
308
  res[fKey] = fVal
369
309
  continue
370
310
  }
@@ -373,18 +313,11 @@ const resolveTokensAndVariants: StyleResolver<Object> = (
373
313
  const subObject = resolveTokensAndVariants(
374
314
  fKey,
375
315
  val,
376
- props,
316
+ styleState,
377
317
  defaultProps,
378
- theme,
379
- variants,
380
- fontFamily,
381
- conf,
382
318
  returnVariablesAs,
383
- staticConfig,
384
319
  key,
385
- languageContext,
386
- avoidDefaultProps,
387
- debug
320
+ avoidDefaultProps
388
321
  )
389
322
 
390
323
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
@@ -452,13 +385,12 @@ const fontShorthand = {
452
385
  const getToken = (
453
386
  key: string,
454
387
  value: string,
455
- conf: TamaguiInternalConfig,
456
- theme: any,
457
- fontFamily: string | undefined,
458
- languageContext?: LanguageContextType,
388
+ styleState: GetStyleState,
459
389
  resolveAs?: ResolveVariableTypes,
460
390
  debug?: DebugProp
461
391
  ) => {
392
+ const { theme, conf, languageContext, fontFamily } = styleState
393
+
462
394
  const tokensParsed = conf.tokensParsed
463
395
  let valOrVar: any
464
396
  let hasSet = false
@@ -14,14 +14,20 @@ import { pseudoDescriptors } from './pseudoDescriptors'
14
14
  * 3. Expands react-native shorthands, ie paddingHorizontal => paddingLeft, paddingRight
15
15
  */
16
16
 
17
- export function expandStyles(style: Record<string, any>, { shorthands } = getConfig()) {
17
+ export function expandStylesAndRemoveNullishValues(
18
+ style: Record<string, any>,
19
+ { shorthands } = getConfig()
20
+ ) {
18
21
  const res: Record<string, any> = {}
19
22
 
20
23
  for (let key in style) {
21
24
  const valIn = style[key]
25
+ if (valIn == null) {
26
+ continue
27
+ }
22
28
  key = shorthands?.[key] || key
23
29
  if (key in pseudoDescriptors) {
24
- res[key] = expandStyles(valIn)
30
+ res[key] = expandStylesAndRemoveNullishValues(valIn)
25
31
  continue
26
32
  }
27
33
  const val = normalizeValueWithProperty(valIn, key)
@@ -36,6 +36,7 @@ import type {
36
36
  ClassNamesObject,
37
37
  DebugProp,
38
38
  GetStyleResult,
39
+ GetStyleState,
39
40
  MediaQueryKey,
40
41
  PseudoPropKeys,
41
42
  PseudoStyles,
@@ -49,7 +50,7 @@ import type {
49
50
  ThemeParsed,
50
51
  ViewStyleWithPseudos,
51
52
  } from '../types'
52
- import type { FontLanguageProps, LanguageContextType } from '../views/FontLanguage.types'
53
+ import type { LanguageContextType } from '../views/FontLanguage.types'
53
54
  import { createMediaStyle } from './createMediaStyle'
54
55
  import { getPropMappedFontFamily } from './createPropMapper'
55
56
  import { fixStyles } from './expandStyles'
@@ -67,21 +68,6 @@ import {
67
68
  } from './normalizeValueWithProperty'
68
69
  import { pseudoDescriptors } from './pseudoDescriptors'
69
70
 
70
- type GetStyleState = {
71
- style: TextStyleProps
72
- usedKeys: Record<string, number>
73
- classNames: ClassNamesObject
74
- staticConfig: StaticConfigParsed
75
- theme: ThemeParsed
76
- props: Record<string, any>
77
- viewProps: Record<string, any>
78
- state: SplitStyleState
79
- conf: TamaguiInternalConfig
80
- languageContext?: FontLanguageProps
81
- avoidDefaultProps?: boolean
82
- avoidMergeTransform?: boolean
83
- }
84
-
85
71
  // bugfix for some reason it gets reset
86
72
  const IS_STATIC = process.env.IS_STATIC === 'is_static'
87
73
 
@@ -162,14 +148,13 @@ export const getSplitStyles: StyleSplitter = (
162
148
  // value is [hash, val], so ["-jnjad-asdnjk", "scaleX(1) rotate(10deg)"]
163
149
  const transforms: Record<TransformNamespaceKey, [string, string]> = {}
164
150
 
165
- // fontFamily is our special baby, ensure we grab the latest set one always
166
- let fontFamily: string | undefined
167
151
  let mediaStylesSeen = 0
168
152
 
169
153
  /**
170
154
  * Not the biggest fan of creating this object but it is a nice API
171
155
  */
172
156
  const styleState: GetStyleState = {
157
+ curProps: props,
173
158
  classNames,
174
159
  conf,
175
160
  props,
@@ -180,6 +165,7 @@ export const getSplitStyles: StyleSplitter = (
180
165
  usedKeys,
181
166
  viewProps,
182
167
  languageContext,
168
+ debug,
183
169
  }
184
170
 
185
171
  if (process.env.NODE_ENV === 'development' && debug && isClient) {
@@ -553,34 +539,24 @@ export const getSplitStyles: StyleSplitter = (
553
539
  // default font family
554
540
  // is this great? no, but backwards compat until we add tests and make better
555
541
  defaultFontVariable ||= `$${conf.defaultFont}`
556
- fontFamily ||=
542
+ styleState.fontFamily ||=
557
543
  props[conf.inverseShorthands.fontFamily] || props.fontFamily || defaultFontVariable
558
544
 
559
545
  const expanded =
560
546
  isMediaOrPseudo || (!(keyInit in validStyleProps) && !isVariant)
561
547
  ? [[keyInit, valInit]]
562
- : propMapper(
563
- keyInit,
564
- valInit,
565
- theme,
566
- props,
567
- state,
568
- fontFamily,
569
- languageContext,
570
- undefined,
571
- debug
572
- )
548
+ : propMapper(keyInit, valInit, styleState)
573
549
 
574
- if (!fontFamily) {
575
- fontFamily = getPropMappedFontFamily(expanded)
550
+ if (!styleState.fontFamily) {
551
+ styleState.fontFamily = getPropMappedFontFamily(expanded)
576
552
  }
577
553
 
578
554
  if (process.env.NODE_ENV === 'development' && debug === 'verbose') {
579
- console.groupCollapsed(' 🔹 expanded', keyInit, valInit)
555
+ console.groupCollapsed(' 💠 expanded', keyInit, valInit)
580
556
  if (!isServer && isDevTools) {
581
557
  // prettier-ignore
582
558
  // rome-ignore lint/nursery/noConsoleLog: <explanation>
583
- console.log({ expanded, state: { ...state }, isVariant, variant: variants?.[keyInit], shouldPassProp, isHOCShouldPassThrough, theme, usedKeys: { ...usedKeys } })
559
+ console.log({ expanded, state: { ...state }, isVariant, variant: variants?.[keyInit], shouldPassProp, isHOCShouldPassThrough, theme, usedKeys: { ...usedKeys }, curProps: { ...styleState.curProps } })
584
560
  // rome-ignore lint/nursery/noConsoleLog: ok
585
561
  console.log('expanded', expanded, '\nusedKeys', { ...usedKeys }, '\ncurrent', {
586
562
  ...style,
@@ -631,7 +607,6 @@ export const getSplitStyles: StyleSplitter = (
631
607
  styleState,
632
608
  key,
633
609
  val,
634
- fontFamily,
635
610
  true,
636
611
  state.noClassNames
637
612
  )
@@ -796,7 +771,6 @@ export const getSplitStyles: StyleSplitter = (
796
771
  styleState,
797
772
  key,
798
773
  val,
799
- fontFamily,
800
774
  // TODO try true like pseudo
801
775
  false
802
776
  )
@@ -898,7 +872,7 @@ export const getSplitStyles: StyleSplitter = (
898
872
  mediaState[mediaKeyShort]
899
873
  )
900
874
  if (key === 'fontFamily') {
901
- fontFamily = mediaStyle.fontFamily as string
875
+ styleState.fontFamily = mediaStyle.fontFamily as string
902
876
  }
903
877
  }
904
878
  }
@@ -912,10 +886,10 @@ export const getSplitStyles: StyleSplitter = (
912
886
  }
913
887
  }
914
888
 
915
- if (key === 'fontFamily' && !fontFamily && valInit && val) {
889
+ if (key === 'fontFamily' && !styleState.fontFamily && valInit && val) {
916
890
  const fam = valInit[0] === '$' ? valInit : val
917
891
  if (fam in conf.fontsParsed) {
918
- fontFamily = fam
892
+ styleState.fontFamily = fam
919
893
  }
920
894
  }
921
895
 
@@ -944,7 +918,7 @@ export const getSplitStyles: StyleSplitter = (
944
918
  }
945
919
 
946
920
  // default to default font
947
- fontFamily ||= conf.defaultFont
921
+ styleState.fontFamily ||= conf.defaultFont
948
922
 
949
923
  fixStyles(style)
950
924
  if (isWeb) {
@@ -960,7 +934,7 @@ export const getSplitStyles: StyleSplitter = (
960
934
  faceInfo[style.fontWeight as string]?.[style.fontStyle || 'normal']?.val
961
935
  if (overrideFace) {
962
936
  style.fontFamily = overrideFace
963
- fontFamily = overrideFace
937
+ styleState.fontFamily = overrideFace
964
938
  delete style.fontWeight
965
939
  delete style.fontStyle
966
940
  }
@@ -1097,7 +1071,7 @@ export const getSplitStyles: StyleSplitter = (
1097
1071
  const result: GetStyleResult = {
1098
1072
  space,
1099
1073
  hasMedia,
1100
- fontFamily,
1074
+ fontFamily: styleState.fontFamily,
1101
1075
  viewProps,
1102
1076
  // @ts-expect-error
1103
1077
  style,
@@ -1211,11 +1185,10 @@ export const getSubStyle = (
1211
1185
  styleState: GetStyleState,
1212
1186
  subKey: string,
1213
1187
  styleIn: Object,
1214
- fontFamily?: string,
1215
1188
  avoidDefaultProps?: boolean,
1216
1189
  avoidMergeTransform?: boolean
1217
1190
  ): TextStyleProps => {
1218
- const { staticConfig, theme, props, state, conf, languageContext } = styleState
1191
+ const { staticConfig, props, conf } = styleState
1219
1192
  const styleOut: TextStyleProps = {}
1220
1193
 
1221
1194
  for (let key in styleIn) {
@@ -1224,11 +1197,8 @@ export const getSubStyle = (
1224
1197
  const expanded = staticConfig.propMapper(
1225
1198
  key,
1226
1199
  val,
1227
- theme,
1200
+ styleState,
1228
1201
  getSubStyleProps(staticConfig.defaultProps, props, props[subKey]),
1229
- state,
1230
- fontFamily,
1231
- languageContext,
1232
1202
  avoidDefaultProps
1233
1203
  )
1234
1204
  if (!expanded || (!staticConfig.isHOC && key in skipProps)) {
@@ -1368,6 +1338,8 @@ if (process.env.TAMAGUI_TARGET === 'native') {
1368
1338
  } else {
1369
1339
  Object.assign(skipProps, {
1370
1340
  elevationAndroid: 1,
1341
+ allowFontScaling: true,
1342
+ adjustsFontSizeToFit: true,
1371
1343
  })
1372
1344
  }
1373
1345
 
@@ -1,23 +1,19 @@
1
- import { getConfig } from '../config'
2
1
  import { getVariableValue } from '../createVariable'
3
- import { GenericFonts } from '../types'
2
+ import { GenericFonts, GetStyleState } from '../types'
4
3
  import { LanguageContextType } from '../views/FontLanguage.types'
5
4
  import { createProxy } from './createProxy'
6
5
 
7
6
  const extrasCache = new WeakMap()
8
7
 
9
8
  export function getVariantExtras(
10
- props: any,
11
- languageContext?: LanguageContextType,
12
- theme?: any,
9
+ styleState: GetStyleState,
13
10
  defaultProps?: any,
14
- avoidDefaultProps = false,
15
- fontFamily?: string
11
+ avoidDefaultProps = false
16
12
  ) {
17
- const conf = getConfig()
13
+ const { curProps, conf, languageContext, theme } = styleState
18
14
 
19
- if (extrasCache.has(props)) {
20
- return extrasCache.get(props)
15
+ if (extrasCache.has(curProps)) {
16
+ return extrasCache.get(curProps)
21
17
  }
22
18
 
23
19
  let fonts = conf.fontsParsed
@@ -25,24 +21,22 @@ export function getVariantExtras(
25
21
  fonts = getFontsForLanguage(conf.fontsParsed, languageContext)
26
22
  }
27
23
 
24
+ // should be able to just use styleState.fontFamily but no time to test for now
25
+ const fontFamily = getVariableValue(
26
+ styleState.fontFamily || styleState.curProps.fontFamily || styleState.conf.defaultFont
27
+ )
28
+
28
29
  const next = {
29
30
  fonts,
30
31
  tokens: conf.tokensParsed,
31
32
  theme,
32
-
33
- get fontFamily() {
34
- return getVariableValue(fontFamily || props.fontFamily)
35
- },
36
-
37
- get font() {
38
- return fonts[this.fontFamily]
39
- },
40
-
33
+ fontFamily,
34
+ font: fonts[fontFamily],
41
35
  // TODO do this in splitstlye
42
36
  // we avoid passing in default props for media queries because that would confuse things like SizableText.size:
43
37
  props: avoidDefaultProps
44
- ? props
45
- : createProxy(props, {
38
+ ? curProps
39
+ : createProxy(curProps, {
46
40
  // handles shorthands
47
41
  get(target, key) {
48
42
  const shorthand = conf.inverseShorthands[key as any]
@@ -68,7 +62,7 @@ export function getVariantExtras(
68
62
  }),
69
63
  }
70
64
 
71
- extrasCache.set(props, next)
65
+ extrasCache.set(curProps, next)
72
66
 
73
67
  return next
74
68
  }
@@ -195,10 +195,10 @@ export const useChangeThemeEffect = (
195
195
  prevState: ThemeManagerState = state,
196
196
  forceShouldChange = false
197
197
  ) {
198
- if (forceShouldChange) return
199
198
  const forceUpdate = shouldUpdate?.()
200
- if (forceUpdate === false) return
199
+ if (!forceShouldChange && forceUpdate === false) return
201
200
  const next = nextState || manager.getState(props, parentManager)
201
+ if (forceShouldChange) return next
202
202
  if (!next) return
203
203
  if (forceUpdate !== true) {
204
204
  if (!manager.getStateShouldChange(next, prevState)) return