SwiftUI, as of now, does not pass the current accent color to sheets. In the following example, the accent color of the button in the sheet will not be red.
// Some parent view which sets an accent color, can't change this
struct ContentView: View {
var body: some View {
ChildView()
.accentColor(.red)
}
}
// A child view that uses the accent color set by the parent
struct ChildView: View {
@State var showSheet = false
var body: some View {
VStack {
Button("this uses red"){
showSheet = true
}
.sheet(isPresented: $showSheet){
VStack {
Button("this will ignore accent color"){ }
}
}
}
}
}
I'm guessing this is a bug, but I'm looking for a workaround. The problem is, I can't just set .accentColor(.red) or whatever inside of the presented sheet, because my app uses dynamic accent colors depending on a setting. That is to say–I need to be able to pass the accentColor of ChildView on to the sheet, without knowing what it is necessarily.
I'v tried passing .accentColor(.accentColor) to the view in the sheet, which does not work.
Any ideas?