SwiftUIMaterialTabs icon indicating copy to clipboard operation
SwiftUIMaterialTabs copied to clipboard

Header behavior - Help

Open oiledCode opened this issue 6 months ago • 8 comments

This isn't really an issue, but more an help request.

I am trying to use the library in my project, however I was wondering if and how I could support / add a different behavior to hide and show the title.

Basically what I would like is when the user is scrolling down (swiping up) hide the title an keep tabs sticky, when the user is scrolling up (scrolling treshold??) showing again the title even if the offset of the current scrollable content did not reach 0. More or less the behavior that we see on the navigationBar when hidesBarsOnSwipe is set.

Do you think this will be possible, if yes could you point me in the right direction? I'm willing to make the modification myself in a fork.

Thanks in advance for your help and for open sourcing this library

oiledCode avatar Jun 23 '25 07:06 oiledCode

Looking into this. I think I understand, but just to confirm:

  1. When scrolling down, the header shrinks the way it does currently by following the scroll one-to-one
  2. When scrolling up by some threshold, the header expands back to full size immediately

Is that right?

wtmoose avatar Jun 25 '25 16:06 wtmoose

Closing this. Reopen if and when you're ready to resume the discussion

wtmoose avatar Jul 07 '25 15:07 wtmoose

Sorry, but somehow I did not get a notification when you replied. However you got it right

oiledCode avatar Jul 08 '25 06:07 oiledCode

I have an initial implementation on the branch work/snap if you'd like to take a look and give me your input. Right now, it only works with StickyHeader. For MaterialTabs, I still need to do some work to maintain proper state when switching between tabs.

https://github.com/user-attachments/assets/ee87c07c-8fef-40b7-9c52-498d2789e58b

wtmoose avatar Jul 15 '25 18:07 wtmoose

To be clear, you can test it in your app with tabs, but there might be some glitchy behavior when switching between tabs. From the change log:

2.0.7

Improvements

  • Implement #21 - Add scroll-up snap behavior for sticky headers. When enabled, the header automatically snaps to fully expanded state after detecting scroll-up intent, making it easier to reveal collapsed headers without extensive scrolling.
// Enable snap-to-expanded behavior
MaterialTabs(
    config: MaterialTabsConfig(
        headerConfig: HeaderConfig(scrollUpSnapMode: .snapToExpanded)
    )
) { }

// Or for StickyHeader
StickyHeader(
    config: HeaderConfig(scrollUpSnapMode: .snapToExpanded)
) { }

wtmoose avatar Jul 15 '25 18:07 wtmoose

@wtmoose I will try it later today, an I will let you know. Anyway thank you for having spent time on this one

oiledCode avatar Jul 16 '25 07:07 oiledCode

@oiledCode are you still interested in this feature?

wtmoose avatar Aug 12 '25 16:08 wtmoose

@wtmoose I'm interested in the feature! I think it makes sense to have the ability to snap headers in place without having to scroll so much.

J6ey avatar Oct 01 '25 06:10 J6ey