The array of items is ordered so that new items are at index 0.
I want the scroll behavior of the ScrollView completely reversed so the newest item 0 is shown at the bottom, and the user must scroll new items down to slide older items in from the top of the scrollview.
Old items are dynamically added when the last item in the array appears.
Here's what I have so far and it works, but the 180 rotation effect just seems inelegant. I feel like this is creative hackery and there just must be a better way.
import SwiftUI
struct MyReversedScrollView: View {
@State var items: [Int]
init() {
_items = State(initialValue: Array(1...10))
}
var body: some View {
ScrollView() {
LazyVStack(spacing: 10) {
ForEach(items, id: \.self) { item in
ItemView(item: item)
.zIndex(Double(items.count - item))
.onAppear {
if items.last == item {
items += Array((item+1)...(item+10))
}
}
}
}
}
.rotationEffect(.degrees(-180))
}
}
struct MyReversedScrollView_Previews: PreviewProvider {
static var previews: some View {
MyReversedScrollView()
}
}
struct ItemView: View {
let item: Int
var body: some View {
Text(item.description)
.frame(width: 100, height: 100)
.border(Color.black)
.rotationEffect(.degrees(-180))
}
}