Skip to content

Commit bd8b420

Browse files
committed
1.0.21
修复: 1. iOS刷新修改 2. 安卓刷新修改 3. 在onScroll的时候才改变进度条透明度 4. scrollTo原生端修改成setContentOffset 5. 原声编译版本修改为28 6. 支持tvOS
1 parent 6789d1d commit bd8b420

File tree

6 files changed

+35
-38
lines changed

6 files changed

+35
-38
lines changed

src/SpringScrollView.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,10 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
290290
};
291291

292292
_onKeyboardWillHide = () => {
293-
this._keyboardHeight > 0 && this.scroll({ x: 0, y: -this._keyboardHeight });
293+
if (this._keyboardHeight > 0) {
294+
this.scroll({ x: 0, y: -this._keyboardHeight });
295+
this._keyboardHeight = 0;
296+
}
294297
};
295298

296299
_beginIndicatorDismissAnimation() {
@@ -306,6 +309,7 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
306309
if (!finished) {
307310
this._indicatorOpacity.setValue(1);
308311
}
312+
this._indicatorAnimation = null;
309313
});
310314
}
311315

@@ -325,6 +329,9 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
325329
this.props.onLoading && loadingStatus === "loading" && this.props.onLoading();
326330
}
327331
this.props.onScroll && this.props.onScroll(e);
332+
if (!this._indicatorAnimation) {
333+
this._indicatorOpacity.setValue(1);
334+
}
328335
};
329336

