kitasuke / PagingMenuController

Paging view controller with customizable menu in Swift
MIT License
2.5k stars 449 forks source link

Add scrolling delegate functionality to allow callbacks for scroll start/end #316

Closed spsammy closed 7 years ago

spsammy commented 7 years ago

I needed to be able to detect when scrolling started and ended in my application, so that expensive background tasks could be disabled whilst scrolling was happening. Otherwise the scrolling experienced was jerky and teared in some situations, especially on lower spec phones.

I'm not very experienced with iOS and XCode, so it might be I've made some school-boy mistakes: let me know and I'll try to fix!

kitasuke commented 7 years ago

Thanks for your PR! Let me ask you some questions at first.

  1. What about adding new case like below?
public enum MenuMoveState {
    case willMoveController(to: UIViewController, from: UIViewController)
    case didMoveController(to: UIViewController, from: UIViewController)
    case willMoveItem(to: MenuItemView, from: MenuItemView)
    case didMoveItem(to: MenuItemView, from: MenuItemView)
    case didScrollStart
    case didScrollEnd
}

pagingMenuController.onMove = { state in
    switch state {
    case let .willMoveController(menuController, previousMenuController):
        print(previousMenuController)
        print(menuController)
    case let .didMoveController(menuController, previousMenuController):
        print(previousMenuController)
        print(menuController)
    case let .willMoveItem(menuItemView, previousMenuItemView):
        print(previousMenuItemView)
        print(menuItemView)
    case let .didMoveItem(menuItemView, previousMenuItemView):
        print(previousMenuItemView)
        print(menuItemView)
    case .didScrollStart:
        // do something
    case .didScrollEnd:
        // do something
    }
}
  1. Do we need to have plural callbacks?
spsammy commented 7 years ago

Hi, thanks for the quick reply, sorry I couldn't get back to you faster myself.

Adding a new case might good, I didn't think of that. The original work for this was done a year ago on an old fork, I thought I should update to the latest and submit a MR. Shall I try to redo it using this idea?

I'm afraid we do need the plural call backs, in my use case anyway. If this will cause a lot of work, then I can see if we can refactor our code to avoid it.

spsammy commented 7 years ago

I created https://github.com/kitasuke/PagingMenuController/pull/318 to do as you suggested. I'll close this pull request.