Skip to content

Commit

Permalink
[iOS]fix touch event conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jianhan-he committed Aug 20, 2020
1 parent 9c40045 commit 6b99ced
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ios/sdk/WeexSDK/Sources/Events/WXComponent+Events.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ @interface WXTouchGestureRecognizer : UIGestureRecognizer
@property (nonatomic, assign) BOOL listenTouchEnd;
@property (nonatomic, assign) BOOL listenTouchCancel;
@property (nonatomic, assign) BOOL listenPseudoTouch;
@property (nonatomic, assign) NSInteger activeTouches;

- (instancetype)initWithComponent:(WXComponent *)component NS_DESIGNATED_INITIALIZER;

Expand Down Expand Up @@ -914,6 +915,7 @@ - (instancetype)initWithComponent:(WXComponent *)component
_listenTouchEnd = NO;
_listenTouchMove = NO;
_listenTouchCancel = NO;
_activeTouches = 0;

self.cancelsTouchesInView = NO;
}
Expand All @@ -933,6 +935,10 @@ - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
[_component updatePseudoClassStyles:styles];
}

_activeTouches += [touches count];
if (_activeTouches > (NSInteger)[event.allTouches count]) {
_activeTouches = [event.allTouches count];
}
}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
Expand All @@ -956,6 +962,11 @@ - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
[self recoveryPseudoStyles:_component.styles];
}

_activeTouches -= [touches count];
if (_activeTouches <= 0) {
self.state = UIGestureRecognizerStateEnded;
_activeTouches = 0;
}
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
Expand All @@ -968,6 +979,12 @@ - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
if(_listenPseudoTouch) {
[self recoveryPseudoStyles:_component.styles];
}

_activeTouches -= [touches count];
if (_activeTouches <= 0) {
self.state = UIGestureRecognizerStateEnded;
_activeTouches = 0;
}
}

- (void)fireTouchEvent:(NSString *)eventName withTouches:(NSSet<UITouch *> *)touches
Expand Down

0 comments on commit 6b99ced

Please sign in to comment.