SwiftUI Weekly - Issue #239
The curated collection of links about SwiftUI. Delivered every Monday.
Building adaptive non-modal panels in SwiftUI
In our walking app Strolly, we make heavy use of non-modal sheets with small and medium detents so users can interact with the map and its controls at the same time. Until recently, the app only supported portrait orientation on iPhone. As part of our latest update, we wanted to support landscape layouts in preparation for the app resizability requirements coming with iOS 27. The system sheet API does not preserve its non-modal presentation when an iPhone rotates to landscape, so we had to find another solution.
Scalable Custom Fonts in SwiftUI
Custom fonts were one of those taboo topics for me. I didn't know how to utilize them properly. I would add custom fonts to a project, and set very specific font sizes and weights to make the view pixel perfect... on one device. Later I learned about preferred font sizes and how they worked. It kinda rocked my world. Afterwards, I was able to please both our users and creatives with UIFont extensions in UIKit.
Concentric Buttons with OS 27's SwiftUI APIs
SwiftUI for iOS, iPadOS, and macOS 27 (I'll shorten this to *OS 27 from here on) is bringing a lot of new additions. One particular addition that is very interesting to me is the ability to read out concentricCornerRadii on a GeometryProxy. I smelled that this might be a possibility to create a truly concentric button shape. Since the introduction of corner concentricity, I was eagerly waiting for a dedicated ButtonBorderShape which respects the corners. Until now, every update has left me disappointed. Even with *OS 27, SwiftUI still misses a first-class shape, but now we have the opportunity to create our own solution that merges into the standard SwiftUI APIs, hiding our custom implementation as well as possible.
Managing focus in SwiftUI with FocusState
SwiftUI provides the @FocusState property wrapper to observe and control focus in a view hierarchy. We can use it to focus a text field programmatically, move focus between fields, or remove focus to dismiss the keyboard.
Geometry, compositing and drawing groups in SwiftUI
SwiftUI provides three modifiers with very similar names that group views for different purposes. The geometryGroup() modifier isolates a view's geometry from its parent. The compositingGroup() modifier wraps a view in a compositing group, so compositing effects from outside the group, such as opacity and blend modes, operate at that boundary. The drawingGroup(opaque:colorMode:) modifier flattens supported content into an offscreen image before display. Understanding which part of the rendering process is being grouped helps us choose the right modifier for each situation.
