I'm a little embarrassed to admit, but I had been blissfully unaware that View extensions are type erasing.
That means if you have an extension for using your ViewModifier in a more ergonomic way, it'll be erased to AnyView unless you explicitly mark it as @inlinable.
https://gist.github.com/phillipcaudell/df04ebf01e9579a308e3534ac829a540
Edit: Perhaps this is just a quirk of Xcode Previews: https://mastodon.notsobig.co/@phill/111051676536041177
NavigationStack loses its navigation bar on iPad when returning from the background, making it impossible to go back or do anything. iOS 16 and 17.
FB13120953
https://gist.github.com/phillipcaudell/f6258c1fbac69a9fb2cd030fadd087de
Something that tripped me up recently was not understanding how .onAppear { } behaves on iPad.
It gets called multiple times, even though the view is not visible.
Why? Logging reveals the size class is also changing, so presumably iOS is taking snapshots for the app switcher.
If like me you rely onAppear to denote a user has seen something (say, Mark as Read), you'll need to check the scenePhase first.
Here's a gist: https://gist.github.com/phillipcaudell/290eab2c42c4cc27cfdc0c595b40654d
Here’s one weird #SwiftUI trick Apple DON'T want you to know:
If you present a confirmation dialogue from a swipeAction or contextMenu nothing will happen as the view is removed before the dialogue is presented. Annoying, but it makes sense.
Instead, delegate the confirmation to the environment. Now the Button isn't responsible for the presentation and you're left with a nice clean call site.
Here's my implementation with an example: https://gist.github.com/phillipcaudell/ecb32dc5a3915931d225a6cb8a67ac34
Man, NavigationSplitView is *still* broken in iOS 17 beta 7.
I reported back in May (FB12178616) that when in compact mode transitions become sporadic and stop working. This code is verbatim from Apple’s docs and it doesn't work.
This broke back in iOS 16.2. It seems nuts to me something so significant can stay broken for this long (and on a relatively new API?!)
https://gist.github.com/phillipcaudell/4cc223bec9a18970aed489d06580a56d
I recently got downvoted into oblivion for explaining why someone's List animation was glitching, perhaps because the solution is so simple it seems stupid.
On the left is swipeAction with a Button. On the right is the exact same Button, but now the animation is smooth.
The difference? I set the Button's role to destructive. SwiftUI uses the role to infer what animation to use. https://gist.github.com/phillipcaudell/e4ee5057dc33f92ed80b817762726275
As of beta 6 it seems to be reporting the wrong value if more than one row is selected on iPad.
I've filed a feedback for any Apple folk who see this 👉 FB13014204
Happy to see iOS 17 now gives our views a way to respond to the List selection style.
By reading the backgroundProminence value in the environment our custom controls, say an unread indicator, can adjust their tint as not to be occluded by the background: https://gist.github.com/phillipcaudell/e2ca686fcd6744b8341ac54f240a7798
Blahhh, it also looks like toolbar customisations are reset when the view identity changes. It works on iPad so I’m not sure if it's intentional (plus seems like it would defeat the purpose of specifying a toolbar identifier?)
No customisation on the Mac for now then 😢
https://gist.github.com/phillipcaudell/503ea2d3e2e7101b41a44f1c747387ad
Here's a fun SwiftUI bug: customisable toolbars on the Mac won't persist changes if there's a searchable modifier in the view hierarchy. Remove search, works fine.
🤷♂️
https://gist.github.com/phillipcaudell/349f1cb1ef6cef530276d6248306d28b (FB12999760)
#SwiftUI I'm stumped on how to add an undo keyboard shortcut on iPad. I'm using the environment's UndoManager. On the Mac, Undo appears in the Edit menu and "just works”.
I tried adding my own button, but UIKit throws a messaging saying it's duplicate, so I assume there is one but it's hidden?
Any ideas would be very much appreciated!
I wrongly assumed the format panel used in Mail was a system control like it is on macOS; but alas it isn't!
It ended up being a lot of fun recreating it, including the silly stretching/rubber-banding when you pull it.
🏳️🌈 Founder / Maker
Building that new email app.
Swift and rollercoasters are my thing.
Recovering VC.