9

iOS 15 introduces the '.refreshable' View Modifier, but most of the examples I've seen use a List. I want to implement a pull to refresh feature in an app that does not use a list but just a VStack with Text views like the below. How can I implement this so that pull down to refresh will refresh my data?

import SwiftUI

struct ContentView: View {

@State var songName = "Song"
@State var artistName = "Artist"

    var body: some View {
        VStack {
            Text(songName)
            Text(artistName)
        }
        .refreshable {
            reloadData()
        }
    }
    
    private func reloadData() {
        
        songName = "Let it Be"
        artistName = "The Beatles"
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
5
  • 6
    Unfortunately only possible for a List at the moment. My feedback from 13th June 2021 is still open with no recent similar reports. I recommend also reporting this on Feedback Assistant, to make it a higher priority on their list. Commented Aug 2, 2021 at 19:13
  • 2
    @George_E can I get your Feedback number? That way I can create a new one and reference yours directly. Commented Aug 2, 2021 at 22:11
  • 4
    @AndyIbanez Sure, it's FB9168168. It's about 'Add refreshable for ScrollView' Commented Aug 2, 2021 at 22:13
  • 2
    I filed one as well 👍 FB9444578 Commented Aug 2, 2021 at 22:25
  • Consider this topic SwiftUI Generic Pull to refresh view Commented May 15, 2022 at 7:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.