iOS: add js dispatcher for refresh widget
This commit is contained in:
parent
aa844407b4
commit
2817be24ec
@ -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 {
|
||||
|
@ -22,4 +22,6 @@
|
||||
|
||||
@interface DoricJSDispatcher : NSObject
|
||||
- (void)dispatch:(DoricAsyncResult *(^)(void))block;
|
||||
@end
|
||||
|
||||
- (void)clear;
|
||||
@end
|
||||
|
@ -56,4 +56,8 @@ - (void)consume {
|
||||
self.consuming = NO;
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
- (void)clear {
|
||||
[self.blocks removeAllObjects];
|
||||
}
|
||||
@end
|
||||
|
Reference in New Issue
Block a user