How do I make the top part of the list to stay in place?
For example, here, I don’t want the upper part of the background to be allowed to slide up. In other words, the list should only be allowed to move downwards from its initial position.
import SwiftUI
import Foundation
struct Attendance: Identifiable {
let id = UUID()
let name: String
}
struct AttendanceRow: View {
var attendance: Attendance
var body: some View {
HStack {
Text(attendance.name)
}
.padding(.vertical, 20)
}
}
struct ContentView: View {
let attendances = [
Attendance(name: "John"),
Attendance(name: "Michael"),
Attendance(name: "Steve"),
Attendance(name: "Donald"),
Attendance(name: "Johathan"),
Attendance(name: "William"),
Attendance(name: "Dave"),
Attendance(name: "Richard"),
Attendance(name: "Boris"),
Attendance(name: "Catherine"),
Attendance(name: "Susan")
]
var body: some View {
NavigationView {
VStack {
List {
ForEach(attendances) { attendance in
AttendanceRow(attendance: attendance)
}
}
}
}
}
}