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

Request Feature #2

Open
webserveis opened this issue Jun 29, 2023 · 2 comments
Open

Request Feature #2

webserveis opened this issue Jun 29, 2023 · 2 comments

Comments

@webserveis
Copy link

Is posible recive encapsulate resposte, with ScrollStatus enum, for receive more info of scroll states

enum ScrollState {
    case idle
    case upScrolling
    case downScrolling

    func isScrolling() -> Bool {
        return self == .upScrolling || self == .downScrolling
    }
}
@webserveis
Copy link
Author

I testing with this

struct ScrollStatusMonitorCommonModifier: ViewModifier {
    @StateObject private var store = CommonStore()
    @Binding var isScrolling: Bool
    
    func body(content: Content) -> some View {
        var previousY: CGFloat = 0
        
        return content
            .environment(\.isScrolling, store.isScrolling)
            .onChange(of: store.isScrolling) { value in
                isScrolling = value
            }
            .onPreferenceChange(MinValueKey.self) { value in
                let currentY = value.origin.y
                print("currentY \(currentY) previousY \(previousY)")

                if currentY < previousY {
                    print("Scrolling Up")
                } else if currentY > previousY {
                    print("Scrolling Down")
                }
                previousY = currentY
                store.preferencePublisher.send(1)
            }
            .onDisappear {
                store.cancellable = nil
            }
    }
}

but sometimes I see that there is a small direction jump in the scroll X_o

@fatbobman
Copy link
Owner

Your approach is basically correct (by judging MinValueKey.self ).
The reason why there is no API to display the current scrolling direction is that MinValue cannot provide the correct state in any case. For example, you also found that sometimes the direction of the data is reversed. In addition, when scrolling to the top and bottom, there is a bounce, and the direction expression cannot be correctly expressed.

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

No branches or pull requests

2 participants