左侧为Android的<TextInput>切口粗体文本错误

问题描述

我有本机的 TextInput ,如果我输入长字符串,它会自动增长。在iOS上,它可以按预期工作,但在Android上,它会在5到7个字符后从左侧开始截取。弦越长-截止点越大。我试图删除页边距和填充物-没有变化。我调查了文档中的道具-找不到解决方案。我可以滚动查看截断的字符串,但是除非没有更多空间可扩展,否则我希望不滚动即可看到它。

          <TextInput
            key={key}
            style={{
                flex:1,fontSize: '1.2rem',fontWeight: 'bold',}}
            value={this.state.value}
            onChangeText={this._onChangeText}
            underlineColorAndroid="transparent"
            autoCapitalize="none"
            autoCompleteType='off' // Android
            autoCorrect={false} // iOS
            contextMenuHidden={true}
            importantForAutofill="no"
            keyboardAppe@R_502_6460@nce="dark"
            maxLength={150}
            returnKeyType={returnKeyType}
            spellCheck={false}
            keyboardType={Platform.OS==='ios'
              ?'default'
              :"visible-password" // to disable autocorrect suggestions on android
            } 
          />

enter image description here

解决方法

在准备问题时,我发现设置fontWeight: 'bold'会导致此问题。但我仍在研究如何使其与粗体文本一起使用(如果可能)。

enter image description here

我试图找到一种没有粗体属性的粗体字体,但是它的行为却相同……因此,看来TextInput仅适用于没有粗体属性的默认字体,这很不方便。

在github上的问题:https://github.com/facebook/react-native/issues/30317

,

在TextInput元素上将textBreakStrategy设置为simple似乎也可以在某些设备上使用。

基本上这是与系统字体的冲突,因此您可以为文本输入指定其他一些fontFamily。在更多hack上,可以在左侧添加一些额外的空间