Skip to content

iOS RN TextInput 文本偏下问题解决

症状

一个普通的 TextInput,在安卓上展现没问题,iOS 会有文本偏下的问题,甚至英文字符会被裁切。

image-20251229155745387

image-20251229155753006

解决方案

设置 iOS 下的 lineHeight 为 0

tsx
<TextInput
  ...
  style={styles.textInput}
/>

const styles = StyleSheet.create({
  // iOS 文本垂直居中问题修复
  textInput: Platform.OS === 'ios' ? { lineHeight: 0 } : {},
});

参考来源:https://github.com/facebook/react-native/issues/39145#issuecomment-3153012157

感想

RN 跨平台总会有一些奇葩问题出现,好在社区足够大,但还是有种吃屎的感觉。

上次更新于: