@@ -12,6 +12,9 @@ struct TimezoneChoiceView: View {
1212 @Environment ( \. presentationMode) private var presentationMode
1313
1414 @Binding var selectedTimeZone : TimeZone
15+ @Binding var selectedTimeZones : [ TimeZone ]
16+ @Binding var selectedDate : Date
17+ var selectMultiple : Bool
1518 @State private var searchTerm : String = " "
1619
1720 private var filteredTimeZones : [ TimeZone ] {
@@ -20,24 +23,45 @@ struct TimezoneChoiceView: View {
2023 } . filter { $0. matches ( searchTerm: searchTerm) }
2124 }
2225
26+ private func timeZoneIsSelected( _ tz: TimeZone ) -> Bool {
27+ if selectMultiple {
28+ return selectedTimeZones. contains ( tz)
29+ } else {
30+ return selectedTimeZone == tz
31+ }
32+ }
33+
2334 var body : some View {
2435 List {
2536 SearchBar ( text: $searchTerm, placeholder: " Search... " )
2637 . padding ( . horizontal, - 10 )
2738 ForEach ( filteredTimeZones, id: \. self) { tz in
2839 Button ( action: {
29- self . selectedTimeZone = tz
30- presentationMode. wrappedValue. dismiss ( )
40+ if self . selectMultiple {
41+ if let index = self . selectedTimeZones. firstIndex ( of: tz) {
42+ self . selectedTimeZones. remove ( at: index)
43+ } else {
44+ self . selectedTimeZones. append ( tz)
45+ }
46+ } else {
47+ self . selectedTimeZone = tz
48+ }
49+ if !selectMultiple {
50+ presentationMode. wrappedValue. dismiss ( )
51+ }
3152 } ) {
3253 HStack {
3354 Text ( tz. friendlyName)
3455 Spacer ( )
35- if let abbreviation = tz. abbreviation ( ) {
56+ if let abbreviation = tz. fudgedAbbreviation ( for : selectedDate ) {
3657 Text ( abbreviation)
37- . foregroundColor ( selectedTimeZone == tz ? . accentColor : . secondary)
58+ . foregroundColor ( . secondary)
59+ }
60+ if timeZoneIsSelected ( tz) {
61+ Image ( systemName: " checkmark " )
3862 }
3963 }
40- . foregroundColor ( selectedTimeZone == tz ? . accentColor : . primary)
64+ . foregroundColor ( timeZoneIsSelected ( tz ) ? . accentColor : . primary)
4165 }
4266 }
4367 }
@@ -48,6 +72,6 @@ struct TimezoneChoiceView: View {
4872
4973struct TimezoneChoiceView_Previews : PreviewProvider {
5074 static var previews : some View {
51- TimezoneChoiceView ( selectedTimeZone: . constant( TimeZone ( identifier: " Europe/London " ) !) )
75+ TimezoneChoiceView ( selectedTimeZone: . constant( TimeZone ( identifier: " Africa/Accra " ) !) , selectedTimeZones : . constant ( [ TimeZone ( identifier : " Africa/Algiers " ) ! , TimeZone ( identifier : " Africa/Bissau " ) ! ] ) , selectedDate : . constant ( Date ( ) ) , selectMultiple : true )
5276 }
5377}
0 commit comments