-
-
Save phillipcaudell/b5cb0e8b90fcfee922e4511e697b81f2 to your computer and use it in GitHub Desktop.
ListFocus
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 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