How to determine multicolor accent color on watchOS with SwiftUI?

50 Views Asked by At

Here you can see how .accessoryRectangular look like for Color.accentColor multicolor and red.

enter image description here enter image description here

There is a way how to fix it properly. But first I need to determine if user selected multicolor or not.

Since .accentColor is defined the following not optional way:

public static var accentColor: Color { get }

is there any way to check if it is multicolor or not? I thought that multicolor is when accentColor is nil... but I was wrong. Any other ideas?

1

There are 1 best solutions below

0
On

I wonder how are you able to get the current complication "accentColor" (I've ended up in your question because of that).

But for your original question, There's WidgetRenderingMode environment variable (since iOS 16 / watchOS 9).

So you can switch based on it. Here is the snippet from the link below:

@Environment(\.widgetRenderingMode) var renderingMode

var body: some View {
    ZStack {
       switch renderingMode {
        case .fullColor:
           Text("Full color")
        case .accented:
           ZStack {
               Circle(...)
               VStack {
                   Text("Accented")
                       .widgetAccentable()
                   Text("Normal")
               }
           }
        case .vibrant:
           Text("Full color")
        default:
           ...
        }
    }
}

https://developer.apple.com/documentation/swiftui/environmentvalues/widgetrenderingmode