#StackBounty: #ios #swift #swiftui #swiftui-list How to manage scrolling with page controller swiftui

Bounty: 50

I am trying to show page controller like second screenshot when goes to bottom and hide top view.

Screenshot

Screenshot

Code:

import SwiftUI

struct ContentView: View {

    @State private var currentPage = 0    

    var body: some View {
        if scrollViewContentOffset1 <= 30 {
            AppHeaderView(currentDay: $currentPage)
                .padding()
        } else {
            PageControl(numberOfPages: 7, currentPage: $currentPage)
                .frame(width: CGFloat(7 * 18))
                .padding(.trailing)
        }
        
        TabView (selection: $currentPage) {
            Group {
                Rectangle()
                    .cornerRadius(10)
                    .foregroundColor(Color(UIColor(displayP3Red: 48/255, green: 50/255, blue: 51/255, alpha: 1.0)))
                    .frame(height: 200)
                
                Text("Mon").tag(1)
                Text("Tue").tag(2)
                Text("Wed").tag(3)
                Text("thu").tag(4)
                Text("fri").tag(5)
                Text("Sat").tag(6)
                Text("Sun").tag(7)
            }
        }.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
            .onChange(of: currentPage) {
                currentPage = $0
            }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct PageControl: UIViewRepresentable 
{
    var numberOfPages: Int
    @Binding var currentPage: Int

    func makeUIView(context: Context) -> UIPageControl {
        let control = UIPageControl()
        control.numberOfPages = numberOfPages
        control.currentPageIndicatorTintColor = .green
        control.pageIndicatorTintColor = UIColor(displayP3Red: 48/255, green: 50/255, blue: 51/255, alpha: 1.0)
        return control
    }

    func updateUIView(_ uiView: UIPageControl, context: Context) {
        uiView.currentPage = currentPage
    }
}

Can someone please explain to me how to show page controller at top when scroll to bottom, I’ve tried to implement by above but no results yet.

Any help would be greatly appreciated.

Thanks in advance.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.