Skip to content

Instantly share code, notes, and snippets.

View twstokes's full-sized avatar
📱
LOAD "*",8,1

Tanner Stokes twstokes

📱
LOAD "*",8,1
View GitHub Profile
@insidegui
insidegui / ScrollViewOffsetModifier.swift
Created July 20, 2021 20:28
A SwiftUI ViewModifier that can be used to read a ScrollView's offset and store it into a @State property of the view
struct ScrollViewOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {
value = nextValue()
print("value = \(value)")
}
typealias Value = CGPoint