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

Commit 5dbb79e

Browse files
author
wqyfavor
committed
[iOS] Fix after very quick refresh, scroller cannot stay at 0 point problem.
1 parent f466641 commit 5dbb79e

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

ios/sdk/WeexSDK/Sources/Component/WXRefreshComponent.mm

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#import "WXComponent+Layout.h"
2626

2727
@interface WXRefreshComponent()
28+
{
29+
NSTimeInterval _refreshStateTriggerTime;
30+
}
2831

2932
@property (nonatomic) BOOL displayState;
3033
@property (nonatomic) BOOL initFinished;
@@ -177,12 +180,23 @@ - (void)setDisplay
177180
}
178181
[_indicator start];
179182
[scrollerProtocol setContentOffset:offset animated:YES];
183+
_refreshStateTriggerTime = CFAbsoluteTimeGetCurrent();
180184
} else {
181185
offset.y = 0;
182186
[_indicator stop];
183-
[UIView animateWithDuration:0.25 animations:^{
184-
[scrollerProtocol setContentOffset:offset];
185-
}];
187+
if (CFAbsoluteTimeGetCurrent() - _refreshStateTriggerTime < 0.3) {
188+
/* If javascript doesn't do any refreshing and only update 'display' attribute very quickly.
189+
The previous '[scrollerProtocol setContentOffset:offset animated:YES];' is not finished,
190+
we should also use '[scrollerProtocol setContentOffset:offset animated:YES]' to restore offset.
191+
Or the scroller will not stop at 0.
192+
*/
193+
[scrollerProtocol setContentOffset:offset animated:YES];
194+
}
195+
else {
196+
[UIView animateWithDuration:0.25 animations:^{
197+
[scrollerProtocol setContentOffset:offset];
198+
}];
199+
}
186200
}
187201

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

0 commit comments

Comments
 (0)