Search code examples
swiftswiftuiswiftui-list

SwiftUI: disable .refreshable programmatically


I use a refreshable function available with SwiftUI but I want to disable the function under certain conditions (for example if my list only displays locally saved favorites I don't need to refresh).

I couldn't find anything about it. Anyone got a solution?

Thank you in advance for your help.


Solution

  • With the help of this conditional view modifier:

    https://www.avanderlee.com/swiftui/conditional-view-modifier/

    You can do this:

            .if(condition) { view in
                view.refreshable {
                    // do refresh
                }
            }