SwiftUI Pull To Refresh用の部品

Pocket

SwiftUIで簡単にPull To Refreshできる部品をGitHubに公開してくれていて、下記URLからダウンロードすることも可能です。

https://github.com/siteline/SwiftUIRefresh

Cocoapodsから取得する場合Podfileファイルに下記を追加します。

pod "SwiftUIRefresh"

pod install updateしimport SwiftUIRefreshすると下記の候補が出てくるようになります。

.pullToRefresh(isShowing: Binding<Bool>, onRefresh: () -> Void)

Usageをまねて下記のコードを書きました。

import SwiftUI
import SwiftUIRefresh

struct NavigationRefresh: View {
    @State var isShowing: Bool = false
    var body: some View {
        NavigationView {
            List (["Ceres", "Toutatis", "Phaethon"], id: \.self) {s in
                Text(s)
            }.navigationBarTitle(Text("SwiftUIRefresh"))
        }.pullToRefresh(isShowing: self.$isShowing){
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                self.isShowing = false
            }
        }
    }
}

実行すると下のような挙動です。

Pull To Refresh
Pull To Refresh

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


2022 MJELD TECHNOLOGIES. ALL RIGHTS RESERVED