gh123man / SwiftUI-Refresher

A native, customizable SwiftUI refresh control
MIT License
129 stars 12 forks source link

export offset using @Binding #9

Closed distivi closed 9 months ago

distivi commented 1 year ago

Hi there, thanks for the lib!

As this view makes some work already to get scrollView offset, i'm wondering if you can expose offset value using @Binding or closure? That would be super helpful for making parallax-like effects for headers etc.

gh123man commented 1 year ago

Currently you can access the percentage (0 - 1) of of how far along the pull gesture is via RefreshState.dragPosition

You can access this struct by providing a custom refreshView - in the example it's implicitly passed to the default constructor. However you should be able to explicitly capture it with something like:

.refresher(refreshView: { $state in
    return DefaultRefreshView(state: $state)
        // Do something with state.dragPosition
        .onChange(of: state.dragPosition) { newPosition in
            print(newPosition)
        }
}) { ...

Or you can implement your own custom refresh view similar to the example that captures and uses the RefreshState struct.

Let me know if this works for your use case. If you need an explicit offset, I can add that as well - but you may be able to derive the offset you need from the dragPosition