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.

Doesn't scroll to the right position when a header is before multiple textfields

See original GitHub issue

Hi ! First and foremost, thank you for your great work. I try to make an app with a header at the top of each view. When I try to make the register page, I have to put several TextInputs below the header in a KeyboardAwareScrollView. When I click on a TextField below the Keyboard, the view doesn’t scroll to the right position, my TextField stay below the Keyboard. But when I remove the header, the KeyboardAwareScrollView works as expected.

Here is a gif representing the problem: iphone scrollview bug

My code in index.ios.js:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TextInput,
  Dimensions,
} from 'react-native';

let win = Dimensions.get('window')

import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'

export default class scrollView extends Component {
  render() { return (
    <View style={styles.view}>
      <View style={{height: 200}}>
        <Text style={{marginTop: 20, color: 'white'}}>This is an area I need to put some header</Text>
        <Text style={{marginTop: 100, color: 'white'}}>What can I do ?</Text>
      </View>
    <KeyboardAwareScrollView contentContainerStyle={styles.centered}>
      <Text style={styles.title}>Form</Text>
      <View style={styles.connectTitle}>
        <Text style={styles.connectText}>Connection</Text>
      </View>
      <View style={styles.connectTextInputContainer}>
        <View style={styles.connectTextInputBackground}>
          <TextInput ref={(r) => {this.FirstInput = r;}} placeholder='id'
            style={styles.textInput} onChangeText={this.onChangeTitle}
            returnKeyType={'next'} onSubmitEditing={(event) => {
              this.SecondInput.focus();
            }} />
        </View>
        <View style={styles.connectTextInputBackground}>
          <TextInput ref={(r) => {this.SecondInput = r;}} placeholder='password'
            style={styles.textInput} secureTextEntry={true}
            onChangeText={this.onChangeTitle}
            enablesReturnKeyAutomatically={true} returnKeyType={'send'} />
        </View>
      </View>
      <View style={styles.connectTitle}>
        <Text style={styles.connectText}>Register</Text>
      </View>
      <View style={[styles.connectTextInputBackground,
        styles.registerTextInputBackground]}>
        <TextInput ref={(r) => {this.nom = r;}} placeholder='lastname' style={styles.textInput}
          onChangeText={this.onChangeTitle} returnKeyType={'next'}
          onSubmitEditing={(event) => {
            this.prenom.focus();
          }} />
      </View>
      <View style={[styles.connectTextInputBackground,
        styles.registerTextInputBackground]}>
        <TextInput ref={(r) => {this.prenom = r;}} placeholder='firstname'
          style={styles.textInput} returnKeyType={'next'}
          onSubmitEditing={(event) => {
            this.identifiant.focus();
          }} />
      </View>
      <View style={[styles.connectTextInputBackground,
        styles.registerTextInputBackground]}>
        <TextInput ref={(r) => {this.identifiant = r;}} placeholder='id'
          style={styles.textInput} onChangeText={this.onChangeTitle}
          returnKeyType={'next'} onSubmitEditing={(event) => {
            this.messagerie.focus();
          }} />
      </View>
      <View style={[styles.connectTextInputBackground,
        styles.registerTextInputBackground]}>
        <TextInput ref={(r) => {this.messagerie = r;}} placeholder='mail'
          style={styles.textInput} returnKeyType={'next'}
          onSubmitEditing={(event) => {
            this.password.focus();
          }} />
      </View>
      <View style={[styles.connectTextInputBackground,
        styles.registerTextInputBackground]}>
        <TextInput ref={(r) => {this.password = r;}} placeholder='password'
          secureTextEntry={true} style={styles.textInput}
          enablesReturnKeyAutomatically={true} returnKeyType={'send'}/>
      </View>
    </KeyboardAwareScrollView>
  </View>
  )}
}

const styles = StyleSheet.create({
  centered: {
    alignItems: 'center',
  },
  connectText: {
    color: 'white',
    fontSize: (16 / 360) * win.width,
  },
  connectTitle: {
    justifyContent: 'flex-start',
    marginTop: (18 / 600) * win.height,
    width: (322 / 360) * win.width,
  },
  connectTextInputBackground: {
    alignItems: 'center',
    backgroundColor: 'white',
    borderRadius: 10,
    flexDirection: 'row',
    height: (30 / 600) * win.height,
    marginBottom: (11 / 600) * win.height,
    marginTop: (15 / 600) * win.height,
    width: (154 / 360) * win.width,
  },
  connectTextInputContainer: {
    flexDirection: 'row',
    justifyContent: 'space-between',
    width: (322 / 360) * win.width,
  },
  fourteen: {
    fontSize: (14 / 360) * win.width,
  },
  registerTextInputBackground: {
    marginBottom: 0,
    marginTop: (11 / 600) * win.height,
    width: (322 / 360) * win.width,
  },
  textInput: {
    color: 'black',
    flex: 1,
    fontSize: (16 / 360) * win.width,
    height: (16 / 600) * win.height,
    marginLeft: (15 / 360) * win.width,
    marginTop: (13 / 600) * win.height / 2,
  },
  title: {
    color: 'white',
    fontSize: (18 / 360) * win.width,
  },
  view: {
    backgroundColor: 'black',
    flex: 1,
  },
})

AppRegistry.registerComponent('scrollView', () => scrollView);

° React-Native: 0.39.2 ° Lib: 0.2.4

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
reut-cocommented, Mar 18, 2017

I also encountered a weird bug:

  1. when I focused on the first textInput everything works fine screen shot 2017-03-18 at 1 23 32 pm

  2. and then right after clicking on the first test input I clicked on the third test2 input and that what happened: screen shot 2017-03-18 at 1 23 51 pm

the result is that there is an unwanted space on the top of the screen.

2reactions
alvarombcommented, Dec 15, 2016

Hi @avencat!

Thanks for your detailed issue! This is definitely a weird issue, because having the upper headers is probably making the scroll unusable for some fields. I would try two things, first of all use the extraScrollHeight prop of the KeyboardAwareScrollView and set the prop as the height of your headers. If that’s not working, my suggestion is that you add both headers inside the scroll view, that would definitely work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixed persistent header and scroll to focussed input fields
The good: The fixed header does not change position/height when tapping the fields. The bad: The user cannot see the focussed field without...
Read more >
Freeze panes to lock rows and columns - Microsoft Support
How to freeze panes in Excel to keep rows or columns in your worksheet visible while you scroll, or lock them in place...
Read more >
Scroll-Then-Fix Content - CSS-Tricks
Search bar in its fixed header position. We toggle between them simply by changing a class name. There is no trickery with having...
Read more >
Freeze or Lock Specific Rows and Columns when Scrolling in ...
Prevent specific rows or columns from moving when you scroll through a spreadsheet in Excel This allows you to keep header rows and...
Read more >
overscroll-behavior - CSS: Cascading Style Sheets | MDN
If you have overscroll-behavior: contain; selected, the outer container will not scroll unless you move your cursor out of the inner container ...
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