Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4.  
  5. @State private var bounds: Bounds = .zero
  6.  
  7. var body: some View {
  8. VStack {
  9. controls
  10. scrollArea
  11. }
  12. }
  13.  
  14. private var controls: some View {
  15. HStack {
  16. Text(verbatim: "\(bounds)")
  17. Spacer()
  18. Button("-100") {
  19. withAnimation {
  20. self.bounds.origin.y -= 100
  21. }
  22. }
  23. }
  24. }
  25.  
  26. private var scrollArea: some View {
  27. ScrollArea(bounds: $bounds) {
  28. VStack {
  29. ForEach(0..<50) { item in
  30. self.row(for: item)
  31. }
  32. }
  33. }
  34. }
  35.  
  36. private func row(for item: Int) -> some View {
  37. HStack {
  38. Text("Item: \(item)")
  39. .padding([.leading, .trailing])
  40. .background(Color.blue)
  41.  
  42. Spacer()
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement