Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop to root when domain changes #38

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Core/CommonViewsKit/Sources/CommonViewsKit/NavigationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public final class NavigationStore {
path = path.dropLast()
}
}

public func popToRoot(animated: Bool = true) {
if animated {
withAnimation {
path.removeAll()
}
} else {
path.removeAll()
}
}
}
5 changes: 5 additions & 0 deletions MockingStar/MockingStar/Modules/Home/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import TipKit
struct SidebarView: View {
@Environment(MockDomainDiscover.self) private var domainDiscover: MockDomainDiscover
@SceneStorage("mockDomain") private var mockDomain: String = ""
private let navigationStore = NavigationStore.shared
private let logger = Logger(category: "SidebarView")

var body: some View {
Expand Down Expand Up @@ -64,6 +65,10 @@ struct SidebarView: View {
.onReceive(NotificationCenter.default.publisher(for: .reloadMockDomains)) { _ in
Task { try await reloadMockDomains() }
}
.task(id: mockDomain) {
try? await Task.sleep(for: .milliseconds(100))
navigationStore.popToRoot()
}
}

@MainActor
Expand Down
Loading