-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve interop touches by using UIScrollView-like strategy #1440
Changes from 16 commits
2e7f94e
0df0c23
8b0a412
200df35
f4f0ebd
3554031
0f6c275
5740501
f286942
c0e22b8
f5bfacc
b5b672d
f97fc46
1678443
3a08659
733fb01
40d8d03
288b3f9
82dde9f
cc88ed0
d5caf40
9c9fa41
f2ebb8f
325473f
65338d0
65b8397
ced8856
7d59be2
db4cc40
ac5a031
92ea0a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,82 +7,110 @@ | |
|
||
#import "CMPGestureRecognizer.h" | ||
|
||
@implementation CMPGestureRecognizer | ||
@implementation CMPGestureRecognizer { | ||
dispatch_block_t _scheduledFailureBlock; | ||
} | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
|
||
if (self) { | ||
self.cancelsTouchesInView = false; | ||
if (self) { | ||
self.delegate = self; | ||
[self addTarget:self action:@selector(handleStateChange)]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | ||
id <CMPGestureRecognizerHandler> handler = self.handler; | ||
- (void)handleStateChange { | ||
switch (self.state) { | ||
case UIGestureRecognizerStateBegan: | ||
NSLog(@"state = Began"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems like logs should be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed |
||
break; | ||
|
||
case UIGestureRecognizerStateChanged: | ||
NSLog(@"state = Changed"); | ||
break; | ||
|
||
case UIGestureRecognizerStateEnded: | ||
[self cancelFailure]; | ||
break; | ||
|
||
case UIGestureRecognizerStateCancelled: | ||
[self cancelFailure]; | ||
break; | ||
elijah-semyonov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (BOOL)shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | ||
UIView *view = self.view; | ||
UIView *otherView = otherGestureRecognizer.view; | ||
|
||
if (handler) { | ||
return [handler shouldRecognizeSimultaneously:gestureRecognizer withOther:otherGestureRecognizer]; | ||
} else { | ||
if (view == nil || otherView == nil) { | ||
return NO; | ||
} | ||
|
||
if ([otherView isDescendantOfView:view]) { | ||
return NO; | ||
} else { | ||
return YES; | ||
} | ||
} | ||
|
||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
[self.handler touchesBegan:touches withEvent:event]; | ||
- (BOOL)shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | ||
return NO; | ||
} | ||
|
||
- (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | ||
return YES; | ||
} | ||
|
||
- (void)cancelFailure { | ||
if (_scheduledFailureBlock) { | ||
dispatch_block_cancel(_scheduledFailureBlock); | ||
_scheduledFailureBlock = NULL; | ||
} | ||
} | ||
|
||
- (void)fail { | ||
[self.handler onFailure]; | ||
} | ||
|
||
- (void)scheduleFailure { | ||
__weak typeof(self) weakSelf = self; | ||
dispatch_block_t dispatchBlock = dispatch_block_create(0, ^{ | ||
[weakSelf fail]; | ||
}); | ||
|
||
if (self.state == UIGestureRecognizerStatePossible) { | ||
self.state = UIGestureRecognizerStateBegan; | ||
if (_scheduledFailureBlock) { | ||
dispatch_block_cancel(_scheduledFailureBlock); | ||
} | ||
_scheduledFailureBlock = dispatchBlock; | ||
|
||
// Calculate the delay time in dispatch_time_t | ||
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to a local variable with an explanation |
||
|
||
// Schedule the block to be executed after the delay on the main queue | ||
dispatch_after(delay, dispatch_get_main_queue(), dispatchBlock); | ||
} | ||
|
||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
[self.handler touchesBegan:touches withEvent:event]; | ||
} | ||
|
||
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
[self.handler touchesMoved:touches withEvent:event]; | ||
|
||
switch (self.state) { | ||
case UIGestureRecognizerStateBegan: | ||
case UIGestureRecognizerStateChanged: | ||
self.state = UIGestureRecognizerStateChanged; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
[self.handler touchesEnded:touches withEvent:event]; | ||
|
||
switch (self.state) { | ||
case UIGestureRecognizerStateBegan: | ||
case UIGestureRecognizerStateChanged: | ||
if (self.numberOfTouches == 0) { | ||
self.state = UIGestureRecognizerStateEnded; | ||
} else { | ||
self.state = UIGestureRecognizerStateChanged; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { | ||
[self.handler touchesCancelled:touches withEvent:event]; | ||
|
||
switch (self.state) { | ||
case UIGestureRecognizerStateBegan: | ||
case UIGestureRecognizerStateChanged: | ||
if (self.numberOfTouches == 0) { | ||
self.state = UIGestureRecognizerStateCancelled; | ||
} else { | ||
self.state = UIGestureRecognizerStateChanged; | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sry, it looks like here some formatting issues with spaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed