[add] ScrollView: support scrollToEnd method

Close #541
This commit is contained in:
Jiaming
2017-06-23 11:59:23 -07:00
committed by Nicolas Gallagher
parent 535a7b7027
commit 18d60047d2
+19
View File
@@ -100,6 +100,25 @@ const ScrollView = createReactClass({
});
},
/**
* If this is a vertical ScrollView scrolls to the bottom.
* If this is a horizontal ScrollView scrolls to the right.
*
* Use `scrollToEnd({ animated: true })` for smooth animated scrolling,
* `scrollToEnd({ animated: false })` for immediate scrolling.
* If no options are passed, `animated` defaults to true.
*/
scrollToEnd(options?: { animated?: boolean }) {
// Default to true
const animated = (options && options.animated) !== false;
const { horizontal } = this.props;
const scrollResponder = this.getScrollResponder();
const scrollResponderNode = scrollResponder.scrollResponderGetScrollableNode();
const x = horizontal ? scrollResponderNode.scrollWidth : 0;
const y = horizontal ? 0 : scrollResponderNode.scrollHeight;
scrollResponder.scrollResponderScrollTo({ x, y, animated });
},
/**
* Deprecated, do not use.
*/