Post

Need to toggle between iconOnly and titleAndIcon label styles in SwiftUI? You can create your own custom LabelStyle and add some fun transition animations :D code below 👇

1 repost6 likes

The custom label style which takes in a isExpanded boolean and transitions with a matched geometry effect alongside an opacity and scale transition. You can customize this any way you want!

Thanks for sharing! You might even not need the matchedGeometryEffect. Unfortunately I wasn't able to pass a generic transition to make the toggle effect completely customised (or only provide an AnyTransition which does not include all transitions like blurReplace). cc @matt1corey.bsky.social

It comes down to a faulty assumption on my part - that a Label _should_ be able to smoothly adapt from one built-in style to another. Clearly, this isn't true. What bugs me is that I don't see a reason this assumption _shouldn't_ be true, but rather, I think it's simply a shortcoming of the API. 🧵