Skip to content

Add ScrollManager for programmatic control of ScrollViewWithStickyHeader [solved conflict] #27

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

Conversation

gabrielribeiro
Copy link
Contributor

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!

@gabrielribeiro
Copy link
Contributor Author

@danielsaidi , created a new one!

@danielsaidi
Copy link
Owner

Thank you, I will review it today and release it as a 0.8 update 👍

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.

I love this!

@danielsaidi danielsaidi merged commit 93c96b0 into danielsaidi:main Apr 10, 2025
1 check passed
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