Nested ZStack modifiers in progress/empty modifiers (#876)

Merge into a single modifier because they are used together.
This commit is contained in:
Davide 2024-11-15 16:33:26 +01:00 committed by GitHub
parent 55bb2e79c9
commit b08243949c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 27 deletions

View File

@ -114,8 +114,11 @@ private struct ContainerModifier: ViewModifier {
func body(content: Content) -> some View {
debugChanges()
return content
.themeProgress(if: !profileManager.isReady)
.themeEmptyContent(if: profileManager.isReady && !profileManager.hasProfiles, message: Strings.Views.Profiles.Folders.noProfiles)
.themeProgress(
if: !profileManager.isReady,
isEmpty: !profileManager.hasProfiles,
emptyMessage: Strings.Views.Profiles.Folders.noProfiles
)
.searchable(text: $search)
.onChange(of: search) {
profileManager.search(byName: $0)

View File

@ -65,8 +65,11 @@ struct MigrateView: View {
.disabled(model.step != .fetched)
}
.themeForm()
.themeProgress(if: model.step == .fetching)
.themeEmptyContent(if: model.step == .fetched && model.profiles.isEmpty, message: "Nothing to migrate")
.themeProgress(
if: model.step == .fetching,
isEmpty: model.profiles.isEmpty,
emptyMessage: "Nothing to migrate"
)
.themeAnimation(on: model, category: .profiles)
.navigationTitle(title)
.toolbar(content: toolbarContent)

View File

@ -35,6 +35,9 @@ extension View {
}
public func withMockEnvironment() -> some View {
withEnvironment(from: .mock, theme: Theme())
task {
try? await AppContext.mock.profileManager.observeLocal()
}
.withEnvironment(from: .mock, theme: Theme())
}
}

View File

@ -163,8 +163,8 @@ extension View {
modifier(ThemeProgressViewModifier(isProgressing: isProgressing))
}
public func themeEmptyContent(if isEmpty: Bool, message: String) -> some View {
modifier(ThemeEmptyContentModifier(isEmpty: isEmpty, message: message))
public func themeProgress(if isProgressing: Bool, isEmpty: Bool, emptyMessage: String) -> some View {
modifier(ThemeProgressViewModifier(isProgressing: isProgressing, isEmpty: isEmpty, emptyMessage: emptyMessage))
}
#if !os(tvOS)
@ -370,31 +370,20 @@ struct ThemeAnimationModifier<T>: ViewModifier where T: Equatable {
struct ThemeProgressViewModifier: ViewModifier {
let isProgressing: Bool
var isEmpty: Bool?
var emptyMessage: String?
func body(content: Content) -> some View {
ZStack {
content
.opaque(!isProgressing && isEmpty != true)
if isProgressing {
ThemeProgressView()
}
content
.opaque(!isProgressing)
}
}
}
struct ThemeEmptyContentModifier: ViewModifier {
let isEmpty: Bool
let message: String
func body(content: Content) -> some View {
ZStack {
content
.opaque(!isEmpty)
if isEmpty {
Text(message)
} else if let isEmpty, let emptyMessage, isEmpty {
Text(emptyMessage)
.themeEmptyMessage()
.opaque(isEmpty)
}
}
}