Trying to find a way how to get scroll view's scroll offset using GeometryReader. The view hierarchy I am after is Scrollview with custom view. Custom view (TileCollectionView) defines its size itself (it is custom collection/tile view with fixed number of columns).
struct ContentView: View {
var body: some View {
VStack {
Text("Scoll location")
ScrollView([.horizontal, .vertical]) {
GeometryReader { geometry -> TileCollectionView in
print(geometry.frame(in: .global))
return TileCollectionView()
}
}
}
}
}
struct TileCollectionView: View {
var body: some View {
VStack(spacing: 1) {
ForEach(0..<30) { seriesIndex in
HStack(spacing: 1) {
ForEach(0..<8) { columnIndex in
TileView()
}
}
}
}
}
}
struct TileView: View {
var body: some View {
Color.blue.frame(width: 128, height: 128, alignment: .center).fixedSize()
}
}What happens with this code is GeometryReader making the view size matching with ScollView size and it is not possible to scroll from one edge to another edge of the TileCollectionView. Wondering how to setup the view so that ScrollView's content size matches with TileCollectionView's size and I am able to read the current scroll offset.
In addition, it seems like it is impossible to scroll the ScrollView to the bottom of the document. No API for that (can't find any allowing to change scroll offset programmatically)?
This code cand be tested by just creating SwiftUI template project and replacing ContentView with code shown here.