question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autoscroll to TextInput working partially when blurOnSubmit={false}

See original GitHub issue

I noticed that if you use blurOnSubmit={false}, auto scroll to next focused input will be triggered only when its value is not empty.

Pseudo code example :

<KeyboardAwareScrollView>
  <TextInput
              ref='input1'
              onSubmitEditing={this.input2.focus()}
              blurOnSubmit={false}
              returnKeyType='next' />

  <View style={{ height: 500 }} /> /** Make the scroll **/

  <TextInput ref='input2'/>

Tested on Android only.

Expected behavior :

  • Write something on input1
  • Click on Next button from keyboard
  • input2 get the focus
  • auto scroll to input2.

Current behavior :

  • Write something on input1
  • Click on Next button from keyboard
  • input2 get the focus
  • auto scroll to input2 not done
  • Write something on input2
  • Auto scroll to input2 done.

Seems related to the fact input1 does not blur() before to give focus.

If you ask why using blurOnSubmit=false: it avoids keyboard to close/reopen everytime we switch of input, on Android at least.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13

github_iconTop GitHub Comments

8reactions
jordenchang55commented, Aug 10, 2017
<KeyboardAwareScrollView>
  <TextInput
	  onSubmitEditing={this.input2.focus()}
	  returnKeyType='next' />
  <TextInput
	  ref={i=>this.inputs.input2 = i}
	  onSubmitEditing={this.input3.focus()}
	  returnKeyType='next' />
  <TextInput
	  ref={i=>this.inputs.input3 = i}
	  onSubmitEditing={this.input4.focus()}
	  returnKeyType='next' />
{/* Input4 is outside of visible region*/}
  <TextInput
	  ref={i=>this.inputs.input4 = i}/>
</KeyboardAwareScrollView>

Here’s the code. For simple, I remove the code about style. I implement next function by myself, so when I click next button, it will focus on next input. The library can work as expected if current input and next input are both in visible region. For example, click next button on input1, it will scroll to input2 automatically. But if the next input is not in visible region, i.e. user need to scroll to see it, auto-scroll will not work.

2reactions
dblazeskicommented, Aug 16, 2018

What worked for iOS, is calling blur on the existing input before calling focus on the next one. Haven’t tested android yet. This auto-focused inputs that are not viewable. Ex:

<TextInput 
	ref={input => { this.input1 = input}}
	onSubmitEditing={() => { this.input1.blur(); this.input2.focus() }}
	returnKeyType='next'
        blurOnSubmit={false}
/>
<TextInput 
	ref={input => { this.input2 = input}}
        blurOnSubmit={false}
/>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto scroll on tabbing to input leaving it partially hidden
My issue is when tabbing through each element. The tab order is correct, but when reaching the end of a horizontal row, it...
Read more >
How to auto-scroll to a focused TextInput in a ScrollView
In this blog post I'll show you how to auto-scroll to a focused TextInput in a ScrollView . ProblemPermalink. What I'm working on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found