fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.29k stars 172 forks source link

[FEAT] Restricting next page draggable Area #155

Closed KimTaeHyeong17 closed 3 years ago

KimTaeHyeong17 commented 3 years ago

First, @fermoya thank you for making such a fabulous opensource like this.

I wanted to implement my request feature and contribute to this opensource but I don't have experience editing opensource code so right now I wrote this on Feature request. If you show me briefly how to edit some code or references that I can study, I will try.

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

The UI I'm working on is right now not implemented in your library. Its about paging area of next of previous page.

Currently, if I drag the previous or next page in infinite looping mode, the whole previous or next page appears in view.

But I wanted to restrict the area of showing previous or next page view

Describe the solution you'd like A clear and concise description of what you want to happen.

To make it happen, I edited some code in PagerContent.swift / extension Pager.PagerContent / func onDragChanged()

I added this code in the end of the onDragChanged function

// MARK: Custom Draggable bound inset
            if (direction == Direction.backward && draggingOffset > 110) {
                draggingOffset = 110
            }else if (direction == Direction.forward && draggingOffset < -110) {
                draggingOffset = -110
            }else{
                print("draggingOffset \(draggingOffset)")
            }

if draggingOffset is increased more than boundary (110), I fixed draggingOffset to the boundary(110) so that next page or previous page don't show its full view before paging start.

I added this code and used Pager.sensitivity modifier to enable paging when 110 offset changed.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

when I set a boundary to 110, the maximum view area of previous or next page view

스크린샷 2020-11-16 오전 11 46 17 스크린샷 2020-11-16 오전 11 46 17
fermoya commented 3 years ago

Hi @KimTaeHyeong17 , thanks for your comment. No worries, I can study your request and implement it although if it's something you'd like to try, I'm happy enough to shed some light here. You're very kind.

Just to clarify, you'd like to drag the page and rather than completely scroll to the next page, you'd like to limit the scroll to a boundary and when reached then scroll? So, scroll up to 20% of the page and when so then scroll?

KimTaeHyeong17 commented 3 years ago

Hi, @fermoya sorry for late reply. I'm really sorry if you started to work already. Right now, my UI requirement has changed to restrict the moving area of another page to decrease dragging speed (while moving to the next page is not restricted) I will handle this problem with your existing perfect, beautiful SwiftUIPager API. I will open the issue if I have another problems. Thank you for your consideration. (you can close the issue)

fermoya commented 3 years ago

For future readers, I liked this feature request and I decided to implement it. See singlePagination(ratio:sensitivity:)