Post

Replies

Boosts

Views

Activity

Reply to Having trouble transitioning list onto screen.
import SwiftUI struct Search: Identifiable { let id: UUID let text: String } struct SearchBox: View { @State var searchParam: String = "" @State var stuff = [Search]() @State var showList = false init() { // To remove only extra separators below the list: UITableView.appearance().tableFooterView = UIView() // To remove all separators including the actual ones: UITableView.appearance().separatorStyle = .none } var body: some View { var binding = Binding<String>( get: { self.searchParam }, set: { self.stuff.append( Search(id: UUID(), text: $0) ) self.searchParam = $0 withAnimation { self.showList = self.stuff.count > 0 } }) return VStack(spacing: 0.0) { TextField("Search", text: binding ) .font(.title) .padding() .background(Color.white) if stuff.count > 0 { List { Text("foo") } .transition(.slide) } } } struct SearchBox_Preview: PreviewProvider { static var previews: some View{ SearchBox() } } }I had to change my state in a withAnimation block. That allowed the animation to happen.
Jan ’20