Skip to content
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

ScrollViewHeader behaves strangely with presentationDetents #3

Open
morluna opened this issue Mar 14, 2023 · 3 comments
Open

ScrollViewHeader behaves strangely with presentationDetents #3

morluna opened this issue Mar 14, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@morluna
Copy link

morluna commented Mar 14, 2023

When presenting a sheet with presentation detents, the sticky header functionality breaks a bit because the header tries to grow to the top of the screen, but the presentationDetent cuts it off.

The stretchiness functionality doesn't necessarily need to work on small detents, but would be nice for the header to stick to the top.

Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-03-14.at.08.51.58.MP4
@danielsaidi
Copy link
Owner

@morluna I think that maybe the stretch should be disabled altogether when being presented in a sheet. Do you know if it's possible to detect whether or not the view is in a sheet?

@danielsaidi danielsaidi added the bug Something isn't working label Mar 14, 2023
@morluna
Copy link
Author

morluna commented Mar 14, 2023

@danielsaidi On the parent view, you could just use .presentationDetents(:selection:) and a state property to know when it changed.

There isn't a way for nested views (like the scroll view with sticky header) to know what presentation detent it's on out of the box, but maybe you can created a custom environment property for it?

struct PresentationDetentPreferenceKey: PreferenceKey {
    static var defaultValue: PresentationDetent = .large
    static func reduce(value: inout PresentationDetent, nextValue: () -> PresentationDetent) {
        value = nextValue()
    }
}
struct PresentationDetentEnvironmentKey: EnvironmentKey {
    static let defaultValue: PresentationDetent = .large
}
extension EnvironmentValues {
    var presentationDetent: PresentationDetent {
        get { self[PresentationDetentEnvironmentKey.self] }
        set { self[PresentationDetentEnvironmentKey.self] = newValue }
    }
}

@danielsaidi danielsaidi added this to the 0.5 milestone Dec 10, 2023
@danielsaidi danielsaidi removed this from the 0.5 milestone May 30, 2024
@danielsaidi
Copy link
Owner

I will fix this the next time I use the view in a way that causes this problem, but I'll be happy to review any PRs that fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants