8
8
* @format
9
9
*/
10
10
11
+ import type { TextStyleProp } from '../StyleSheet/StyleSheet' ;
12
+ import type { ____TextStyle_Internal as TextStyleInternal } from '../StyleSheet/StyleSheetTypes' ;
11
13
import type { PressEvent } from '../Types/CoreEventTypes' ;
12
14
import type { NativeTextProps } from './TextNativeComponent' ;
13
15
import type { PressRetentionOffset , TextProps } from './TextProps' ;
@@ -23,7 +25,7 @@ import * as React from 'react';
23
25
import { useContext , useMemo , useState } from 'react' ;
24
26
25
27
const View = require ( '../Components/View/View' ) ; // [Windows]
26
- import { type TextStyleProp , type ViewStyleProp } from '../StyleSheet/StyleSheet' ; // [Windows]
28
+ import { type ViewStyleProp } from '../StyleSheet/StyleSheet' ; // [Windows]
27
29
28
30
type TextForwardRef = React . ElementRef <
29
31
typeof NativeText | typeof NativeVirtualText ,
@@ -144,25 +146,32 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
144
146
145
147
let _selectable = selectable ;
146
148
147
- const processedStyle = flattenStyle ( _style ) ;
149
+ let processedStyle = flattenStyle < TextStyleProp > ( _style ) ;
148
150
if ( processedStyle != null ) {
151
+ let overrides : ?{ ...TextStyleInternal } = null ;
149
152
if ( typeof processedStyle . fontWeight === 'number' ) {
150
- // $FlowFixMe[cannot-write]
151
- processedStyle . fontWeight = processedStyle . fontWeight . toString ( ) ;
153
+ overrides = overrides || ( { } : { ...TextStyleInternal } ) ;
154
+ overrides . fontWeight =
155
+ // $FlowFixMe[incompatible-cast]
156
+ ( processedStyle . fontWeight . toString ( ) : TextStyleInternal [ 'fontWeight' ] ) ;
152
157
}
153
158
154
159
if ( processedStyle . userSelect != null ) {
155
160
_selectable = userSelectToSelectableMap [ processedStyle . userSelect ] ;
156
- // $FlowFixMe[cannot-write]
157
- delete processedStyle . userSelect ;
161
+ overrides = overrides || ( { } : { ... TextStyleInternal } ) ;
162
+ overrides . userSelect = undefined ;
158
163
}
159
164
160
165
if ( processedStyle . verticalAlign != null ) {
161
- // $FlowFixMe[cannot-write]
162
- processedStyle . textAlignVertical =
166
+ overrides = overrides || ( { } : { ... TextStyleInternal } ) ;
167
+ overrides . textAlignVertical =
163
168
verticalAlignToTextAlignVerticalMap [ processedStyle . verticalAlign ] ;
164
- // $FlowFixMe[cannot-write]
165
- delete processedStyle . verticalAlign ;
169
+ overrides . verticalAlign = undefined ;
170
+ }
171
+
172
+ if ( overrides != null ) {
173
+ // $FlowFixMe[incompatible-type]
174
+ _style = [ _style , overrides ] ;
166
175
}
167
176
}
168
177
@@ -185,7 +194,7 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
185
194
numberOfLines : _numberOfLines ,
186
195
selectable : _selectable ,
187
196
selectionColor : _selectionColor ,
188
- style : processedStyle ,
197
+ style : _style ,
189
198
disabled : disabled ,
190
199
children,
191
200
} }
@@ -222,7 +231,7 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
222
231
ref = { forwardedRef}
223
232
selectable = { _selectable}
224
233
selectionColor = { _selectionColor}
225
- style = { processedStyle }
234
+ style = { _style }
226
235
disabled = { disabled} >
227
236
{ children}
228
237
< / N a t i v e V i r t u a l T e x t >
@@ -269,7 +278,7 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
269
278
numberOfLines : _numberOfLines ,
270
279
selectable : _selectable ,
271
280
selectionColor : _selectionColor ,
272
- style : processedStyle ,
281
+ style : _style ,
273
282
children,
274
283
} }
275
284
textPressabilityProps = { {
@@ -307,7 +316,7 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
307
316
ref = { forwardedRef }
308
317
selectable = { _selectable }
309
318
selectionColor = { _selectionColor }
310
- style = { processedStyle } >
319
+ style = { _style } >
311
320
{ children }
312
321
</ NativeText >
313
322
) ;
@@ -328,50 +337,6 @@ const Text: React.AbstractComponent<TextProps, TextForwardRef> =
328
337
styleProps . borderStartWidth != null ||
329
338
styleProps . borderTopWidth != null )
330
339
) {
331
- let textStyleProps = Array . isArray ( styleProps )
332
- ? // $FlowFixMe[underconstrained-implicit-instantiation]
333
- flattenStyle ( styleProps )
334
- : styleProps ;
335
- let {
336
- // $FlowFixMe[prop-missing]
337
- margin,
338
- // $FlowFixMe[prop-missing]
339
- marginBottom,
340
- // $FlowFixMe[prop-missing]
341
- marginEnd,
342
- // $FlowFixMe[prop-missing]
343
- marginHorizontal,
344
- // $FlowFixMe[prop-missing]
345
- marginLeft,
346
- // $FlowFixMe[prop-missing]
347
- marginRight,
348
- // $FlowFixMe[prop-missing]
349
- marginStart,
350
- // $FlowFixMe[prop-missing]
351
- marginTop,
352
- // $FlowFixMe[prop-missing]
353
- marginVertical,
354
- // $FlowFixMe[prop-missing]
355
- padding,
356
- // $FlowFixMe[prop-missing]
357
- paddingBottom,
358
- // $FlowFixMe[prop-missing]
359
- paddingEnd,
360
- // $FlowFixMe[prop-missing]
361
- paddingHorizontal,
362
- // $FlowFixMe[prop-missing]
363
- paddingLeft,
364
- // $FlowFixMe[prop-missing]
365
- paddingRight,
366
- // $FlowFixMe[prop-missing]
367
- paddingStart,
368
- // $FlowFixMe[prop-missing]
369
- paddingTop,
370
- // $FlowFixMe[prop-missing]
371
- paddingVertical,
372
- // $FlowFixMe[not-an-object]
373
- ...rest
374
- } = textStyleProps != null ? textStyleProps : { } ;
375
340
return (
376
341
< View style = { styleProps } >
377
342
< TextAncestor . Provider value = { true } >
0 commit comments