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 "Doric.h"
#import "DoricJSDispatcher.h"
@interface DoricRefreshableNode () <DoricSwipePullingDelegate>
@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 {

View File

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

View File

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