Created
January 20, 2023 14:28
-
-
Save yannxou/90471044a45167a4c1568308f7553323 to your computer and use it in GitHub Desktop.
Pass FocusState property to child views
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
// source: https://developer.apple.com/forums/thread/682448 | |
struct Parent: View { | |
@FocusState var focusedField: UUID? | |
var body: some View { | |
VStack { | |
Child(focusedField: _focusedField) | |
} | |
} | |
} | |
struct Child: View { | |
@FocusState var focusedField: UUID? | |
@State var someText: String = "" | |
@State var someTextFieldUUID: UUID = UUID() | |
var body: some View { | |
VStack { | |
TextField("Focusable field", text: $someText) | |
.focused($focusedField, equals: someTextFieldUUID) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment