Skip to content

Commit 15f27bc

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Handle fontWeight normalization for TextInput component
Summary: Web props work (somewhere around D41230978 and D39268920) made it so that numeric font weights can be set instead of just strings. This is implemented by converting number to string before passing to native component within the `Text` component. We have crash with: ``` 2024-04-19 09:38:21.360 16963 17190 E ViewManager: Error while updating prop fontWeight 2024-04-19 09:38:21.360 16963 17190 E ViewManager: java.lang.IllegalArgumentException: method com.facebook.react.views.text.ReactBaseTextShadowNode.setFontWeight argument 1 has type java.lang.String, got java.lang.Double 2024-04-19 09:38:21.360 16963 17190 E ViewManager: at java.lang.reflect.Method.invoke(Native Method) ``` `TextStyleProps` can also be passed to `TextInput`, which passes to underlying native component, without going through this logic. And the types for Native props directly derive from JS props, so type system does not catch passing incorrect number type to underlying native component. This does a quick and dirty replication of the exact logic in `Text.js` to `TextInput.js`. I'd love to potentially fix this up for Fabric in a different way when we rethink CSS parsing. Changelog: [General][Fixed] - Handle `fontWeight` normalization for TextInput component Reviewed By: arushikesarwani94 Differential Revision: D56539571 fbshipit-source-id: 8975886c117d814a624f817bffe408841bb03b88
1 parent cf926a1 commit 15f27bc

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/react-native/Libraries/Components/TextInput/TextInput.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,12 @@ function InternalTextInput(props: Props): React.Node {
14011401

14021402
const style = flattenStyle<TextStyleProp>(props.style);
14031403

1404+
if (typeof style?.fontWeight === 'number') {
1405+
// $FlowFixMe[prop-missing]
1406+
// $FlowFixMe[cannot-write]
1407+
style.fontWeight = style?.fontWeight.toString();
1408+
}
1409+
14041410
if (Platform.OS === 'ios') {
14051411
const RCTTextInputView =
14061412
props.multiline === true

packages/rn-tester/js/examples/TextInput/TextInputExample.android.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ const examples: Array<RNTesterModuleExample> = [
222222
'normal',
223223
'bold',
224224
'900',
225-
'800',
225+
800,
226226
'700',
227227
'600',
228228
'500',

0 commit comments

Comments
 (0)