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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user