Skip to content

Commit

Permalink
Cleanup style checks (#44864)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44864

Switch the style normalizer checks to only do a single top level `null` check and remove unneeded flow suppression comments.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D58386781

fbshipit-source-id: e4df6fdadb5bfab4c8ae674a420ac453ba262f78
  • Loading branch information
pieterv authored and facebook-github-bot committed Jun 12, 2024
1 parent ce588db commit 872d5d3
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions packages/react-native/Libraries/Text/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,33 +212,28 @@ const Text: React.AbstractComponent<
default: accessible,
});

// $FlowFixMe[underconstrained-implicit-instantiation]
style = flattenStyle(style);
let _selectable = restProps.selectable;

if (typeof style?.fontWeight === 'number') {
// $FlowFixMe[prop-missing]
// $FlowFixMe[cannot-write]
style.fontWeight = style?.fontWeight.toString();
}
const processedStyle = flattenStyle(style);
if (processedStyle != null) {
if (typeof processedStyle.fontWeight === 'number') {
// $FlowFixMe[cannot-write]
processedStyle.fontWeight = processedStyle.fontWeight.toString();
}

let _selectable = restProps.selectable;
if (style?.userSelect != null) {
// $FlowFixMe[invalid-computed-prop]
_selectable = userSelectToSelectableMap[style.userSelect];
// $FlowFixMe[prop-missing]
// $FlowFixMe[cannot-write]
delete style.userSelect;
}
if (processedStyle.userSelect != null) {
_selectable = userSelectToSelectableMap[processedStyle.userSelect];
// $FlowFixMe[cannot-write]
delete processedStyle.userSelect;
}

if (style?.verticalAlign != null) {
// $FlowFixMe[prop-missing]
// $FlowFixMe[cannot-write]
style.textAlignVertical =
// $FlowFixMe[invalid-computed-prop]
verticalAlignToTextAlignVerticalMap[style.verticalAlign];
// $FlowFixMe[prop-missing]
// $FlowFixMe[cannot-write]
delete style.verticalAlign;
if (processedStyle.verticalAlign != null) {
// $FlowFixMe[cannot-write]
processedStyle.textAlignVertical =
verticalAlignToTextAlignVerticalMap[processedStyle.verticalAlign];
// $FlowFixMe[cannot-write]
delete processedStyle.verticalAlign;
}
}

const _hasOnPressOrOnLongPress =
Expand All @@ -257,7 +252,7 @@ const Text: React.AbstractComponent<
ref={forwardedRef}
selectable={_selectable}
selectionColor={selectionColor}
style={style}
style={processedStyle}
/>
) : (
<TextAncestor.Provider value={true}>
Expand All @@ -280,7 +275,7 @@ const Text: React.AbstractComponent<
ref={forwardedRef}
selectable={_selectable}
selectionColor={selectionColor}
style={style}
style={processedStyle}
/>
</TextAncestor.Provider>
);
Expand Down

0 comments on commit 872d5d3

Please sign in to comment.