swiftuisidebarstickynavigationsplitview

Declare bottom zone in a SwiftUI navigation sidebar below a list


In the below screenshots (taken from the Apple Developer app), we can see that the Account button sticks to the bottom of the sidebar.

When the window is tall enough (left), the list doesn’t scroll, Account button’s background color has no difference. When the window is not tall enough (right), causing the list to scroll, Account button changes its background color to reveal the relationship.

The list's scroll position can not be probed. How can I declare the Account button in SwiftUI?

enter image description here


Solution

  • That app is a UIKit catalyst app and the sidebar uses scrollViewDidScroll which uses the contentSize to set a bottomButtonState which is passed into a child UIHostingController (so the account button can be SwiftUI) which I would assume switches between a clear or solid background.

    We cant get the scroll info in SwiftUI however a possible workaround would be to add dummy 1 pixel high cell to the bottom of the list and using its onAppear to set a binding that is used in a bottom view to enable/disable a background colour and should achieve the same effect.