fermoya / SwiftUIPager

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

[FEAT] little dot indicators #211

Closed iKK001 closed 3 years ago

iKK001 commented 3 years ago

Not sure if I haven't found it yet - is there the possiblity to show little dot indicators ?

I am having a hard time creating a correct isCurrentPageIndex callback with your SwiftUIPager. (if I could, then I am happily creating my own dot-indicators - but right now I cannot since the correct index is not available as a callback of some sort. Or do I not get something here ?

Do you have any idea how I could do so ?

(i.e. it is not enough to observe .onPageChanged { newPage in ... } since this does not kick-in when swiping fast. Also .onDraggingEnded { ... } does not work for getting the dot-indicator index since if you just take a glimpse at the next page but do not actuall fully swipe then this does not work.)

The native SwiftUI behaviour for TabView's PageViewStyle pages indicators show up to a max of 8 dots (and fades the ones left or right if more than 8 pages).

iKK001 commented 3 years ago

ah - I just found a solution:

.onChange(of: page.index) { newIdx in
    myOwnDotIndicatorView.selectedIndex = newIdx
}

never mind !

fermoya commented 3 years ago

Hi @iKK001 , please add a title to the issues.

Take a look at how other users have implemented this:

https://github.com/franklynw/PagingControl

This isn't part of this library's purpose. You have at all moment a reference to the page with the current index so this implementation is feasible on the client side