Comments (2)
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from isscrolling.