Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Fix after very quick refresh, scroller cannot stay at 0 point p…
Browse files Browse the repository at this point in the history
…roblem.
  • Loading branch information
wqyfavor committed Apr 8, 2019
1 parent f466641 commit 5dbb79e
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ios/sdk/WeexSDK/Sources/Component/WXRefreshComponent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#import "WXComponent+Layout.h"

@interface WXRefreshComponent()
{
NSTimeInterval _refreshStateTriggerTime;
}

@property (nonatomic) BOOL displayState;
@property (nonatomic) BOOL initFinished;
Expand Down Expand Up @@ -177,12 +180,23 @@ - (void)setDisplay
}
[_indicator start];
[scrollerProtocol setContentOffset:offset animated:YES];
_refreshStateTriggerTime = CFAbsoluteTimeGetCurrent();
} else {
offset.y = 0;
[_indicator stop];
[UIView animateWithDuration:0.25 animations:^{
[scrollerProtocol setContentOffset:offset];
}];
if (CFAbsoluteTimeGetCurrent() - _refreshStateTriggerTime < 0.3) {
/* If javascript doesn't do any refreshing and only update 'display' attribute very quickly.
The previous '[scrollerProtocol setContentOffset:offset animated:YES];' is not finished,
we should also use '[scrollerProtocol setContentOffset:offset animated:YES]' to restore offset.
Or the scroller will not stop at 0.
*/
[scrollerProtocol setContentOffset:offset animated:YES];
}
else {
[UIView animateWithDuration:0.25 animations:^{
[scrollerProtocol setContentOffset:offset];
}];
}
}

/* If we are adding elements while refreshing, like this demo:http://dotwe.org/vue/f541ed72a121db8447a233b777003e8a
Expand Down

0 comments on commit 5dbb79e

Please sign in to comment.