Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Sources/Showcase/FocusStatePlayground.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI
struct FocusStatePlayground: View {
@State var textA = ""
@State var textB = ""
@State var textC = ""

@FocusState var focusBool: Bool
@FocusState var focusEnum: FocusField?
Expand All @@ -18,15 +19,43 @@ struct FocusStatePlayground: View {
.focused($focusEnum, equals: .textA)
TextField("textB", text: $textB)
.focused($focusEnum, equals: .textB)

ChildTextField(
title: "textC",
value: $textC,
focusedField: $focusEnum,
assignedFocusField: FocusField.textC
)

Button("Set focus to A via Boolean") { focusBool = true }
Button("Set focus to A via Enum") { focusEnum = .textA }
Button("Set focus to B via Enum") { focusEnum = .textB }
Button("Set focus to C via Enum") { focusEnum = .textC }
Button("Nil Enum") { focusEnum = nil }
}
}
}

struct ChildTextField: View {

let title: String
@Binding var value: String

#if !SKIP
@FocusState.Binding var focusedField: FocusField?
#else
@Binding var focusedField: FocusField?
#endif
Comment on lines +44 to +48
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aabewhite Do you think we could just typealias FocusState.Binding to Binding in SkipUI? I'm unclear on why FocusState.Binding exists at all.

let assignedFocusField: FocusField

var body: some View {
TextField(title, text: $value)
.focused($focusedField, equals: assignedFocusField)
}
}

enum FocusField: Int {
case textA
case textB
case textC
}
3 changes: 3 additions & 0 deletions Sources/Showcase/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,9 @@
},
"Set focus to B via Enum" : {

},
"Set focus to C via Enum" : {

},
"Settings" : {
"localizations" : {
Expand Down
Loading