iOS: add js dispatcher for refresh widget

This commit is contained in:
王劲鹏 2023-03-15 11:08:28 +08:00 committed by osborn
parent aa844407b4
commit 2817be24ec
3 changed files with 19 additions and 3 deletions

View File

@ -19,16 +19,20 @@
#import "DoricRefreshableNode.h" #import "DoricRefreshableNode.h"
#import "Doric.h" #import "Doric.h"
#import "DoricJSDispatcher.h"
@interface DoricRefreshableNode () <DoricSwipePullingDelegate> @interface DoricRefreshableNode () <DoricSwipePullingDelegate>
@property(nonatomic, strong) DoricViewNode *contentNode; @property(nonatomic, strong) DoricViewNode *contentNode;
@property(nonatomic, copy) NSString *contentViewId; @property(nonatomic, copy) NSString *contentViewId;
@property(nonatomic, strong) DoricViewNode *headerNode; @property(nonatomic, strong) DoricViewNode *headerNode;
@property(nonatomic, copy) NSString *headerViewId; @property(nonatomic, copy) NSString *headerViewId;
@property(nonatomic, strong) DoricJSDispatcher *jsDispatcher;
@end @end
@implementation DoricRefreshableNode @implementation DoricRefreshableNode
- (DoricSwipeRefreshLayout *)build { - (DoricSwipeRefreshLayout *)build {
self.jsDispatcher = [DoricJSDispatcher new];
return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) { return [[DoricSwipeRefreshLayout new] also:^(DoricSwipeRefreshLayout *it) {
it.swipePullingDelegate = self; it.swipePullingDelegate = self;
}]; }];
@ -152,15 +156,21 @@ - (void)blendSubNode:(NSDictionary *)subModel {
} }
- (void)startAnimation { - (void)startAnimation {
[self.jsDispatcher clear];
[self.headerNode callJSResponse:@"startAnimation", nil]; [self.headerNode callJSResponse:@"startAnimation", nil];
} }
- (void)stopAnimation { - (void)stopAnimation {
[self.jsDispatcher clear];
[self.headerNode callJSResponse:@"stopAnimation", nil]; [self.headerNode callJSResponse:@"stopAnimation", nil];
} }
- (void)setPullingDistance:(CGFloat)distance { - (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 { - (void)setRefreshing:(NSNumber *)refreshable withPromise:(DoricPromise *)promise {

View File

@ -22,4 +22,6 @@
@interface DoricJSDispatcher : NSObject @interface DoricJSDispatcher : NSObject
- (void)dispatch:(DoricAsyncResult *(^)(void))block; - (void)dispatch:(DoricAsyncResult *(^)(void))block;
- (void)clear;
@end @end

View File

@ -56,4 +56,8 @@ - (void)consume {
self.consuming = NO; self.consuming = NO;
} }
} }
- (void)clear {
[self.blocks removeAllObjects];
}
@end @end