Es wird dieses dunkle graue Highlight erhalten, und ich möchte ihn in etwas Gelüteres ändern. Ich werde beide für den Kontext hinzufügen:
Code: Select all
// HomeView snippet
var body: some View {
NavigationStack {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text("Explore")
.font(.title2)
Spacer()
SortButton(isAscending: $isAscending) // Now properly updates sorting
}
SearchBar(text: $searchText)
.padding(.vertical, 2)
//below is the list with the NavigationLink
List(filteredFolders) { folder in
NavigationLink(destination: DummyFolderDetailView(folder: folder)) {
FolderRowView(folder: folder)
}
}
.clipShape(RoundedRectangle(cornerRadius: 8))
.navigationTitle("Folders")
}
}
}
< /code>
// Component FolderRowView
struct FolderRowView: View {
let folder: Folder
@State private var isHovering = false
var body: some View {
HStack {
// Folder Icon
Image(systemName: "folder.fill")
.resizable()
.scaledToFit()
.frame(width: 18, height: 18)
.foregroundStyle(.gray)
Spacer()
// Folder Name
Text(folder.name)
.font(.body)
.frame(maxWidth: .infinity, alignment: .leading)
// Chevron Icon
Image(systemName: "chevron.right")
.foregroundColor(.gray)
}
.padding(.vertical, 6)
.padding(.horizontal, 10) // Added horizontal padding for space around content
.background(isHovering ? Color.gray.opacity(0.1) : Color.clear) // Optional background change on hover
.scaleEffect(isHovering ? 1.05 : 1.0) // Zoom-in effect
.cornerRadius(8)
.animation(.easeInOut(duration: 0.2), value: isHovering) // Smooth animation
.onHover { hovering in
isHovering = hovering
}
.contextMenu { //(...)
< /code>
So as you can see i already successfully added on hover styling and animation to the rows by working inside the component file.
I realize that customizing the on press style is a bit more complicated than that!
[b]I tried:[/b]
[*].onTapGesture

machte eine dritte Komponent -Datei -Custom -Struktur. Ein Modifikator zum NavigationLink as .buttonStyle (practableStyle ()) Aber es hat nichts getan. NavigationLink durch die Schaltfläche ausgelöst. Dann müsste ich in der HomeView diesen Ordner in der Liste nur den Ordner aufrufen. Ich habe es versucht, aber es hat das gleiche Ergebnis wie der erste Ansatz, bei dem der neue Druckstil angezeigt wird, aber das Klicken auf keine Aktion. Assets>