wwdc2023-10162 - Grid Navigation on macOS

In the video 'The SwiftUI cookbook for focus" a key detail is left out.

https://developer.apple.com/videos/play/wwdc2023/10162/?time=1130

selectRecipe has no code provided meaning it leaves out a vital detail, how to handle up and down keyboard presses.

If a LazyVGrid has 4 items per row with the current shape of the window and the user presses the down key, how is the application supposed to know which item is directly underneath the currently focused one? Or if they press up and they need to know which is directly above? What happens when the user resizes the window and the number of items per row changes?

This would seem to require knowing the exact current layout of the window to return the correct recipe ID. The code provided isn't wrapped in a complex GeometryReader so I assume there's some magic I am missing here.

I am trying to create a similar LazyVGrid that can be navigated with the keyboard as with the recipes grid here but have no means of implementing .onMoveCommand in such a way that makes sense.

At the moment, SwiftUI seems to be intentionally built in such a way to defy all attempts to implement keyboard navigation.

wwdc2023-10162 - Grid Navigation on macOS
 
 
Q