React Native TextInput - 更新值时向左滚动

React Native TextInput - Scroll to left when value is updated

我有一行 TextInput 可以通过 UI 的其他部分进行更新。

我的问题是,有时文本可能会很长。在这种情况下,当我更新 value 时,TextInput 一直滚动到其内容的末尾。我需要 TextInput 在更新时保持在左侧。

我有什么办法可以做到这一点吗?

Expo SDK 37、React Native 0.61、React 16.9

如果我理解正确,您想将“可见文本”移动到 TextInput 的开头,但只有当您通过 props 设置值时(我假设用户在输入时能够查看字符串的最后部分)。

如果这是您的问题,我有时会使用以下代码解决它(this.input 是对您的 TextInput 的引用)

 if (this.input) {
   this.input.setNativeProps({
     selection: {
       start: 0,
       end: 0
     }
   });
 }

让我知道这是否适合你:)