zholmes1
zholmes1

Reputation: 609

React Native TextInput - Scroll to left when value is updated

I have a single line TextInput that can be updated via other parts of the UI.

My issue is that sometimes, the text can be long. And in this case, when I update the value, the TextInput scrolls all the way to the end of its content. I need the TextInput to stay pegged to the left when it is updated.

Is there any way for me to do this?

Expo SDK 37, React Native 0.61, React 16.9

Upvotes: 2

Views: 908

Answers (1)

Fabrizio Rizzonelli
Fabrizio Rizzonelli

Reputation: 429

If I understand right, you want to move the "visible text" to the beginning of the TextInput, but only when you set value via props (I assume that, while typing, users will be able to see last portion of the string).

If this is your issue, I managed to fix it sometimes ago with the following code (this.input is the ref to your TextInput)

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

Let me know if this works for you :)

Upvotes: 3

Related Questions