Are you seeing a weird change in text and image styles when you dismiss a SwiftUI popover?

Development / iOS / Making of Captionista

Another one from the “building Captionista” files, I noticed that on iPad any Text inside a popover that has no explicit font will change weight/size when the popover is dismissed, also affecting the layout. You only see it briefly when you tap away from the popover, but it looks bad!

Note that the same problem applies to imageScale so it looks like there is something in the environment that changes when the popover dismiss begins.

Workaround: Add .font(.body) or similar on the elements so you’re not relying on any defaults in the View hierarchy.

SwiftUI Popover replaces existing popover without moving it or pointing it at the correct view

Development / iOS / Making of Captionista

While building our new subtitling app Captionista we changed the UI to have a couple of buttons in the navigation bar that show popups on iPad.

I hit another fun bug with Popovers in SwiftUI: if you have multiple UI elements that can show a popover, if the user does not dismiss the previous popover, the next one will be shown in the previously active popover.

Unfortunately SwiftUI replaces the previous popover content but does not move the popover on iPad to point at the correct UI element, which is very bad.

Workaround: None that I know of yet.

There’s a feedback: FB8889229 “With SwiftUI, opening a new popover on iPad when the previous is still active, replaces the content of the old popover”

Colouring the arrow of a Popover in SwiftUI

Development / iOS / Making of Captionista

If you have custom background colours or e.g. force dark mode on your View as we do in Captionista, you will be sad to discover that the popover in SwiftUI draws the arrow without allowing you to colour it. If you use a NavigationView this is hidden from you as the navigation bar “fills” the arrow space also, but if you don’t… you end up with the system background colour in the arrow, and your custom colour in the body of the popover.

Read More

Me: “Why is my SwiftUI view not updating when the model changes?”

Development / iOS / Making of Captionista

The initialisers of Views in SwiftUI have some surprising and obscure behaviours related to state. If you’ve used SwiftUI at all you will likely have discovered this.

In addition, the rules around how properties that are wrapped with Property Wrappers are accessed are interesting when inside the initialiser of the type. It is this latter issue that bit me.

Read More