7

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()
    }
}
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • 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. – George Aug 02 '21 at 19:13
  • 2
    @George_E can I get your Feedback number? That way I can create a new one and reference yours directly. – Andy Ibanez Aug 02 '21 at 22:11
  • 4
    @AndyIbanez Sure, it's `FB9168168`. It's about 'Add `refreshable` for `ScrollView`' – George Aug 02 '21 at 22:13
  • 2
    I filed one as well FB9444578 – GarySabo Aug 02 '21 at 22:25
  • Consider this topic [SwiftUI Generic Pull to refresh view](https://stackoverflow.com/a/61371933/12299030) – Asperi May 15 '22 at 07:45

0 Answers0