Chapter 11.4: Highlighting active style sheet - any changes?

Highlighting active style sheet using Text(style.rawValue).foregroundColor(style == styleSheet ? .accentColor : .primary) doesn’t work under Ventura Beta 5. I’m not sure whether this modifier is also ignored for menu items.

I have seen the same thing and reported it.

Since menu items already ignore a lot of modifiers, this may be what Apple intends now, or it may be a bug that is fixed later on in the beta cycle.

Thanks for the report,
Sarah

2 Likes

Thank you, also for the excellent book!

I’m not sure whether there’s an equivalent to UIMenuElement.State in SwiftUI.

I tried using a Label with a checkmark image, but images are not displayed in menus. But this seems to work:

HStack {
  Image(systemName: style == styleSheet ? "circle.fill" : "circle")
  Text(style.rawValue)
}

In SwiftUI, the equivalent of using a menu item’s state is to use a Toggle, like in Chapter 3.

This works perfectly for a Boolean property but when selecting from several options, the data handling would get very messy, even though the look and feel would be perfect.

And I’m glad you’re enjoying the book. It was a lot of fun to write.

Sarah

This now works again under Ventura beta 6.
Actually, it seems to work better as the accentColor is correctly shown instead of showing some variant.

Yes!
Thanks again for the book - looking forward to the next release :slight_smile:

1 Like