ScrollView how can i scroll to the bottom
Compute the y offset from the content size and viewport size, and call scrollTo.
but i can i get viewport size and content size ?
Look in the source code to learn how the UIManager.measureX methods are used. You can measure the scroll view and its content view. If you are using a ListView you will need to write your own ListView that measures the height of every single row to compute the content size.
Where do you call the scrollTo method?
@bdeezz, something like:
render() {
return <ScrollView ref="scrollView" />;
}
onSomeEvent() {
this.refs.scrollView.scrollTo(0); // will scroll to the top at y-position 0
}
@wangzhe1995 Scroll to bottom of ScrollView in React Native see this .
I came up with this solution.
there is a component for listView to scroll to top, hope it is uesful to someone: scrolltotop
One way is to perform a transform on the ScrollView and the inner elements.
This allows you to to use the scrollTo(0) function
<View ref="container"
style={{transform: [{rotate: '180deg'}] }} >
>
<ScrollView/>
</View>
Try this out: https://github.com/fritx/react-native-auto-scroll
Works fine with both iOS and Android (with adjustResize config'd).
// android/app/src/main/AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
+ android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">

Try this:
<ScrollView ref="scrollView"
onContentSizeChange={(width,height) => this.refs.scrollView.scrollTo({y:height})}>
</ScrollView>
@VladPolynko this seems to work fine for me on Android, but on iOS it scrolls below the ScrollView content (as if there was no lower boundary for the ScrollView) (RN 0.38.0)
Same issue than @septemptus
Same issue as @septemptus
ScrollView in iOS has no lower boundary and gives a bigger height.
My shortcut is to give a manual offset for iOS-only.
scrolltoend method still scrolls past the end of the ScrollView on IOS.
onSomeEvent = () => { This worksssss
this.scrollView.scrollTo({ x: 0});
}
Most helpful comment
Try this: