diff --git a/packages/react-native/Libraries/Components/TextInput/TextInput.js b/packages/react-native/Libraries/Components/TextInput/TextInput.js index 8b827ae1cc6969..7fe1210f8278d7 100644 --- a/packages/react-native/Libraries/Components/TextInput/TextInput.js +++ b/packages/react-native/Libraries/Components/TextInput/TextInput.js @@ -1646,6 +1646,10 @@ const ExportedForwardRef: React.AbstractComponent< let style = flattenStyle(restProps.style); if (style?.verticalAlign != null) { + if (Object.isFrozen(style)) { + // $FlowFixMe[incompatible-type] + style = {...style}; + } // $FlowFixMe[prop-missing] // $FlowFixMe[cannot-write] style.textAlignVertical = diff --git a/packages/react-native/Libraries/Text/TextOptimized.js b/packages/react-native/Libraries/Text/TextOptimized.js index 615badd9ad6758..01cab7b5257df2 100644 --- a/packages/react-native/Libraries/Text/TextOptimized.js +++ b/packages/react-native/Libraries/Text/TextOptimized.js @@ -8,6 +8,7 @@ * @format */ +import type {____TextStyle_Internal as TextStyleInternal} from '../StyleSheet/StyleSheetTypes'; import type {PressEvent} from '../Types/CoreEventTypes'; import type {NativeTextProps} from './TextNativeComponent'; import type {PressRetentionOffset, TextProps} from './TextProps'; @@ -141,25 +142,32 @@ const TextOptimized: React.AbstractComponent = let _selectable = selectable; - const processedStyle = flattenStyle(_style); + let processedStyle: ?TextStyleInternal = flattenStyle(_style); if (processedStyle != null) { + let overrides: ?{...TextStyleInternal} = null; if (typeof processedStyle.fontWeight === 'number') { - // $FlowFixMe[cannot-write] - processedStyle.fontWeight = processedStyle.fontWeight.toString(); + overrides = overrides || ({}: {...TextStyleInternal}); + overrides.fontWeight = + // $FlowFixMe[incompatible-cast] + (processedStyle.fontWeight.toString(): TextStyleInternal['fontWeight']); } if (processedStyle.userSelect != null) { _selectable = userSelectToSelectableMap[processedStyle.userSelect]; - // $FlowFixMe[cannot-write] - delete processedStyle.userSelect; + overrides = overrides || ({}: {...TextStyleInternal}); + overrides.userSelect = undefined; } if (processedStyle.verticalAlign != null) { - // $FlowFixMe[cannot-write] - processedStyle.textAlignVertical = + overrides = overrides || ({}: {...TextStyleInternal}); + overrides.textAlignVertical = verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign]; - // $FlowFixMe[cannot-write] - delete processedStyle.verticalAlign; + overrides.verticalAlign = undefined; + } + + if (overrides != null) { + // $FlowFixMe[incompatible-type] + processedStyle = [processedStyle, overrides]; } }