Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only Works with List #11

Open
Peter-Schorn opened this issue Jul 22, 2020 · 8 comments
Open

Only Works with List #11

Peter-Schorn opened this issue Jul 22, 2020 · 8 comments

Comments

@Peter-Schorn
Copy link

This only seems to work with lists. There are many cases where I cannot use a list but would still like to enable pull down to refresh. For example, how would I enable this on a ScrollView?

@Bubba8291
Copy link

I'm having the same issue too. +1

@Peter-Schorn
Copy link
Author

Peter-Schorn commented Jul 23, 2020

@Bubba8291 I was actually able to figure out how to get it to work with scroll views. You can find my fork here: https://github.com/Peter-Schorn/SwiftUIRefresh

@Bubba8291
Copy link

@Peter-Schorn Unfortunately, it didn't work for me. Are you on Xcode beta? If so, which one. I'm on Xcode B3, so maybe that's why.

@Peter-Schorn
Copy link
Author

Peter-Schorn commented Jul 24, 2020

I just tested in in beta 2 (12A6159), and I have found that when you attach pullToRefresh as a modifier to the ScrollView, it doesn't work, but when you attach it to a VStack that is the direct child of a ScrollView, then it does work, although the position of the activity indicator is higher up than it should be.

This works:

ScrollView {
    VStack {
        ForEach(data, id: \.self) { item in
            Text(item)
                .padding()
        }
    }
    .pullToRefresh(
        isRefreshing: $isRefreshing,
        onRefresh: onRefresh
    )
}

But this does not:

ScrollView {
    VStack {
        ForEach(data, id: \.self) { item in
            Text(item)
                .padding()
        }
    }
}
.pullToRefresh(
    isRefreshing: $isRefreshing,
    onRefresh: onRefresh
)

@Bubba8291
Copy link

The code worked in Xcode B3 for me.

@Peter-Schorn
Copy link
Author

@Bubba8291 Did you have the same issue with the activity indicator Benning to high up on the screen?

@RobertPeteleaza
Copy link

I just tested in in beta 2 (12A6159), and I have found that when you attach pullToRefresh as a modifier to the ScrollView, it doesn't work, but when you attach it to a VStack that is the direct child of a ScrollView, then it does work, although the position of the activity indicator is higher up than it should be.

This works:

ScrollView {
    VStack {
        ForEach(data, id: \.self) { item in
            Text(item)
                .padding()
        }
    }
    .pullToRefresh(
        isRefreshing: $isRefreshing,
        onRefresh: onRefresh
    )
}

But this does not:

ScrollView {
    VStack {
        ForEach(data, id: \.self) { item in
            Text(item)
                .padding()
        }
    }
}
.pullToRefresh(
    isRefreshing: $isRefreshing,
    onRefresh: onRefresh
)

I tried your suggested method. It doesn't work for me, unfortunately.

@bradley
Copy link

bradley commented Mar 25, 2021

I ended up writing an alternative version, but somewhat based on this repo, for my ScrollView needs. I've heavily tested it in numerous use cases such as heavy styling of the content view and such as being wrapped in problematic UI like a NavigationView. This could likely be easily modified to work for list views too should other bugs herein block you.

https://gist.github.com/bradley/7517e6592a3621bf57aa5dbb7395e394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants