Add ProgressView as overlay when possible

Instead of replacing view entirely (GenericCreditsView).

Make replacement explicit in DebugLogView.

Basically drop View extension.
This commit is contained in:
Davide De Rosa 2022-04-21 10:56:11 +02:00
parent aefbfaa588
commit 96b199425f
3 changed files with 19 additions and 20 deletions

View File

@ -141,14 +141,18 @@ extension GenericCreditsView {
@Binding var content: String?
var body: some View {
content.map { unwrapped in
ScrollView {
Text(unwrapped)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.padding()
ZStack {
content.map { unwrapped in
ScrollView {
Text(unwrapped)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
.padding()
}
}
}.replacedWithProgress(when: content == nil)
.onAppear(perform: loadURL)
if content == nil {
ProgressView()
}
}.onAppear(perform: loadURL)
}
private func loadURL() {

View File

@ -88,15 +88,6 @@ extension View {
}
}
}
@ViewBuilder
func replacedWithProgress(when condition: Bool) -> some View {
if condition {
ProgressView()
} else {
self
}
}
}
extension View {

View File

@ -65,11 +65,15 @@ struct DebugLogView: View {
.edgesIgnoringSafeArea([.leading, .trailing])
}
@ViewBuilder
private func toolbar() -> some View {
Button(action: shareDebugLog) {
themeShareImage.asSystemImage
}.replacedWithProgress(when: isSharing)
.disabled(logLines.isEmpty)
if !isSharing {
Button(action: shareDebugLog) {
themeShareImage.asSystemImage
}.disabled(logLines.isEmpty)
} else {
ProgressView()
}
}
private var contentView: some View {