Skip to content

Instantly share code, notes, and snippets.

@phillipcaudell
Created December 8, 2023 12:48
Show Gist options
  • Save phillipcaudell/b5cb0e8b90fcfee922e4511e697b81f2 to your computer and use it in GitHub Desktop.
Save phillipcaudell/b5cb0e8b90fcfee922e4511e697b81f2 to your computer and use it in GitHub Desktop.
ListFocus
struct RootView: View {
@State var items: [Int] = [0,1,2]
@State var selected: Int?
@State var detailView: Bool = false
var body: some View {
VStack {
List(items, id:\.self, selection: $selected) { index in
Text("\(index)")
.tag(index)
}
Button(action: {
detailView = true
}, label: {
Text("detail view")
})
}
.frame(width: 300, height: 420, alignment: .top)
.background()
.onAppear {
selected = 0
}
.overlay {
if detailView {
VStack {
Button(action: {
detailView = false
}, label: {
Text("Exit")
})
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment