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

[IOS]ScrollView does not scroll to correct position after updating contentOffset, children and its height at the same time #26403

Closed
plusice opened this issue Sep 11, 2019 · 3 comments
Labels
Bug Component: ScrollView Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@plusice
Copy link

plusice commented Sep 11, 2019

There is a horizontal ScrollView which height and content may change. When I shorten the height and make the content wider, I update the contentOffset expecting the ScrollView scroll to the correct position. But it only works occasionally

React Native version:

info Fetching system and libraries information...
System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    Memory: 146.34 MB / 8.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.0/bin/npm
    Watchman: 3.1.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    Android SDK:
      API Levels: 22, 23, 25, 26, 28
      Build Tools: 23.0.2, 25.0.1, 25.0.3, 26.0.2, 28.0.3
      System Images: android-21 | ARM EABI v7a, android-22 | Google APIs Intel x86 Atom_64, android-26 | Google Play Intel x86 Atom
      Android NDK: 15.2.4203891
  IDEs:
    Android Studio: 2.3 AI-162.4069837
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6 
    react-native: 0.60 => 0.60.5 
  npmGlobalPackages:
    react-native-cli: 2.0.1

Steps To Reproduce

Here is the code to reproduce:

import * as React from 'react'
import { View, TouchableOpacity, Text, ScrollView } from 'react-native'

export default class Calendars extends React.Component<{}, {
    current: number
    scrollList: number[]
}> {

  constructor(props) {
    super(props)
    this.state = {
      current: 1,
      scrollList: [1, 2, 3]
    }
  }

  render() {
    return (
      <View style={{paddingTop: 50}}>
        <View style={{height: 400 / this.state.current}} >
          {/* <View style={{height: 100}}> */}
          <ScrollView horizontal={true} style={{flex: 1}} contentOffset={{x: this.state.current * 375, y: 0}}>
          {
            this.state.scrollList.map(item => {
              return (
                <View style={{width: 375, height: 100}} key={item}><Text>{'test' + item}</Text></View>
              )
            })
          }
          </ScrollView>
        </View>
        <TouchableOpacity onPress={() => {this.setState({
          current: 4,
          scrollList: [1, 2, 3, 4, 5]
        })}}>
          <Text>change</Text>
        </TouchableOpacity>
      </View>
    )
  }

}

As the code above, after pressing "change" , the ScrollView should scroll to "test5", but sometimes it scroll to "test3":

Describe what you expected to happen:

ScrollView always scroll to correct position after updating contentOffset

@plusice
Copy link
Author

plusice commented Sep 12, 2019

And it works all the way only if the height remain unchanged

@stale
Copy link

stale bot commented Dec 11, 2019

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 11, 2019
@stale
Copy link

stale bot commented Dec 18, 2019

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Dec 18, 2019
@facebook facebook locked as resolved and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Component: ScrollView Platform: iOS iOS applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

2 participants