mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 09:17:55 +08:00
Replace ScrollView.scrollTo() API with something less ambiguous.
Summary:
public
The current `ScrollView.scrollTo()` API is confusing due to the `(y, x)` parameter order, and the boolean `animated` argument. E.g.
ScrollView.scrollTo(5, 0, true) // what do these arguments mean?
This diff replaces the API with a configuration object, so the arguments are all explicit:
ScrollView.scrollTo({x: 0, y: 5, animated: true}) // much better
The `scrollTo()` method checks the argument types, and provides backwards compatibility with the old argument format for now. Using the old API will generate a warning, and this will eventually be upgraded to an error.
Reviewed By: davidaurelio
Differential Revision: D2892287
fb-gh-sync-id: cec4d504242391267c6e863816b6180ced7a7d5e
This commit is contained in:
committed by
facebook-github-bot-4
parent
5f4390bf03
commit
6941c4e027
@@ -19,6 +19,8 @@ var React = require('react-native');
|
||||
var {
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
Image
|
||||
} = React;
|
||||
@@ -31,27 +33,45 @@ exports.examples = [
|
||||
title: '<ScrollView>',
|
||||
description: 'To make content scrollable, wrap it within a <ScrollView> component',
|
||||
render: function() {
|
||||
var _scrollView: ScrollView;
|
||||
return (
|
||||
<ScrollView
|
||||
automaticallyAdjustContentInsets={false}
|
||||
onScroll={() => { console.log('onScroll!'); }}
|
||||
scrollEventThrottle={200}
|
||||
style={styles.scrollView}>
|
||||
{THUMBS.map(createThumbRow)}
|
||||
</ScrollView>
|
||||
<View>
|
||||
<ScrollView
|
||||
ref={(scrollView) => { _scrollView = scrollView; }}
|
||||
automaticallyAdjustContentInsets={false}
|
||||
onScroll={() => { console.log('onScroll!'); }}
|
||||
scrollEventThrottle={200}
|
||||
style={styles.scrollView}>
|
||||
{THUMBS.map(createThumbRow)}
|
||||
</ScrollView>
|
||||
<TouchableOpacity
|
||||
style={styles.button}
|
||||
onPress={() => { _scrollView.scrollTo({y: 0}); }}>
|
||||
<Text>Scroll to top</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}, {
|
||||
title: '<ScrollView> (horizontal = true)',
|
||||
description: 'You can display <ScrollView>\'s child components horizontally rather than vertically',
|
||||
render: function() {
|
||||
var _scrollView: ScrollView;
|
||||
return (
|
||||
<ScrollView
|
||||
automaticallyAdjustContentInsets={false}
|
||||
horizontal={true}
|
||||
style={[styles.scrollView, styles.horizontalScrollView]}>
|
||||
{THUMBS.map(createThumbRow)}
|
||||
</ScrollView>
|
||||
<View>
|
||||
<ScrollView
|
||||
ref={(scrollView) => { _scrollView = scrollView; }}
|
||||
automaticallyAdjustContentInsets={false}
|
||||
horizontal={true}
|
||||
style={[styles.scrollView, styles.horizontalScrollView]}>
|
||||
{THUMBS.map(createThumbRow)}
|
||||
</ScrollView>
|
||||
<TouchableOpacity
|
||||
style={styles.button}
|
||||
onPress={() => { _scrollView.scrollTo({x: 0}); }}>
|
||||
<Text>Scroll to start</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}];
|
||||
|
||||
Reference in New Issue
Block a user