I have a TextInput in React native. If i change the value using keyboard it works fine but, if i change it programmatically using a useState var then, if the text is too long, the text alignment becomes centered and i saw the text cut off on both sides. enter image description here

我只想删掉结尾处的文字.

它在iOS上运行得很好,但在Android上就不行了.

谢谢你的帮助!

我试着用风格来做到这一点,但没有运气.文本对齐在第一次加载时是正确的,但如果我以编程方式更改它,则不是正确的. 预期的行为是看到文本仅在结尾处被切断.

下面是我的TextInput代码.没什么可看的:)

         <TextInput
          ref={ref}
          editable={!props.disabled}
          placeholder={isFocus || props.value ? undefined : props.title}
          placeholderTextColor={colors.neutral[600]}
          maxLength={props.maxLength || 60}
          onFocus={setFocusOn}
          onBlur={setFocusOff}
          multiline={false}
          value={checkedItems.length > 0 ? boxInfo : null}
        />

推荐答案

最后,我设法在Android中使用了MaxLength来"修复"它.现在我使用固定值,但我将使用与屏幕宽度相关的值. 以下是我的代码:

     <TextInput
      ref={ref}
      editable={!props.disabled}
      placeholder={isFocus || props.value ? undefined : props.title}
      placeholderTextColor={colors.neutral[600]}
      maxLength={props.maxLength || 60}
      onFocus={setFocusOn}
      onBlur={setFocusOff}
      multiline={false}
      maxLength={Platform.OS === 'ios' ? 0 : 42
      value={checkedItems.length > 0 ? boxInfo : null}
    />

以防它能帮上什么人.

React-native相关问答推荐

构建 iOS Expo 应用时出现 React-Native xcodebuild 错误 65

使用 Auth Token 标头react 本机图像,如何处理 401?

react native调用fetch后如何使用Async Storage在本地保存数据?

React Native - 动画宽度缩小

从 React 原生 Js 代码调用 Android Native UI 组件方法

使用 React Native 下载数据文件以供离线使用

使用 Bearer身份验证令牌react native图像

react native图像不适用于特定 URL

React Native:如何获取文件大小、mime 类型和扩展名?

未计算文件的 React-Native Bundle Error 错误 SHA-1

Android 依赖 'com.google.android.gms:play-services-stats' 的编译(16.0.1)和运行时(17.0.0)类路径有不同的版本

React Native require(image) 返回数字

使用 expo SDK react-native ios 应用程序的 Info.plist 文件

在 react-native 中设置动态 'initialRouteName'

是否需要使用 StyleSheet.create?

运行时尚未准备好进行调试

React Native 从导航堆栈中清除上一个屏幕

ReactNative TextInput 不可见 iOS

如何在react-native中显示toast消息

使用 React Native 运行多个 iOS 模拟器?