Skip to content

Commit 78139ef

Browse files
committed
支持decelerationRate
1 parent ede451e commit 78139ef

File tree

8 files changed

+36
-14
lines changed

8 files changed

+36
-14
lines changed

Examples/Test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 石破天惊
33
* @email: shanshang130@gmail.com
44
* @Date: 2021-07-16 17:29:37
5-
* @LastEditTime: 2021-07-27 18:23:18
5+
* @LastEditTime: 2021-07-30 00:10:08
66
* @LastEditors: 石破天惊
77
* @Description:
88
*/
@@ -35,6 +35,7 @@ export class Test extends React.Component {
3535
showsHorizontalScrollIndicator: true,
3636
dragToHideKeyboard: true,
3737
pagingEnabled: false,
38+
decelerationRate: 0.997,
3839
pageSize: { width: 200, height: 200 },
3940
contentStyle: { width: "100%", height: "350%" },
4041

@@ -46,6 +47,7 @@ export class Test extends React.Component {
4647

4748
_contentStyleRef = React.createRef();
4849
_pageSizeRef = React.createRef();
50+
_decelerationRateRef = React.createRef();
4951

5052
render() {
5153
const propertyKeys = Object.keys(this.state).filter(
@@ -68,7 +70,11 @@ export class Test extends React.Component {
6870
<SpringScrollView
6971
{...this.state}
7072
inputToolBarHeight={Platform.select({ ios: 44, android: 200 })}
71-
textInputRefs={[this._contentStyleRef, this._pageSizeRef]}
73+
textInputRefs={[
74+
this._contentStyleRef,
75+
this._pageSizeRef,
76+
this._decelerationRateRef,
77+
]}
7278
ref={(ref) => (this._main = ref)}
7379
onScroll={this._onScroll}
7480
onTouchBegin={this._onTouchBegin}
@@ -94,6 +100,8 @@ export class Test extends React.Component {
94100
let inputRef;
95101
if (key === "contentStyle") inputRef = this._contentStyleRef;
96102
if (key === "pageSize") inputRef = this._pageSizeRef;
103+
if (key === "decelerationRate")
104+
inputRef = this._decelerationRateRef;
97105
return (
98106
<this.Row
99107
key={key}

docs/en/V3/BasicControl.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 石破天惊
33
* @email: shanshang130@gmail.com
44
* @Date: 2021-07-23 23:43:47
5-
* @LastEditTime: 2021-07-24 00:00:31
5+
* @LastEditTime: 2021-07-29 23:42:11
66
* @LastEditors: 石破天惊
77
* @Description:
88
-->
@@ -24,4 +24,5 @@ onSizeChange | ({width:number,height:number})=>any | undefined | The callback wh
2424
onContentSizeChange | ({width:number,height:number})=>any | undefined | The callback when the content view size changed.
2525
inverted | boolean | false | inverted. It is a service for LargeList.
2626
pagingEnabled | boolean | false | When true, the scroll view stops on multiples of `pageSize` when scrolling. This can be used for pagination on both horizontal and vertical directions.
27+
decelerationRate | number | 0.997 | decelerationRate
2728
pageSize | {width:number, height:number} | {width:0,height:0} | Works only when `pagingEnabled=true`, the scroll view stops on multiples of `pageSize` when scrolling. This can be used for pagination on both horizontal and vertical directions。If the width or height set to 0, it will equal to the view port of the SpringScrollView's width or height.

docs/zh-cn/V3/BasicControl.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 石破天惊
33
* @email: shanshang130@gmail.com
44
* @Date: 2021-07-22 10:22:58
5-
* @LastEditTime: 2021-07-23 23:18:42
5+
* @LastEditTime: 2021-07-29 23:41:55
66
* @LastEditors: 石破天惊
77
* @Description:
88
-->
@@ -23,6 +23,7 @@ dragToHideKeyboard | boolean | true | 点击SpringScrollView是否收起键盘
2323
onSizeChange | ({width:number,height:number})=>any | undefined | 外部Wrapper视图宽高变化时回调
2424
onContentSizeChange | ({width:number,height:number})=>any | undefined | 内部ContentView视图宽高变化时回调
2525
inverted | boolean | false | 将SpringScrollView上下翻转,此属性单独意义不大,主要是为了LargeList提供功能
26+
decelerationRate | number | 0.997 | decelerationRate
2627
pagingEnabled | boolean | false | 当值为 true 时,滚动条会停在设置的pageSize整数倍位置。这个属性在iOS和安卓上都支持双向分页。
2728
pageSize | {width:number, height:number} | {width:0,height:0} | 配合pagingEnabled使用分页,使滑动停止在设置的整数倍位置。同时支持水平和垂直双向分页。0代表使用SpringScrollView的视口大小。
2829

src/SpringScrollView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
572572
refreshHeader: NormalHeader,
573573
loadingFooter: NormalFooter,
574574
textInputRefs: [],
575+
decelerationRate: 0.997,
575576
inputToolBarHeight: 44,
576577
dragToHideKeyboard: true,
577578
keyboardShouldPersistTaps: "handled",

src/Types.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
*
3-
* Created by Stone
4-
* https://github.com/bolan9999
5-
* Email: shanshang130@gmail.com
6-
* Date: 2018/7/17
7-
*
2+
* @Author: 石破天惊
3+
* @email: shanshang130@gmail.com
4+
* @Date: 2021-07-21 13:05:32
5+
* @LastEditTime: 2021-07-29 23:34:45
6+
* @LastEditors: 石破天惊
7+
* @Description:
88
*/
99

1010
import {Animated, ViewProps, ViewStyle} from 'react-native';
@@ -51,6 +51,7 @@ export interface SpringScrollViewPropType extends ViewProps {
5151
scrollEnabled?: boolean;
5252
pagingEnabled?: boolean;
5353
pageSize?: Size;
54+
decelerationRate?: number;
5455
directionalLockEnabled?: boolean;
5556
initialContentOffset?: Offset;
5657
showsVerticalScrollIndicator?: boolean;

src/android/src/main/java/com/bolan9999/SpringScrollView.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
import com.facebook.react.views.view.ReactViewGroup;
1919

2020
public class SpringScrollView extends ReactViewGroup implements View.OnLayoutChangeListener, SpringAnimatorListener {
21-
private float refreshHeaderHeight, loadingFooterHeight;
21+
private float refreshHeaderHeight, loadingFooterHeight, decelerationRate;
2222
private boolean momentumScrolling, bounces, scrollEnabled, dragging, inverted,
23-
directionalLockEnabled, pagingEnabled, shouldVerticalRebound;
23+
directionalLockEnabled, pagingEnabled;
2424
private VelocityTracker tracker;
2525
private SpringAnimator verticalAnimation, horizontalAnimation;
2626
private String refreshStatus, loadingStatus, draggingDirection;
@@ -258,12 +258,12 @@ private void onUp(MotionEvent evt) {
258258
sendEvent("onCustomMomentumScrollBegin", null);
259259
}
260260
float maxY = contentSize.height + contentInsets.bottom - size.height;
261-
verticalAnimation.startInner(contentOffset.y, -vy, pagingEnabled ? 0.99f : 0.997f,
261+
verticalAnimation.startInner(contentOffset.y, -vy, pagingEnabled ? 0.99f : decelerationRate,
262262
-contentInsets.top, maxY, pagingEnabled, getPageHeight());
263263

264264
if (contentSize.width <= size.width) return;
265265
float maxX = contentSize.width - size.width + contentInsets.right;
266-
horizontalAnimation.startInner(contentOffset.x, -vx, pagingEnabled ? 0.99f : 0.997f,
266+
horizontalAnimation.startInner(contentOffset.x, -vx, pagingEnabled ? 0.99f : decelerationRate,
267267
-contentInsets.left, maxX, pagingEnabled, getPageWidth());
268268
}
269269

@@ -455,6 +455,10 @@ public void scrollTo(float x, float y, boolean animated) {
455455
}
456456
}
457457

458+
public void setDecelerationRate(float rate){
459+
decelerationRate = rate;
460+
}
461+
458462
public void setBounces(boolean bounces) {
459463
this.bounces = bounces;
460464
}

src/android/src/main/java/com/bolan9999/SpringScrollViewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public void setScrollEnabled(SpringScrollView view, boolean scrollEnabled) {
4949
view.setScrollEnabled(scrollEnabled);
5050
}
5151

52+
@ReactProp(name = "decelerationRate")
53+
public void setDecelerationRate(SpringScrollView view, float decelerationRate) {
54+
view.setDecelerationRate(decelerationRate);
55+
}
56+
5257
@ReactProp(name = "initialContentOffset")
5358
public void setInitContentOffset(SpringScrollView view, ReadableMap offset) {
5459
float x = offset != null ? PixelUtil.toPixelFromDIP(offset.getDouble("x")) : 0;

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ declare module 'react-native-spring-scrollview' {
9393
scrollEnabled?: boolean;
9494
pagingEnabled?: boolean;
9595
pageSize?: Size;
96+
decelerationRate?: number;
9697
directionalLockEnabled?: boolean;
9798
initialContentOffset?: Offset;
9899
showsVerticalScrollIndicator?: boolean;

0 commit comments

Comments
 (0)