Thirumal Sakthivel
Thirumal Sakthivel

Reputation: 188

How to find the bottom position of the ScrollView for Android in React Native

How to find the ScrollView bottom position value in React Native for android. My requirement is while loading the page, scroll position have to show in bottom of the page.

Upvotes: 0

Views: 644

Answers (1)

G. Hamaide
G. Hamaide

Reputation: 7106

You can do this in the following way : it'll give you the height of the ScrollView.

onContentSizeChange = (width, height) => {
  console.log('scrollview width : ' + width);
  console.log('scrollview height : ' + height);
};

render () {
  return (
    <ScrollView style={{height: Dimensions.get('window').height, backgroundColor: '#DDDDDD'}} onContentSizeChange={this.onContentSizeChange}>
      {_.map([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], (number) => {
        return <Text key={number} style={{textAlign: 'center', paddingTop: 30, paddingBottom: 30, backgroundColor: number % 2 ? 'red' : 'blue'}}>{number}</Text>;
      })}
    </ScrollView>
  );
};

I've set up a working example here.

Upvotes: 1

Related Questions