Created
July 22, 2020 03:51
-
-
Save CastIrony/2e5c06ed128fe50d7377d3b848e6bf29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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