Skip to content

Instantly share code, notes, and snippets.

@CastIrony
Created July 22, 2020 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CastIrony/2e5c06ed128fe50d7377d3b848e6bf29 to your computer and use it in GitHub Desktop.
Save CastIrony/2e5c06ed128fe50d7377d3b848e6bf29 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// ScrollViewTest
//
// Created by Bernstein, Joel on 7/21/20.
//
import SwiftUI
struct ContentView: View {
@State var ids: [Int] = [1]
var body: some View {
NavigationView {
ScrollView {
VStack {
ForEach(ids, id: \.self) { id in
Text("\(id)")
.font(Font.largeTitle.bold())
.foregroundColor(.white)
.padding([.top, .bottom], 50)
.frame(maxWidth: .infinity)
.background(Color.green)
.padding(.all, 10)
.onTapGesture {
withAnimation { ids.removeAll { $0 == id } }
}
}
}
.frame(maxWidth: .infinity)
.background(Color.blue)
}
.navigationBarTitle("List", displayMode: .inline)
.toolbar {
ToolbarItem {
Button("Add") { withAnimation { ids.append((ids.last ?? 0) + 1) } }
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment