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
Multiple direction support #131
Multiple direction support #131
Conversation
Hi @felix-dumit . I'll review your code by the end of the week. Sorry for delay. |
@AEugene Any updates on this? |
bf6cd75
to
cfb0763
Compare
@felix-dumit Sorry for delay again, there were some urgent tasks. Could you update your branch with latest master? And then I'll provide review. Thank you for contribution. |
b74fe69
to
ea4e56a
Compare
@AEugene Just updated with the changes from |
ea4e56a
to
aac9e46
Compare
} | ||
|
||
func normalizedPointForSize(screenSize:CGSize) -> CGPoint { | ||
let x = 2 * (self.x / screenSize.width) |
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.
Why do you multiple by 2 in normalisation? Also parameter called screenSize, but you're actually using bounds of DraggableCardView.
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.
Ok this function name was actually misleading, I added another function that performed the normalisation correctly.
What this one does is normalize a distance based on the screensize. It is multiplied by two because the normalized coordinate system goes from (-1, 1)
@felix-dumit I've found a bug. It reproduces with horizontal swiping: Issue is in dragPercentage calculations. I tried this approach: private var dragPercentage:CGFloat {
// normalize dragDistance then convert project closesest direction vector
let normalizedDragPoint = dragDistance.normalizedPointForSize(bounds.size)
let swipePoint = normalizedDragPoint.scalarProjectionPointWith(dragDirection.point)
// if point is outside rect, percentage of swipe in direction is over 100%
if !SwipeResultDirection.boundsRect.contains(swipePoint) {
return 1.0
} else {
let projectionPoint: CGPoint = directions.reduce(dragDirection.point) {
if $0.distanceTo(normalizedDragPoint) > $1.point.distanceTo(normalizedDragPoint) {
return $1.point
}
return $0
}
return normalizedDragPoint.scalarProjectionWith(projectionPoint)
}
} And it works great with horizontal and vertical swiping, but there is obvious jumping with directions set I can't merge it now, because horizontal swiping is key functionality of Koloda. And setting currentCardIndex requires more complex logic. For example when you try to set Also there are some syntax issues(like space after colon, etc). I started refactoring Koloda, so let's keep it clean. We use these guidelines: https://swift.org/documentation/api-design-guidelines/ Thank you for contribution. I'm waiting for updated pull request :) |
I'll take a closer look on Monday, but I couldn't reproduce the issue from the video, I set those directions in the Anyway thanks for review I'll update soon |
00e3c03
to
de27d80
Compare
@felix-dumit It is reproducible with default threshold value. You can try it on first example(one with red background). |
@AEugene I was able to reproduce, you have to start dragging at the very center of the card either up or down then I get the issue. |
@AEugene Ok I fixed the issue. It was because if the dragDistance was very small (rounded to CGPoint.zero) it would not intersect with any of the target lines so the I updated so that now it will return 0 if no instersections are found: return rect.perimeterLines
.flatMap { CGPoint.intersectionBetweenLines(targetLine, line2: $0) }
.map { centerDistance / $0.distanceTo(.zero) }
.minElement() ?? 0 |
Should be ready for re-review now |
This sounds great 👍 |
@@ -62,7 +66,11 @@ public class DraggableCardView: UIView { | |||
|
|||
override public var frame: CGRect { | |||
didSet { | |||
actionMargin = delegate?.card(cardSwipeThresholdMargin: self) ?? frame.size.width / 2.0 | |||
if let r = delegate?.card(cardSwipeThresholdRatioMargin: self) where r != 0 { |
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.
could you name variable as "ratio" here?
hi @felix-dumit . Code looks great, you did good job. Thank you for contribution. Your code will be merged after these changes. Also I’ve noticed finish percentage jumping with configuration |
@AEugene Ok just pushed those changes, I had to leave the change from |
@felix-dumit I'm testing your branch and I'm getting some weird behaviour when using.
The card moves slightly then "falls" off the screen. Better control of allowed directions would be a great feature though. Thanks for working on this. |
@brsunter yeah that's kind of undefined behaviour for that scenario as it doesn't make much sense to use it. If you don't want to allow any directions just return an empty array. Maybe there could be an assert preventing your example. Or even remove the |
I think removing |
@felix-dumit @brsunter Yup, I think we should remove func koloda(koloda: KolodaView, allowedDirectionsForIndex index: UInt) -> [SwipeResultDirection]? |
@AEugene I think we don't need to make |
@felix-dumit Hm, maybe you're right. It will complicate the logic, because we still need to handle empty array of directions. Also we need to handle nil direction when we update overlay state. Could you implement it? |
@AEugene Ok I just pushed that, tell me what you think. |
0c8df94
to
0db7c9e
Compare
delegate?.card(self, wasDraggedWithFinishPercentage: min(fabs(100 * percentage), 100), inDirection: dragDirection) | ||
if let dragDirection = dragDirection { | ||
let percentage = dragPercentage | ||
updateOverlayWithFinishPercent(percentage, direction:dragDirection) |
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.
Shouldn't we handle nil direction to update overlay image?
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.
Yes, you're right, I just fixed this.
@felix-dumit I merged your request. Thanks for contribution. |
@AEugene Great! |
#118
Added the ability to swipe in any direction.
Currently implemented directions are:
It could also be extended to another custom direction by specifying a direction point (the coordinate system has its origin at the center to the cardView).
Most drastic changes are: