I have the same problem.
Post
Replies
Boosts
Views
Activity
link: https://stackoverflow.com/questions/62588015/swiftui-get-current-scroll-position-from-scrollview
struct DemoScrollViewOffsetView: View {
		@State private var offset = CGFloat.zero
		var body: some View {
				ScrollView {
						VStack {
								ForEach(0..<100) { i in
										Text("Item \(i)").padding()
								}
						}.background(GeometryReader {
								Color.clear.preference(key: ViewOffsetKey.self,
										value: -$0.frame(in: .named("scroll")).origin.y)
						})
						.onPreferenceChange(ViewOffsetKey.self) { print("offset >> \($0)") }
				}.coordinateSpace(name: "scroll")
		}
}
struct ViewOffsetKey: PreferenceKey {
		typealias Value = CGFloat
		static var defaultValue = CGFloat.zero
		static func reduce(value: inout Value, nextValue: () -> Value) {
				value += nextValue()
		}
}
You should first import WidgetKit in your file, and add the function reloadAllWidget below.
@objc public func reloadAllWidget() {
#if arch(arm64) arch(i386) arch(x86_64)
WidgetCenter.shared.reloadAllTimelines()
#endif
}
When you want to update timeline, you use
if #available(iOS 14.0, *) {
self.reloadAllWidget()
}
watching this to.
watching this too...