Swift/Swift CS

[iOS/SwiftUI] refreshable

힛해 2024. 8. 31. 18:40
728x90

https://developer.apple.com/documentation/swiftui/view/refreshable(action:)

 

refreshable(action:) | Apple Developer Documentation

Marks this view as refreshable.

developer.apple.com

 

nonisolated
func refreshable(action: @escaping () async -> Void) -> some View

 

간단하게 새로고침을 구현할 수 있는 키워드다.

 

새로고침 UI가 상단에 생성되고 안에 정의한 함수들이 실행된다

 

사용방법

struct RefreshableView: View {
  let store: StoreOf<Refreshable>
  @State var isLoading = false

  var body: some View {
    List {...}
    .refreshable {
      isLoading = true
      defer { isLoading = false }
      await store.send(.refresh).finish()
    }
  }
}