Skip to content

Instantly share code, notes, and snippets.

@marcoarment
Created August 15, 2022 13:19
Show Gist options
  • Save marcoarment/b980ff60cc45623aeb06a4121e13f354 to your computer and use it in GitHub Desktop.
Save marcoarment/b980ff60cc45623aeb06a4121e13f354 to your computer and use it in GitHub Desktop.
import SwiftUI
extension UIColor: Identifiable {
public var id: String {
get { self.accessibilityName }
}
}
struct ContentView: View {
let defaultColor = UIColor.systemBlue
let colors: [UIColor] = [
.systemRed,
.systemGreen,
.systemYellow,
.systemBlue,
]
@State var navigationValue: String?
@State var selectedColor: UIColor?
var body: some View {
NavigationSplitView {
List(selection: $navigationValue) {
NavigationLink("Tint Color", value: "test")
}
.navigationTitle("Home")
} detail: {
Text("⬆️ Back button and/or display-mode button above should change color after choosing a new color:")
List(selection: $selectedColor) {
ForEach(colors) { color in
Button {
selectedColor = color
navigationValue = nil
} label: {
Text(color.accessibilityName)
}
}
}
}
.tint(Color(uiColor: selectedColor ?? defaultColor))
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
@marcoarment
Copy link
Author

Happy to report that this is fixed in iOS 16 developer beta 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment