ScrollKit icon indicating copy to clipboard operation
ScrollKit copied to clipboard

How to center placeholder with ScrollViewWithStickyHeader

Open OuSS-90 opened this issue 1 year ago • 8 comments

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 ?

OuSS-90 avatar May 06 '24 02:05 OuSS-90

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?

danielsaidi avatar May 08 '24 12:05 danielsaidi

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

OuSS-90 avatar May 08 '24 16:05 OuSS-90

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

danielsaidi avatar May 10 '24 08:05 danielsaidi

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

OuSS-90 avatar May 10 '24 12:05 OuSS-90

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.

danielsaidi avatar May 10 '24 12:05 danielsaidi

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

OuSS-90 avatar May 10 '24 17:05 OuSS-90

I see, thank you for clarifying!

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

danielsaidi avatar May 21 '24 09:05 danielsaidi

@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.

danielsaidi avatar May 30 '24 07:05 danielsaidi

Closing this due to inactivity.

danielsaidi avatar Feb 17 '25 12:02 danielsaidi