Skip to content

Instantly share code, notes, and snippets.

@literalpie
Created June 28, 2020 13:48
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 literalpie/aaccf76cd49918423ceccb9341b708ed to your computer and use it in GitHub Desktop.
Save literalpie/aaccf76cd49918423ceccb9341b708ed to your computer and use it in GitHub Desktop.
struct ListTransitionView: View {
@State var pickedNumber: Int?
@Namespace var namespace
var body: some View {
VStack {
if pickedNumber == nil {
VStack(spacing: 15) {
ForEach(0..<3) { number in
Button("Hello world \(number)") {
withAnimation {
pickedNumber = number
}
}
.frame(width: 300, height: 30, alignment: .center)
.padding()
.border(Color.black, width: 1)
.matchedGeometryEffect(id: number, in: namespace)
}
}
} else {
ForEach(0..<3) { number in
if pickedNumber == number {
ZStack {
Rectangle().foregroundColor(.blue).cornerRadius(30)
Button("Back") {
withAnimation {
pickedNumber = nil
}
}
.padding()
.foregroundColor(.black)
}
.matchedGeometryEffect(id: number, in: namespace)
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment