Skip to content

Commit

Permalink
Fix TimeZonePickerView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jan 3, 2025
1 parent bebfda7 commit ca9ee96
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/TrueWidget/swift/Views/TimeZonePickerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,25 @@ struct TimeZonePickerView: View {

@ObservedObject private var source = Source.shared
@Binding private(set) var abbreviation: String
// If passing $abbreviation directly to the Picker's selection, changes may not be reflected in the Picker because $abbreviation might not be an ObservableObject.
// Instead, pass $value to the Picker and manually update the changes.
@State private(set) var value: String

init(abbreviation: Binding<String>) {
self._abbreviation = abbreviation
self.value = abbreviation.wrappedValue
}

var body: some View {
Picker("", selection: $abbreviation) {
Picker("", selection: $value) {
ForEach(source.timeZones) { timeZone in
Text(timeZone.label)
.tag(timeZone.abbreviation)
}
}
.pickerStyle(.menu)
.onChange(of: value) { _ in
abbreviation = value
}
}
}

0 comments on commit ca9ee96

Please sign in to comment.