mirror of
https://github.com/Homebrew/BrewUI.git
synced 2026-10-02 08:34:36 +08:00
Scroll to selection on selecting relationship
This commit is contained in:
@@ -43,41 +43,54 @@ struct InstalledPackagesView: View {
|
||||
}
|
||||
|
||||
private func installedList(_ content: InstalledPackagesContent) -> some View {
|
||||
List {
|
||||
if content.shouldShowFormulaeSection {
|
||||
Section("Formulae") {
|
||||
ForEach(content.formulaPackages) { package in
|
||||
listRow(for: package)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.setSelection(package.id)
|
||||
}
|
||||
.listRowBackground(
|
||||
viewModel.activeSelectedPackageID == package.id ? Color.brewBrandTint : Color.clear,
|
||||
)
|
||||
ScrollViewReader { proxy in
|
||||
List {
|
||||
if content.shouldShowFormulaeSection {
|
||||
Section("Formulae") {
|
||||
ForEach(content.formulaPackages) { package in
|
||||
listRow(for: package)
|
||||
.id(package.id)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.setSelection(package.id)
|
||||
}
|
||||
.listRowBackground(
|
||||
viewModel.activeSelectedPackageID == package.id ? Color.brewBrandTint : Color.clear,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if content.shouldShowCasksSection {
|
||||
Section("Casks") {
|
||||
ForEach(content.caskPackages) { package in
|
||||
listRow(for: package)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.setSelection(package.id)
|
||||
}
|
||||
.listRowBackground(
|
||||
viewModel.activeSelectedPackageID == package.id ? Color.brewBrandTint : Color.clear,
|
||||
)
|
||||
if content.shouldShowCasksSection {
|
||||
Section("Casks") {
|
||||
ForEach(content.caskPackages) { package in
|
||||
listRow(for: package)
|
||||
.id(package.id)
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.setSelection(package.id)
|
||||
}
|
||||
.listRowBackground(
|
||||
viewModel.activeSelectedPackageID == package.id ? Color.brewBrandTint : Color.clear,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.accessibilityLabel("Installed packages")
|
||||
.onExitCommand {
|
||||
viewModel.clearSelection()
|
||||
.listStyle(.plain)
|
||||
.accessibilityLabel("Installed packages")
|
||||
.onAppear {
|
||||
scrollToSelection(viewModel.activeSelectedPackageID, in: content, with: proxy)
|
||||
}
|
||||
.onChange(of: viewModel.activeSelectedPackageID) { _, selectedID in
|
||||
scrollToSelection(selectedID, in: content, with: proxy)
|
||||
}
|
||||
.onChange(of: content.packages.map(\.id)) { _, _ in
|
||||
scrollToSelection(viewModel.activeSelectedPackageID, in: content, with: proxy)
|
||||
}
|
||||
.onExitCommand {
|
||||
viewModel.clearSelection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +98,19 @@ struct InstalledPackagesView: View {
|
||||
InstalledListRowRoot(package: package)
|
||||
}
|
||||
|
||||
private func scrollToSelection(
|
||||
_ selectedID: BrewPackage.ID?,
|
||||
in content: InstalledPackagesContent,
|
||||
with proxy: ScrollViewProxy,
|
||||
) {
|
||||
guard let selectedID, content.packages.contains(where: { $0.id == selectedID }) else {
|
||||
return
|
||||
}
|
||||
withAnimation(.brewFast) {
|
||||
proxy.scrollTo(selectedID, anchor: .center)
|
||||
}
|
||||
}
|
||||
|
||||
private var loadingSkeletonList: some View {
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading, spacing: 0) {
|
||||
|
||||
Reference in New Issue
Block a user