Skip to content

Commit

Permalink
Simplify focus state binding
Browse files Browse the repository at this point in the history
  • Loading branch information
rachelmcr committed Jan 9, 2025
1 parent 9e28ee3 commit 3c50700
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ struct WooShippingEditAddressView: View {
@Binding var text: String

/// The focused state of the field.
var focused: FocusState<AddressField?>.Binding

/// Whether the field is focused.
private var isFocused: Bool {
focused.wrappedValue == field
}
@FocusState.Binding var focused: AddressField?

var body: some View {
VStack(spacing: Constants.innerSpacing) {
Expand All @@ -93,11 +88,11 @@ struct WooShippingEditAddressView: View {
.font(.subheadline)
.foregroundStyle(Color(.text))
TextField(field.title, text: $text, prompt: Text(field.required ? "" : Localization.optional))
.focused(focused, equals: field)
.focused($focused, equals: field)
.padding()
.roundedBorder(cornerRadius: Constants.cornerRadius,
lineColor: isFocused ? Color(.accent) : Color(.separator),
lineWidth: isFocused ? 2 : 1)
lineColor: focused == field ? Color(.accent) : Color(.separator),
lineWidth: focused == field ? 2 : 1)
}
}
}
Expand Down

0 comments on commit 3c50700

Please sign in to comment.