330337
_toRefreshStatus(status: HeaderStatus) {
@@ -493,8 +500,6 @@ export class SpringScrollView extends React.PureComponent<SpringScrollViewPropTy
493500
_onTouchBegin = () => {
494501
if (TextInputState.currentlyFocusedField())
495502
TextInputState.blurTextInput(TextInputState.currentlyFocusedField());
496-
this._indicatorAnimation && this._indicatorAnimation.stop();
497-
this._indicatorOpacity.setValue(1);
498503
this.props.tapToHideKeyboard && Keyboard.dismiss();
499504
this.props.onTouchBegin && this.props.onTouchBegin();
500505
};

src/android/build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
def safeExtGet(prop, fallback) {
2+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
3+
}
14

25
buildscript {
36
repositories {
@@ -12,13 +15,12 @@ buildscript {
1215
apply plugin: 'com.android.library'
1316

1417
android {
15-
compileSdkVersion 26
18+
compileSdkVersion safeExtGet('compileSdkVersion', 26)
19+
publishNonDefault true
1620

1721
defaultConfig {
18-
minSdkVersion 16
19-
targetSdkVersion 26
20-
versionCode 1
21-
versionName "1.0"
22+
minSdkVersion safeExtGet('minSdkVersion', 16)
23+
targetSdkVersion safeExtGet('targetSdkVersion', 26)
2224
}
2325
lintOptions {
2426
abortOnError false

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ public void onAnimationRepeat(Animator animation) {
5858
}
5959

6060
public boolean cancel() {
61-
boolean cancel=this.animating;
61+
boolean cancel = this.animating;
6262
animator.cancel();
6363
return cancel;
6464
}
6565

66-
protected abstract void onEnd();
66+
protected void onEnd() {
67+
}
6768

6869
protected abstract void onUpdate(float value);
6970
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -522,12 +522,9 @@ private void sendEvent(String evtName, WritableMap event) {
522522
public void endRefresh() {
523523
if (!refreshStatus.equals("refreshing")) return;
524524
refreshStatus = "rebound";
525+
if (verticalAnimation != null) verticalAnimation.cancel();
526+
contentInsets.top = 0;
525527
verticalAnimation = new DecelerateAnimation(contentOffset.y, 0, 500) {
526-
@Override
527-
protected void onEnd() {
528-
contentInsets.top = 0;
529-
}
530-
531528
@Override
532529
protected void onUpdate(float value) {
533530
setContentOffset(contentOffset.x, value);
@@ -539,12 +536,9 @@ protected void onUpdate(float value) {
539536
public void endLoading() {
540537
if (!loadingStatus.equals("loading")) return;
541538
loadingStatus = "rebound";
539+
if (verticalAnimation != null) verticalAnimation.cancel();
540+
contentInsets.bottom = 0;
542541
verticalAnimation = new DecelerateAnimation(contentOffset.y, contentSize.height - size.height, 500) {
543-
@Override
544-
protected void onEnd() {
545-
contentInsets.bottom = 0;
546-
}
547-
548542
@Override
549543
protected void onUpdate(float value) {
550544
setContentOffset(contentOffset.x, value);

src/ios/SpringScrollView/STSpringScrollView.m

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
@interface STSpringScrollView ()
1212
@property(nonatomic, assign) float refreshHeaderHeight;
1313
@property(nonatomic, assign) float loadingFooterHeight;
14-
@property(nonatomic, assign) UIEdgeInsets orgInsets;
14+
//@property(nonatomic, assign) UIEdgeInsets orgInsets;
1515
@property(nonatomic, copy) NSString *refreshStatus;
1616
@property(nonatomic, copy) NSString *loadingStatus;
17-
@property(nonatomic, assign) BOOL orgScrollEnabled;
1817
@property(nonatomic, copy) NSDictionary *initialContentOffset;
1918
@property(nonatomic, assign) BOOL allLoaded;
2019
@property(nonatomic, assign) BOOL initialed;
@@ -53,16 +52,17 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
5352
[super scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
5453
if ([self shouldRefresh]) {
5554
self.refreshStatus = @"refreshing";
56-
self.orgInsets = self.scrollView.contentInset;
57-
[self.scrollView setContentInset:UIEdgeInsetsMake(self.orgInsets.top+self.refreshHeaderHeight, self.orgInsets.left, self.orgInsets.bottom, self.orgInsets.right)];
55+
[self.scrollView setContentInset:UIEdgeInsetsMake(self.refreshHeaderHeight, 0, 0, 0)];
5856
} else if ([self shouldLoad]) {
5957
self.loadingStatus = @"loading";
60-
self.orgInsets = self.scrollView.contentInset;
6158
CGFloat fill = .0f;
6259
if(self.scrollView.frame.size.height>self.scrollView.contentSize.height){
6360
fill=self.scrollView.frame.size.height-self.scrollView.contentSize.height;
6461
}
65-
[self.scrollView setContentInset:UIEdgeInsetsMake(self.orgInsets.top, self.orgInsets.left, self.orgInsets.bottom+self.loadingFooterHeight+fill, self.orgInsets.right)];
62+
[self.scrollView setContentInset:UIEdgeInsetsMake(0, 0, self.loadingFooterHeight+fill, 0)];
63+
}
64+
else if ([self hitRefreshStatus:@[@"rebound"]] && !UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, scrollView.contentInset)){
65+
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
6666
}
6767
}
6868

@@ -75,6 +75,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
7575
self.refreshStatus = @"pullingCancel";
7676
} else if ([self shouldWaiting]){
7777
self.refreshStatus = @"waiting";
78+
scrollView.contentInset = UIEdgeInsetsZero;
7879
}
7980
if ([self shouldDragging]) {
8081
self.loadingStatus = @"dragging";
@@ -84,21 +85,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
8485
self.loadingStatus = @"draggingCancel";
8586
} else if ([self shouldFooterWaiting]) {
8687
self.loadingStatus = @"waiting";
88+
scrollView.contentInset = UIEdgeInsetsZero;
8789
}
8890
[super scrollViewDidScroll:scrollView];
8991
}
9092

91-
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
92-
if (!UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, self.orgInsets) && ([self hitRefreshStatus:@[@"waiting"]] || [self hitLoadingStatus:@[@"waiting"]])) {
93-
scrollView.contentInset = self.orgInsets;
94-
}
95-
}
96-
9793
- (void)endRefresh {
9894
if ([self hitRefreshStatus:@[@"refreshing"]]) {
9995
self.refreshStatus = @"rebound";
100-
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
101-
self.orgScrollEnabled = self.scrollView.scrollEnabled;
96+
[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0) animated:YES];
10297
}
10398
}
10499

@@ -126,7 +121,7 @@ - (BOOL) shouldPullingCancel{
126121
}
127122

128123
- (BOOL) shouldWaiting{
129-
return self.refreshHeaderHeight>0 && ([self hitRefreshStatus:@[@"rebound",@"pullingCancel"]]) && self.scrollView.contentOffset.y >=0;
124+
return self.refreshHeaderHeight>0 && ([self hitRefreshStatus:@[@"rebound",@"pullingCancel"]]) && !UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, self.scrollView.contentInset) && self.scrollView.contentOffset.y >=0;
130125
}
131126

132127
- (BOOL) shouldDragging{
@@ -207,8 +202,8 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated{
207202

208203
- (void)setAllLoaded:(BOOL)allLoaded{
209204
self.loadingStatus = allLoaded?@"allLoaded":@"waiting";
210-
if (allLoaded && !UIEdgeInsetsEqualToEdgeInsets(self.orgInsets, self.scrollView.contentInset)) {
211-
[self.scrollView setContentInset:self.orgInsets];
205+
if (allLoaded && !UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsetsZero, self.scrollView.contentInset)) {
206+
[self.scrollView setContentInset:UIEdgeInsetsZero];
212207
}
213208
[self sendScrollEventWithName:@"onScroll" scrollView:self.scrollView userData:@{}];
214209
}

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-spring-scrollview",
3-
"version": "2.0.20",
3+
"version": "2.0.21",
44
"description": "An cross-platform (iOS & Android) spring ScrollView",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)