add flag to enable momentum scrolling on iOS

Summary:
Expose a `decelerationNormalEnabled` flag on WebView, which, when enabled, will WebView's ScrollView's `decelerationRate` to `UIScrollViewDecelerationRateNormal`. This gives the WebView the same "momentum" style scrolling as other iOS views.

This was discussed with ide in #5447. Please let me know if there's anything I'm missing, or anything else you'd like to see in this pull request.
Closes https://github.com/facebook/react-native/pull/5527

Reviewed By: svcscm

Differential Revision: D2870312

Pulled By: nicklockwood

fb-gh-sync-id: 7dbfd06a349e3365a5df40c3bacf25a4fdb306cf
This commit is contained in:
August Flanagan
2016-01-28 05:35:14 -08:00
committed by facebook-github-bot-4
parent 4511993ffa
commit 0f7477f9f9
6 changed files with 62 additions and 11 deletions

View File

@@ -32,7 +32,7 @@ var invariant = require('invariant');
var pointsDiffer = require('pointsDiffer');
var requireNativeComponent = require('requireNativeComponent');
var processColor = require('processColor');
var processDecelerationRate = require('processDecelerationRate');
var PropTypes = React.PropTypes;
var SCROLLVIEW = 'ScrollView';
@@ -130,12 +130,18 @@ var ScrollView = React.createClass({
contentContainerStyle: StyleSheetPropType(ViewStylePropTypes),
/**
* A floating-point number that determines how quickly the scroll view
* decelerates after the user lifts their finger. Reasonable choices include
* decelerates after the user lifts their finger. You may also use string
* shortcuts `"normal"` and `"fast"` which match the underlying iOS settings
* for `UIScrollViewDecelerationRateNormal` and
* `UIScrollViewDecelerationRateFast` respectively.
* - Normal: 0.998 (the default)
* - Fast: 0.9
* @platform ios
*/
decelerationRate: PropTypes.number,
decelerationRate: PropTypes.oneOfType([
PropTypes.oneOf(['fast', 'normal']),
PropTypes.number,
]),
/**
* When true, the scroll view's children are arranged horizontally in a row
* instead of vertically in a column. The default value is false.
@@ -465,6 +471,11 @@ var ScrollView = React.createClass({
function() { onRefreshStart && onRefreshStart(this.endRefreshing); }.bind(this);
}
var { decelerationRate } = this.props;
if (decelerationRate) {
props.decelerationRate = processDecelerationRate(decelerationRate);
}
var ScrollViewClass;
if (Platform.OS === 'ios') {
ScrollViewClass = RCTScrollView;