Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN-iOS: ScrollView holds onto current offset on rotation #13566

Closed
kpink224 opened this issue Apr 18, 2017 · 2 comments
Closed

RN-iOS: ScrollView holds onto current offset on rotation #13566

kpink224 opened this issue Apr 18, 2017 · 2 comments
Assignees
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.

Comments

@kpink224
Copy link
Contributor

kpink224 commented Apr 18, 2017

ScrollView holds onto current offset on rotation causing the content to not scroll to end if needed.

Steps to Reproduce

  • make a project with the code below
  • scroll to the end in portrait
  • Rotate the screen from portrait (It happens occasionally)

Result

The content in the scroll view doesn't format to the end of the scrollview

Expected Behavior

The content should be scrolled to the end of the scroll view.

Image

screen shot 2017-04-18 at 4 00 26 pm

CODE

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  ScrollView,
  View
} from 'react-native';

export default class ScrollBug extends Component {
  render() {
    return (
      <View style={styles.container}>
        <ScrollView
        style={styles.scrollContainer}
        alwaysBounceHorizontal={false}
        showsHorizontalScrollIndicator={false}
        horizontal={true}
        decelerationRate={0}
        snapToAlignment="start">
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
          <View style={styles.item}/>
        </ScrollView>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    paddingTop: 44,
    backgroundColor: '#ecf0f1',
  },
  scrollContainer: {
    flexDirection: 'row',
    flex: 1
  },

  item: {
    width: 200,
    height: 200,
    backgroundColor: '#00ee88',
    borderColor: '#990077',
    borderWidth: 10
  }
});

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

Additional Information

  • React Native version: 0.43.3
  • Platform: iOS only
  • Development Operating System: MacOS
@TLenahan
Copy link

TLenahan commented May 3, 2017

I have the same issue, but when the ScrollView is vertical scrolling

I have modified @kpink224's code to demonstrate the issue when vertical scrolling:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  ScrollView,
  View,
} from 'react-native';

export default class ScrollBug extends Component {
  render() {
    return (
      <View style={styles.container}>
        <ScrollView >
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
          <View style={styles.item} />
        </ScrollView>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flexGrow: 1,
  },
  item: {
    height: 100,
    backgroundColor: 'red',
    borderColor: 'blue',
    borderWidth: 10,
  },
});

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

screen shot 2017-05-03 at 1 53 04 pm

@shergin shergin self-assigned this May 28, 2017
@shergin shergin added the Platform: iOS iOS applications. label May 28, 2017
facebook-github-bot pushed a commit that referenced this issue Jul 18, 2017
Summary:
Previous `contentOffset` can be invalid for a new layout and overscroll the ScrollView, so the diff fixes that.
Also documented here: #13566

Reviewed By: mmmulani

Differential Revision: D5414442

fbshipit-source-id: 7de1b4a4571108a37d1795e80f165bca5aba5fef
@kpink224
Copy link
Contributor Author

@shergin fixed it!

@facebook facebook locked as resolved and limited conversation to collaborators Jul 27, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Platform: iOS iOS applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants