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

Fix Getting Stuck in Sub-View within Settings #1942

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,39 @@ struct AccountsSettingsView: View {
@State private var selectedProvider: SourceControlAccount.Provider?

var body: some View {
SettingsForm {
Section {
if $gitAccounts.isEmpty {
Text("No accounts")
.foregroundColor(.secondary)
.frame(maxWidth: .infinity, alignment: .center)
} else {
ForEach($gitAccounts, id: \.self) { $account in
AccountsSettingsAccountLink($account)
}
}
} footer: {
HStack {
Spacer()
Button("Add Account...") { addAccountSheetPresented.toggle() }
.sheet(isPresented: $addAccountSheetPresented, content: {
AccountSelectionView(selectedProvider: $selectedProvider)
})
.sheet(item: $selectedProvider, content: { provider in
switch provider {
case .github, .githubEnterprise, .gitlab, .gitlabSelfHosted:
AccountsSettingsSigninView(provider, addAccountSheetPresented: $addAccountSheetPresented)
default:
implementationNeeded
NavigationStack {
SettingsForm {
Section {
if $gitAccounts.isEmpty {
Text("No accounts")
.foregroundColor(.secondary)
.frame(maxWidth: .infinity, alignment: .center)
} else {
ForEach($gitAccounts, id: \.self) { $account in
AccountsSettingsAccountLink($account)
}
})
}
} footer: {
HStack {
Spacer()
Button("Add Account...") { addAccountSheetPresented.toggle() }
.sheet(isPresented: $addAccountSheetPresented, content: {
AccountSelectionView(selectedProvider: $selectedProvider)
})
.sheet(item: $selectedProvider, content: { provider in
switch provider {
case .github, .githubEnterprise, .gitlab, .gitlabSelfHosted:
AccountsSettingsSigninView(
provider,
addAccountSheetPresented: $addAccountSheetPresented
)
default:
implementationNeeded
}
})
}
.padding(.top, 10)
}
.padding(.top, 10)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ struct SettingsView: View {
}
}
.navigationSplitViewColumnWidth(215)
.hideSidebarToggle()
} detail: {
Group {
switch selectedPage.name {
Expand Down Expand Up @@ -184,7 +185,6 @@ struct SettingsView: View {
}
}
.navigationSplitViewColumnWidth(500)
.hideSidebarToggle()
.onAppear {
model.backButtonVisible = false
}
Expand Down
22 changes: 14 additions & 8 deletions CodeEdit/Features/Settings/Views/View+HideSidebarToggle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import SwiftUIIntrospect

extension View {
func hideSidebarToggle() -> some View {
Expand All @@ -15,14 +16,19 @@ extension View {

struct HideSidebarToggleViewModifier: ViewModifier {
func body(content: Content) -> some View {
content
.task {
let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }!
let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar"
let index = window.toolbar?.items.firstIndex { $0.itemIdentifier.rawValue == sidebaritem }
if let index {
window.toolbar?.removeItem(at: index)
if #available(macOS 14, *) {
content
.toolbar(removing: .sidebarToggle)
} else {
content
.task {
let window = NSApp.windows.first { $0.identifier?.rawValue == SceneID.settings.rawValue }!
let sidebaritem = "com.apple.SwiftUI.navigationSplitView.toggleSidebar"
let index = window.toolbar?.items.firstIndex { $0.itemIdentifier.rawValue == sidebaritem }
if let index {
window.toolbar?.removeItem(at: index)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ struct NavigationBarBackButtonVisible: ViewModifier {
}
}
}
.hideSidebarToggle()
.navigationBarBackButtonHidden()
.onAppear {
model.backButtonVisible = true
}
.onDisappear {
model.backButtonVisible = false
}
}
}

Expand Down