Skip to content

Add ScrollManager for programmatic control of ScrollViewWithStickyHeader #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

gabrielribeiro
Copy link
Contributor

@gabrielribeiro gabrielribeiro commented Apr 7, 2025

Summary

This PR introduces a ScrollManager class that enables programmatic scrolling within ScrollViewWithStickyHeader. It allows external code (e.g., view models or UI interactions) to scroll to the sticky header or the main content.

Key Changes

  • Added ScrollManager with scrollToHeader() and scrollToContent() APIs.
  • Updated ScrollViewWithStickyHeader to optionally accept a ScrollManager and register its internal ScrollViewProxy.
  • Added .id(...) identifiers to the header and content views for ScrollViewReader compatibility.
  • Maintained full backward compatibility — if no ScrollManager is passed, the behavior is unchanged.

Example Usage

Simulator Screen Recording - iPhone 16 Pro - 2025-04-07 at 18 47 00

private var scrollManager = ScrollManager()

ScrollViewWithStickyHeader(
    scrollManager: scrollManager,
    header: { /* ... */ },
    content: { /* ... */ }
)

Button("Scroll to Header") {
    scrollManager.scrollToHeader()
}

Motivation

I just wanted to programmatically show or hide the header!

Let me know if you'd like any changes, doc, tests... Happy to help!

Copy link
Owner

@danielsaidi danielsaidi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow @gabrielribeiro this looks amazing, thank you! I will merge this into main and release it in a new version tomorrow.

@gabrielribeiro
Copy link
Contributor Author

Thank you, Daniel! I'm glad that you liked it!!!

@danielsaidi danielsaidi force-pushed the main branch 2 times, most recently from a952166 to c3d4635 Compare April 9, 2025 05:08
@danielsaidi
Copy link
Owner

Hi @gabrielribeiro

I was going to merge this for the 0.7 release, but see now that my ScrollViewWithStickyHeader changes has caused some merge conflicts. Would you be able to take a look? Sorry for the additional work.

@gabrielribeiro
Copy link
Contributor Author

Opened a new one due to conflicts: #27

@gabrielribeiro gabrielribeiro deleted the feature/scroll-manager branch April 9, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants