Skip to content

Commit 3cfa201

Browse files
committed
fix(TextInput): fall back to theme fontWeight when style doesn't provide one
Both TextInputOutlined and TextInputFlat destructure `fontWeight` from the user's `style` prop and spread it after the theme font object: const { fontWeight } = StyleSheet.flatten(style) || {}; textStyle: { ...font, fontWeight } When the user doesn't set `fontWeight` in their style, the destructured value is `undefined`. Spreading `{ ...font, fontWeight: undefined }` then overrides `font.fontWeight` (e.g. '400' from the theme) with `undefined`. On React Native's Fabric renderer (New Architecture), this `undefined` flows through as nil to the native `RCTGetFontWeight` function, which passes it to `CFStringFind` → `CFStringGetLength` on a NULL pointer → EXC_BAD_ACCESS (SIGSEGV). The fix renames the destructured variable to `fontWeightStyle` and uses nullish coalescing to fall back to the theme font's fontWeight: const fontWeight = fontWeightStyle ?? font.fontWeight; This preserves the existing behavior when `fontWeight` IS provided in the style prop, while preventing the nil crash when it isn't.
1 parent ad744ff commit 3cfa201

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/components/TextInput/TextInputFlat.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ const TextInputFlat = ({
8888
const {
8989
fontSize: fontSizeStyle,
9090
lineHeight: lineHeightStyle,
91-
fontWeight,
91+
fontWeight: fontWeightStyle,
9292
height,
9393
paddingHorizontal,
9494
textAlign,
9595
...viewStyle
9696
} = (StyleSheet.flatten(style) || {}) as TextStyle;
97+
const fontWeight = fontWeightStyle ?? font.fontWeight;
9798
const fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
9899
const lineHeight =
99100
lineHeightStyle || (Platform.OS === 'web' ? fontSize * 1.2 : undefined);

src/components/TextInput/TextInputOutlined.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ const TextInputOutlined = ({
9090

9191
const {
9292
fontSize: fontSizeStyle,
93-
fontWeight,
93+
fontWeight: fontWeightStyle,
9494
lineHeight: lineHeightStyle,
9595
height,
9696
backgroundColor = colors?.background,
9797
textAlign,
9898
...viewStyle
9999
} = (StyleSheet.flatten(style) || {}) as TextStyle;
100+
const fontWeight = fontWeightStyle ?? font.fontWeight;
100101
const fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE;
101102
const lineHeight =
102103
lineHeightStyle || (Platform.OS === 'web' ? fontSize * 1.2 : undefined);

0 commit comments

Comments
 (0)