-
Notifications
You must be signed in to change notification settings - Fork 912
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
Add support for swiping from the specified edge of the screen #1286
Changes from all commits
29b6746
ebf5a0a
f582ccd
26b1a96
d07657e
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 |
---|---|---|
|
@@ -636,6 +636,27 @@ - (void)dragFromPoint:(CGPoint)startPoint displacement:(KIFDisplacement)displace | |
[self dragPointsAlongPaths:@[path]]; | ||
} | ||
|
||
- (void)dragFromEdge:(UIRectEdge)startEdge toEdge:(UIRectEdge)endEdge | ||
{ | ||
CGFloat width = self.bounds.size.width; | ||
CGFloat height = self.bounds.size.height; | ||
CGFloat edgeInset = 0.5; | ||
NSDictionary *edgeToPoint = @{ | ||
@(UIRectEdgeTop): @(CGPointMake(width / 2, edgeInset)), | ||
@(UIRectEdgeLeft): @(CGPointMake(edgeInset, height / 2)), | ||
@(UIRectEdgeBottom): @(CGPointMake(width / 2, height - edgeInset)), | ||
@(UIRectEdgeRight): @(CGPointMake(width - edgeInset, height / 2)), | ||
}; | ||
CGPoint startPoint = [edgeToPoint[@(startEdge)] CGPointValue]; | ||
CGPoint endPoint = [edgeToPoint[@(endEdge)] CGPointValue]; | ||
|
||
CGPoint screenPoint = [self convertPoint:startPoint toView:self.window]; | ||
BOOL isFromScreenEdge = (screenPoint.x < 1 || screenPoint.x > self.window.bounds.size.width - 1); | ||
|
||
NSArray<NSValue *> *path = [self pointsFromStartPoint:startPoint toPoint:endPoint steps:20]; | ||
[self dragPointsAlongPaths:@[path] isFromEdge:isFromScreenEdge]; | ||
} | ||
|
||
- (void)dragAlongPathWithPoints:(CGPoint *)points count:(NSInteger)count; | ||
{ | ||
// convert point array into NSArray with NSValue | ||
|
@@ -648,6 +669,10 @@ - (void)dragAlongPathWithPoints:(CGPoint *)points count:(NSInteger)count; | |
} | ||
|
||
- (void)dragPointsAlongPaths:(NSArray<NSArray<NSValue *> *> *)arrayOfPaths { | ||
[self dragPointsAlongPaths:arrayOfPaths isFromEdge:NO]; | ||
} | ||
|
||
- (void)dragPointsAlongPaths:(NSArray<NSArray<NSValue *> *> *)arrayOfPaths isFromEdge:(BOOL)isFromEdge { | ||
// There must be at least one path with at least one point | ||
if (arrayOfPaths.count == 0 || arrayOfPaths.firstObject.count == 0) | ||
{ | ||
|
@@ -692,6 +717,7 @@ - (void)dragPointsAlongPaths:(NSArray<NSArray<NSValue *> *> *)arrayOfPaths { | |
point = [self convertPoint:point fromView:self.window]; | ||
UITouch *touch = [[UITouch alloc] initAtPoint:point inView:self]; | ||
[touch setPhaseAndUpdateTimestamp:UITouchPhaseBegan]; | ||
[touch setIsFromEdge:isFromEdge]; | ||
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. I wonder if we should alternatively come up with a heuristic here for what constitutes an edge swipe and do it implicitly. Being explicit seems reasonable as well though. 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. I think with this we can make an API specifically for swiping at an edge, similarly to like tapping on a button or status bar instead of using x,y coordinatotes. As well as implicitly doing it from the edge if we can detect it being around where it should be. I think that'd be in line with other APIs of KIf 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. I thought about doing it implicitly like
But this could be a breaking change for users who utilize the 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. I have tried to implement an alternative way based on the suggestions, which one do you prefer? |
||
[touches addObject:touch]; | ||
} | ||
UIEvent *eventDown = [self eventWithTouches:[NSArray arrayWithArray:touches]]; | ||
|
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.
What would happen if we directly called
_UITouchSetBasicTouchPropertiesFromEvent
? Does Apple already have the appropriate heuristics to set this properly?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.
Apple derives the value of the property from the HIDEvent. We would need to synthesize a different HIDEvent for edge pan before calling
_UITouchSetBasicTouchPropertiesFromEvent
. This introduces additional complexity and I lack the necessary knowledge to implement it.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.
I wonder if we could replace these magic numbers with Apple enums.