2

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

Baoshan Sheng
  • 2,635
  • 1
  • 11
  • 11

1 Answers1

3

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.

malhal
  • 26,330
  • 7
  • 115
  • 133
  • Thanks for the explanation! I can not reproduce a stable proof-of-concept using the appear/disappear technique. When the window is launching with enough height, it seems that `onDisappear` is not triggered at all when the window is resized. – Baoshan Sheng Sep 26 '22 at 03:01
  • Because cells are reused they don't have appear/disappear you expect without marking them as equatable, see https://stackoverflow.com/a/73814218/259521 if that doesn't fix it then I can attempt a proof of concept for you. – malhal Sep 26 '22 at 09:59