Created
January 5, 2022 18:51
-
-
Save Gernot/72a37e52d24d2b5d0c051cc1767bc63a to your computer and use it in GitHub Desktop.
List like transitions for VStacks?
This file contains hidden or 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
import Foundation | |
import SwiftUI | |
import PlaygroundSupport | |
let allTexts = ["one", "two", "three", "four", "five"] | |
let selectedTexts = ["two", "four"] | |
struct TestView: View { | |
@State private var expanded = false | |
var body: some View { | |
VStack { // <- Replace with "List" to see what I want | |
ForEach(expanded ? allTexts : selectedTexts, id:\.self) { text in | |
Text(text) | |
} | |
} | |
.animation(.default, value: expanded) | |
.onTapGesture { expanded.toggle() } | |
.frame(width: 300, height: 600) | |
} | |
} | |
PlaygroundPage.current.setLiveView(TestView()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to propose that but thought that if
allTexts
andselectedText
change with a common addition the common addition would animate in in the undesired way. But if that won't happen, then I think that solution looks really nice.