はじめに
読み込み中であることをユーザーに伝える方法としてredacted
があります。
redacted
を使ったので記録しておきます。
サンプルアプリ
実装
import SwiftUI
struct ContentView: View {
@State private var isLoading = false
var body: some View {
VStack(spacing: 50) {
Text("テキスト")
.redacted(reason: isLoading ? .placeholder : [])
Button {
Task { @MainActor in
isLoading = true
// 長い処理の代わり
try? await Task.sleep(nanoseconds: 1 * NSEC_PER_SEC)
isLoading = false
}
} label: {
Text("再読み込み")
}
}
}
}
おわり
色々なアプリで使われてる方法なので自分のアプリにも積極的に使っていきたいです。