GithubHelp home page GithubHelp logo

Request Feature about isscrolling HOT 2 OPEN

webserveis avatar webserveis commented on July 17, 2024
Request Feature

from isscrolling.

Comments (2)

fatbobman avatar fatbobman commented on July 17, 2024 1

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.

from isscrolling.

webserveis avatar webserveis commented on July 17, 2024

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

from isscrolling.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.