gh123man / SwiftUI-Refresher

A native, customizable SwiftUI refresh control
MIT License
119 stars 12 forks source link

Not working if view is child of TabView #11

Closed neal3000 closed 8 months ago

neal3000 commented 1 year ago

I'm using a TabView as my initial content view and that has a FriendsView with a ScrollView.

I can't get Refresher to work with the ScrollView in FriendsView - it looks like private func offsetChanged(_ val: CGFloat) never gets called.

If I make FriendsView the initial view ( removing the TabView) then things work.

struct ContentView: View {NavigationStack {ZStack(alignment: .bottom) {HStack {TabView(selection: $appData.currentTab) { FriendsView().tabItem { Label("Friends", systemImage: "square.fill") }.tag(TabPages.FriendTab) ....

struct FriendsView: View { var body: some View { ScrollView(.vertical) { VStack { }} .refresher() {...}

gh123man commented 1 year ago

Hello,

Can you try the following code? (Mostly the same as what you posted, but cleaned up so it can compile) Works fine for me. Targeting iOS 16, running on iOS 17.

struct ContentView: View {

    struct FriendsView: View {
        var body: some View {
            ScrollView(.vertical) {
                VStack {
                    Text("Foo")
                }
            }.refresher() {}
        }
    }

    var body: some View {
        NavigationStack {
            ZStack(alignment: .bottom) {
                HStack {
                    TabView() {
                        FriendsView().tabItem {
                            Label("Friends", systemImage: "square.fill")
                        }
                    }
                }
            }
        }
    }
}
neal3000 commented 1 year ago

Thanks ! That fix it. That does look like what I tried, but obviously something changed. previously OffSet reader never got called (I put in some print statements)

btw, avoid .scrollTargetBehavior(.viewAligned(limitBehavior: .never)). it makes things jerky.