Skip to content

Instantly share code, notes, and snippets.

@phillipcaudell
Created May 8, 2023 08:52
Show Gist options
  • Save phillipcaudell/a125708c3075abcabe9940427c57d1a3 to your computer and use it in GitHub Desktop.
Save phillipcaudell/a125708c3075abcabe9940427c57d1a3 to your computer and use it in GitHub Desktop.
Arghhh. Another #SwiftUI regression in 16.4: NavigationSplitView won’t animate the first push of the detail column if the content column goes from List, to no List. Again, this worked just fine in prior releases!
import SwiftUI
enum FruitSuggestion: String, Identifiable, CaseIterable {
case apple, banana, orange
var id: Self { self }
}
struct AppView: View {
@State private var selection: FruitSuggestion?
@State private var contentSelection = Set<Int>()
var body: some View {
NavigationSplitView {
SidebarView(selection: $selection)
} content: {
if let content = selection {
switch content {
case .apple:
Text("Apple View")
case .banana:
Text("Banana View")
case .orange:
ContentView(fruit: content, rowSelection: $contentSelection)
}
} else {
Text("Nothing selected")
}
} detail: {
if let row = contentSelection.first {
DetailView(row: row)
} else {
Text("No Item Selected")
}
}
}
}
struct SidebarView: View {
@Binding var selection: FruitSuggestion?
var body: some View {
List(selection: $selection) {
ForEach(FruitSuggestion.allCases) {
NavigationLink($0.rawValue, value: $0)
}
}
.navigationTitle("Sidebar")
}
}
struct ContentView: View {
let fruit: FruitSuggestion?
@Binding var rowSelection: Set<Int>
var body: some View {
List(selection: $rowSelection) {
ForEach(0...20, id: \.self) { id in
NavigationLink(value: id) {
Text("Row \(id)")
}
}
}
.navigationTitle(fruit?.rawValue ?? "")
}
}
struct DetailView: View {
let row: Int
var body: some View {
Text("Detail View \(row)")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
AppView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment