iOS: update with js dispatcher

This commit is contained in:
王劲鹏 2021-09-23 11:05:40 +08:00 committed by osborn
parent 73dd78ca05
commit 6e8c5cc8ea
2 changed files with 66 additions and 31 deletions

View File

@ -20,12 +20,15 @@
// Created by jingpeng.wang on 2021/09/17.
//
#import "DoricJSDispatcher.h"
#import "DoricStackNode.h"
NS_ASSUME_NONNULL_BEGIN
@interface DoricGestureContainerNode : DoricStackNode
@property(nonatomic, strong) DoricJSDispatcher *jsDispatcher;
@property(nonatomic, strong) NSString *onTouchDown;
@property(nonatomic, strong) NSString *onTouchMove;
@property(nonatomic, strong) NSString *onTouchUp;

View File

@ -49,7 +49,14 @@ - (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[touches enumerateObjectsUsingBlock:^(UITouch * _Nonnull obj, BOOL * _Nonnull stop) {
if (self.node.onTouchMove) {
CGPoint currentLocation = [obj locationInView:self];
[self.node callJSResponse: self.node.onTouchMove, @(currentLocation.x), @(currentLocation.y), nil];
if (!self.node.jsDispatcher) {
self.node.jsDispatcher = [DoricJSDispatcher new];
}
__weak typeof(self) __self = self;
[self.node.jsDispatcher dispatch:^DoricAsyncResult * {
__strong typeof(__self) self = __self;
return [self.node callJSResponse: self.node.onTouchMove, @(currentLocation.x), @(currentLocation.y), nil];
}];
*stop = YES;
}
}];
@ -151,8 +158,16 @@ -(void)longPressAction:(UILongPressGestureRecognizer *)sender{
}
-(void)pinchAction:(UIPinchGestureRecognizer *)sender{
if (self.onPinch)
[self callJSResponse:self.onPinch, @(sender.scale), nil];
if (self.onPinch) {
if (!self.jsDispatcher) {
self.jsDispatcher = [DoricJSDispatcher new];
}
__weak typeof(self) __self = self;
[self.jsDispatcher dispatch:^DoricAsyncResult * {
__strong typeof(__self) self = __self;
return [self callJSResponse:self.onPinch, @(sender.scale), nil];
}];
}
}
-(void)panAction:(UIPanGestureRecognizer *)sender{
@ -166,8 +181,17 @@ -(void)panAction:(UIPanGestureRecognizer *)sender{
self.startPanLocation = currentLocation;
if (self.onPan)
[self callJSResponse:self.onPan, @(dx), @(dy), nil];
if (self.onPan) {
if (!self.jsDispatcher) {
self.jsDispatcher = [DoricJSDispatcher new];
}
__weak typeof(self) __self = self;
[self.jsDispatcher dispatch:^DoricAsyncResult * {
__strong typeof(__self) self = __self;
return [self callJSResponse:self.onPan, @(dx), @(dy), nil];
}];
}
// detect the swipe gesture
if (sender.state == UIGestureRecognizerStateEnded) {
@ -202,8 +226,16 @@ -(void)rotationAction:(UIRotationGestureRecognizer *)sender{
CGFloat diffRotation = sender.rotation - self.startRotationDegree;
self.startRotationDegree = sender.rotation;
if (self.onRotate)
[self callJSResponse:self.onRotate, @(diffRotation), nil];
if (self.onRotate) {
if (!self.jsDispatcher) {
self.jsDispatcher = [DoricJSDispatcher new];
}
__weak typeof(self) __self = self;
[self.jsDispatcher dispatch:^DoricAsyncResult * {
__strong typeof(__self) self = __self;
return [self callJSResponse:self.onRotate, @(diffRotation), nil];
}];
}
}
- (void)blendView:(UIView *)view forPropName:(NSString *)name propValue:(id)prop {