Created
June 28, 2020 13:48
-
-
Save literalpie/aaccf76cd49918423ceccb9341b708ed 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
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