danielsaidi / ScrollKit

ScrollKit is a SwiftUI SDK that adds powerful scroll features, like offset tracking and a header view that stretches & transforms as you pull down, and sticks to the top when you scroll.
MIT License
660 stars 22 forks source link

How to center placeholder with ScrollViewWithStickyHeader #17

Open OuSS-90 opened 3 months ago

OuSS-90 commented 3 months ago

I am using ScrollViewWithStickyHeader and want to center placeholder when list is empty. I tried to add empty placeholder with maxHeight infinity but still not centered. How can i do this ?

danielsaidi commented 3 months ago

How do you mean, that the header should be centered on screen when there's no content in the list?

There's nothing built-in for this, so I suggest perhaps switching between two views?

OuSS-90 commented 3 months ago

My scenario: header: is carousel of items content: is List of element

When user select item from carousel, I need to load list of element related to that item, sometimes there is no elements so I need to add empty placeholder with icon saying "There is no elements" centered inside content space

My issue: I added this placeholder but it's under header not centered

danielsaidi commented 3 months ago

I see! In this case, can't you just add a centered overlay above the list?

OuSS-90 commented 3 months ago

It will not be centered cause my list its just lazyVstack inside ScrollViewWithStickyHeader. It don’t take full space under header

danielsaidi commented 3 months ago

What if you apply .frame(maxHeight: .infinity) to your stack, to make it take up all available height?

Regardless, I'd say that this is not a ScrollKit-related issue, so I'm closing this.

OuSS-90 commented 3 months ago

It's related to ScrollKit, because content (my LazyVStack) is inside scrollView (ScrollViewWithStickyHeader), so .frame(maxHeight: .infinity) don't work

danielsaidi commented 3 months ago

I see, thank you for clarifying!

I'll reopen this so that we can keep track of it.

danielsaidi commented 2 months ago

@OuSS-90 Can you wrap the scroll view in a geometry reader to get the total available height, then inject that height into the scroll view content, and reduce the current header height to determine how tall the content should be?

Regardless, you'd have the same challenge with any native scroll view, where .frame(maxHeight: .infinity) doesn't work, since the scroll view itself isn't greedy.