diff --git a/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m b/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m index 18c2a31f..dcd82f07 100644 --- a/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m +++ b/doric-iOS/Pod/Classes/Refresh/DoricRefreshableNode.m @@ -19,16 +19,20 @@ #import "DoricRefreshableNode.h" #import "Doric.h" +#import "DoricJSDispatcher.h" @interface DoricRefreshableNode () @property(nonatomic, strong) DoricViewNode *contentNode; @property(nonatomic, copy) NSString *contentViewId; @property(nonatomic, strong) DoricViewNode *headerNode; @property(nonatomic, copy) NSString *headerViewId; + +@property(nonatomic, strong) DoricJSDispatcher *jsDispatcher; @end @implementation DoricRefreshableNode - (DoricSwipeRefreshLayout *)build { + self.jsDispatcher = [DoricJSDispatcher new]; return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) { it.swipePullingDelegate = self; }]; @@ -152,15 +156,21 @@ - (void)blendSubNode:(NSDictionary *)subModel { } - (void)startAnimation { + [self.jsDispatcher clear]; [self.headerNode callJSResponse:@"startAnimation", nil]; } - (void)stopAnimation { + [self.jsDispatcher clear]; [self.headerNode callJSResponse:@"stopAnimation", nil]; } - (void)setPullingDistance:(CGFloat)distance { - [self.headerNode callJSResponse:@"setPullingDistance", @(distance), nil]; + __weak typeof(self) __self = self; + [self.jsDispatcher dispatch:^DoricAsyncResult * { + __strong typeof(__self) self = __self; + return [self.headerNode callJSResponse:@"setPullingDistance", @(distance), nil]; + }]; } - (void)setRefreshing:(NSNumber *)refreshable withPromise:(DoricPromise *)promise { diff --git a/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.h b/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.h index 96c408dd..507d74cf 100644 --- a/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.h +++ b/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.h @@ -22,4 +22,6 @@ @interface DoricJSDispatcher : NSObject - (void)dispatch:(DoricAsyncResult *(^)(void))block; -@end \ No newline at end of file + +- (void)clear; +@end diff --git a/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.m b/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.m index 899a96f1..2d2620f4 100644 --- a/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.m +++ b/doric-iOS/Pod/Classes/Util/DoricJSDispatcher.m @@ -56,4 +56,8 @@ - (void)consume { self.consuming = NO; } } -@end \ No newline at end of file + +- (void)clear { + [self.blocks removeAllObjects]; +} +@end