fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.28k stars 171 forks source link

onPageChangeCanceled so we can know what the active page is after swiping but not changing the page #219

Closed bryan1anderson closed 3 years ago

bryan1anderson commented 3 years ago

I have a list of videos I'm trying to page through. We need to use a shared AVPlayer instance which means monitoring which video is being presented.

If I am about to change a page the video should pause. If I cancel the page change I need to be alerted so I can resume the video

Describe the solution you'd like

onPageChangeDidCancel(_ callback: ((Int) -> Void)?) -> Pager<URL, URL, VideoView>

Describe alternatives you've considered Getting alerted when the animation finishes so I can detect the correct index and play the video.

fermoya commented 3 years ago

Hi @bryan1anderson , what you describe can be easily implemented. Currently, onPageChanged and onPageWillChange are only triggered if the page changes. I'm thinking of adding a new onPageWillTransition(_:) to inform the client with a Result<PageTransition, PagerError> if the transition is successful or the user "canceled" the transition. Would that work for you?

bryan1anderson commented 3 years ago

@fermoya That would work amazingly.

fermoya commented 3 years ago

@bryan1anderson I've triggered CI/CD workflow and you should have this available in 2.3.0-beta.1 that will be released in about 10 min.

bryan1anderson commented 3 years ago

oh wow that was fast!! I got in the project and tried to see if it will work but haven't tested it. Here is the PR you can just delete it https://github.com/fermoya/SwiftUIPager/pull/222

@fermoya thanks very much