clayellis / APReorderableStackView

Other
36 stars 8 forks source link

Added horizontal support #10

Open OscarFridh opened 5 years ago

OscarFridh commented 5 years ago

Here's a new PR that strictly addresses adding horizontal support. I wasn't sure how you want to handle delegation in this case, so currently If the stack view is set up to be horizontal the delegate method (didDragToReorder) is called in the same way where 'up' represents right and 'Y' represents X.

teameh commented 5 years ago

I think I would either create an alternative delegate method:

@objc optional func didDragHorizontalToReorder(inRightDirection right: Bool, maxX: CGFloat, minX: CGFloat)

Or introduce enum:

@objc public enum DragDirection: Int {
  case up, down, left, right
}

And use that in the delegate?

@objc optional func didDragToReorder(direction: APRedorderableStackView.DragDirection, max: CGFloat, min: CGFloat)
OscarFridh commented 5 years ago

Good idea! I think I prefer the alternative delegate method because then the caller can check the direction on the boolean instead of switching over an enum. The stack view will be either horizontal or vertical so it's unnecessary to switch over four cases. Or what do you think?

teameh commented 5 years ago

Yeah that makes sense :)