Fix publishing changes during view updates warning
Defer state mutations in .onReceive handlers to next run loop
by wrapping them in Task { @MainActor in ... }
This commit is contained in:
@@ -155,19 +155,23 @@ import SwiftUI
|
||||
}
|
||||
#if os(iOS) || os(tvOS)
|
||||
.onReceive(environments.commandClient.$groups) { _ in
|
||||
updateButtonVisibility()
|
||||
#if os(iOS)
|
||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||
coordinator.selection = .overview
|
||||
}
|
||||
#endif
|
||||
Task { @MainActor in
|
||||
updateButtonVisibility()
|
||||
#if os(iOS)
|
||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||
coordinator.selection = .overview
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}.onReceive(profile.$status) { _ in
|
||||
updateButtonVisibility()
|
||||
#if os(iOS)
|
||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||
coordinator.selection = .overview
|
||||
}
|
||||
#endif
|
||||
Task { @MainActor in
|
||||
updateButtonVisibility()
|
||||
#if os(iOS)
|
||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||
coordinator.selection = .overview
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}.onAppear {
|
||||
updateButtonVisibility()
|
||||
}
|
||||
|
||||
@@ -77,13 +77,15 @@ public struct MainView: View {
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .navigateToSettingsPage)) { notification in
|
||||
guard let page = notification.object as? SettingsPage else { return }
|
||||
pendingSettingsPage = page
|
||||
if viewModel.selection == .settings {
|
||||
settingsNavigationPath = NavigationPath()
|
||||
settingsNavigationPath.append(page)
|
||||
pendingSettingsPage = nil
|
||||
} else {
|
||||
viewModel.selection = .settings
|
||||
Task { @MainActor in
|
||||
pendingSettingsPage = page
|
||||
if viewModel.selection == .settings {
|
||||
settingsNavigationPath = NavigationPath()
|
||||
settingsNavigationPath.append(page)
|
||||
pendingSettingsPage = nil
|
||||
} else {
|
||||
viewModel.selection = .settings
|
||||
}
|
||||
}
|
||||
}
|
||||
.environment(\.selection, $viewModel.selection)
|
||||
|
||||
+6
-6
@@ -92,22 +92,22 @@ struct MainView: View {
|
||||
updateButtonVisibility()
|
||||
}
|
||||
.onReceive(environments.commandClient.$groups) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.onReceive(environments.commandClient.$connections) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.onReceive(environments.commandClient.$hasAnyConnection) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .NEVPNStatusDidChange)) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.onReceive(environments.$extensionProfile) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.onReceive(environments.$emptyProfiles) { _ in
|
||||
updateButtonVisibility()
|
||||
Task { @MainActor in updateButtonVisibility() }
|
||||
}
|
||||
.sheet(isPresented: $showGroups) {
|
||||
GroupsSheetContent()
|
||||
|
||||
Reference in New Issue
Block a user