mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 23:05:00 +08:00
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:
committed by
facebook-github-bot-4
parent
4511993ffa
commit
0f7477f9f9
@@ -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;
|
||||
|
||||
29
Libraries/Components/ScrollView/processDecelerationRate.js
Normal file
29
Libraries/Components/ScrollView/processDecelerationRate.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule processDecelerationRate
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var ScrollViewConsts = require('UIManager').RCTScrollView.Constants;
|
||||
|
||||
function processDecelerationRate(decelerationRate) {
|
||||
var ScrollViewDecelerationRateNormal = ScrollViewConsts && ScrollViewConsts.DecelerationRate.normal;
|
||||
var ScrollViewDecelerationRateFast = ScrollViewConsts && ScrollViewConsts.DecelerationRate.fast;
|
||||
|
||||
if (typeof decelerationRate === 'string') {
|
||||
if (decelerationRate === 'fast') {
|
||||
return ScrollViewDecelerationRateFast;
|
||||
} else if (decelerationRate === 'normal') {
|
||||
return ScrollViewDecelerationRateNormal;
|
||||
}
|
||||
}
|
||||
return decelerationRate;
|
||||
}
|
||||
|
||||
module.exports = processDecelerationRate;
|
||||
@@ -18,7 +18,9 @@ var StyleSheet = require('StyleSheet');
|
||||
var Text = require('Text');
|
||||
var UIManager = require('UIManager');
|
||||
var View = require('View');
|
||||
var ScrollView = require('ScrollView')
|
||||
|
||||
var processDecelerationRate = require('processDecelerationRate');
|
||||
var invariant = require('invariant');
|
||||
var keyMirror = require('keyMirror');
|
||||
var requireNativeComponent = require('requireNativeComponent');
|
||||
@@ -117,6 +119,17 @@ var WebView = React.createClass({
|
||||
* @platform ios
|
||||
*/
|
||||
bounces: PropTypes.bool,
|
||||
/**
|
||||
* A floating-point number that determines how quickly the scroll view
|
||||
* 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
|
||||
* - Fast: 0.9 (the default for iOS WebView)
|
||||
* @platform ios
|
||||
*/
|
||||
decelerationRate: ScrollView.propTypes.decelerationRate,
|
||||
/**
|
||||
* @platform ios
|
||||
*/
|
||||
@@ -228,6 +241,8 @@ var WebView = React.createClass({
|
||||
domStorageEnabled = this.props.domStorageEnabledAndroid;
|
||||
}
|
||||
|
||||
var decelerationRate = processDecelerationRate(this.props.decelerationRate);
|
||||
|
||||
var webView =
|
||||
<RCTWebView
|
||||
ref={RCT_WEBVIEW_REF}
|
||||
@@ -238,6 +253,7 @@ var WebView = React.createClass({
|
||||
injectedJavaScript={this.props.injectedJavaScript}
|
||||
bounces={this.props.bounces}
|
||||
scrollEnabled={this.props.scrollEnabled}
|
||||
decelerationRate={decelerationRate}
|
||||
contentInset={this.props.contentInset}
|
||||
automaticallyAdjustContentInsets={this.props.automaticallyAdjustContentInsets}
|
||||
onLoadingStart={this.onLoadingStart}
|
||||
|
||||
Reference in New Issue
Block a user