Last active
March 29, 2024 11:19
-
-
Save tciuro/ef04030689c29a27e3d2c6dc1bdeaad6 to your computer and use it in GitHub Desktop.
SwiftUI Form Highlight Issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// FormRowHighlightIssue | |
// | |
// Created by Tito Ciuro on 3/27/24. | |
// | |
import SwiftUI | |
enum Route: Hashable { | |
case one | |
case two | |
case three | |
} | |
@Observable | |
final class SomeViewModel { | |
var count: Int = 0 | |
@MainActor | |
func setRandomCount() { | |
count = Int.random(in: 1 ... 99) | |
} | |
} | |
@MainActor | |
struct ContentView: View { | |
@State private var viewModel = SomeViewModel() | |
@State private var navigationPath: [Route] = [] | |
var body: some View { | |
NavigationStack(path: $navigationPath) { | |
Form { | |
Section { | |
NavigationLink(value: Route.one) { | |
Label("\(viewModel.count)", systemImage: "stethoscope") | |
} | |
NavigationLink(value: Route.two) { | |
Label("Two", systemImage: "stethoscope") | |
} | |
} | |
Section { | |
NavigationLink(value: Route.three) { | |
Label("\(viewModel.count)", systemImage: "stethoscope") | |
} | |
} | |
} | |
.navigationDestination(for: Route.self) { route in | |
switch route { | |
case .one: | |
Text("One") | |
case .two: | |
Text("Two") | |
case .three: | |
Text("Three") | |
} | |
} | |
.navigationBarTitleDisplayMode(.inline) | |
.navigationTitle("Selection Issue") | |
.task { | |
viewModel.setRandomCount() | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I’m just not sure. And it may be a bug! I just don’t have enough SwiftUI experience to help I’m afraid.