@@ -18,39 +18,33 @@ import SwiftUI
18
18
/// A view which allows selection of sites and facilities represented in a `FloorManager`.
19
19
@MainActor
20
20
struct SiteAndFacilitySelector : View {
21
- /// Creates a `SiteAndFacilitySelector`.
22
- /// - Parameter isHidden: A binding used to dismiss the site selector.
23
- init ( isHidden: Binding < Bool > ) {
24
- self . isHidden = isHidden
25
- }
26
-
27
21
/// The view model used by the `SiteAndFacilitySelector`.
28
22
@EnvironmentObject var viewModel : FloorFilterViewModel
29
23
30
24
/// Allows the user to toggle the visibility of the site and facility selector.
31
- private var isHidden : Binding < Bool >
25
+ @ Binding var isPresented : Bool
32
26
33
27
var body : some View {
34
28
NavigationStack {
35
29
Group {
36
30
// If there's more than one site
37
31
if viewModel. sites. count > 1 {
38
32
// Show the list of sites for site selection
39
- SitesList ( isHidden : isHidden )
33
+ SitesList ( isPresented : $isPresented )
40
34
} else {
41
35
// Otherwise there're no sites or only one site, show the list of facilities
42
36
FacilitiesList (
43
37
usesAllSitesStyling: false ,
44
38
facilities: viewModel. facilities,
45
- isHidden : isHidden
39
+ isPresented : $isPresented
46
40
)
47
41
. navigationBarBackButtonHidden ( true )
48
42
}
49
43
}
50
44
. navigationBarTitleDisplayMode ( . inline)
51
45
. toolbar {
52
46
ToolbarItem ( placement: . navigationBarTrailing) {
53
- CloseButton { isHidden . wrappedValue . toggle ( ) }
47
+ CloseButton { isPresented = false }
54
48
}
55
49
}
56
50
}
@@ -75,7 +69,7 @@ struct SiteAndFacilitySelector: View {
75
69
@State private var userBackedOutOfSelectedSite = false
76
70
77
71
/// Allows the user to toggle the visibility of the site and facility selector.
78
- var isHidden : Binding < Bool >
72
+ @ Binding var isPresented : Bool
79
73
80
74
/// A subset of `sites` with names containing `searchPhrase` or all `sites` if
81
75
/// `searchPhrase` is empty.
@@ -133,11 +127,11 @@ struct SiteAndFacilitySelector: View {
133
127
FacilitiesList (
134
128
usesAllSitesStyling: true ,
135
129
facilities: viewModel. sites. flatMap ( \. facilities) ,
136
- isHidden : isHidden
130
+ isPresented : $isPresented
137
131
)
138
132
. toolbar {
139
133
ToolbarItem ( placement: . navigationBarTrailing) {
140
- CloseButton { isHidden . wrappedValue . toggle ( ) }
134
+ CloseButton { isPresented = false }
141
135
}
142
136
}
143
137
} label: {
@@ -213,7 +207,7 @@ struct SiteAndFacilitySelector: View {
213
207
let facilities : [ FloorFacility ]
214
208
215
209
/// Allows the user to toggle the visibility of the site and facility selector.
216
- var isHidden : Binding < Bool >
210
+ @ Binding var isPresented : Bool
217
211
218
212
/// A subset of `facilities` with names containing `searchPhrase` or all
219
213
/// `facilities` if `searchPhrase` is empty.
@@ -298,7 +292,7 @@ struct SiteAndFacilitySelector: View {
298
292
. onTapGesture {
299
293
viewModel. setFacility ( facility, zoomTo: true )
300
294
if horizontalSizeClass == . compact {
301
- isHidden . wrappedValue . toggle ( )
295
+ isPresented = false
302
296
}
303
297
}
304
298
}
@@ -340,7 +334,7 @@ extension SiteAndFacilitySelector.SitesList {
340
334
SiteAndFacilitySelector . FacilitiesList (
341
335
usesAllSitesStyling: false ,
342
336
facilities: site. facilities,
343
- isHidden : isHidden
337
+ isPresented : $isPresented
344
338
)
345
339
. navigationBarBackButtonHidden ( true )
346
340
. toolbar {
@@ -354,7 +348,7 @@ extension SiteAndFacilitySelector.SitesList {
354
348
}
355
349
. toolbar {
356
350
ToolbarItem ( placement: . navigationBarTrailing) {
357
- CloseButton { isHidden . wrappedValue . toggle ( ) }
351
+ CloseButton { isPresented = false }
358
352
}
359
353
}
360
354
}
0 commit comments