Skip to content

FloorFilter - Fix unintended SiteAndFacilitySelector re-open #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2024
Merged
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
14 changes: 7 additions & 7 deletions Sources/ArcGISToolkit/Components/FloorFilter/FloorFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public struct FloorFilter: View {
@StateObject private var viewModel: FloorFilterViewModel

/// A Boolean value that indicates whether the site and facility selector is presented.
@State private var isSitesAndFacilitiesHidden = true
@State private var siteAndFacilitySelectorIsPresented = false

/// The selected site, floor, or level.
private var selection: Binding<FloorFilterSelection?>?
Expand All @@ -119,7 +119,7 @@ public struct FloorFilter: View {
/// Button to open and close the site and facility selector.
private var sitesAndFacilitiesButton: some View {
Button {
isSitesAndFacilitiesHidden.toggle()
siteAndFacilitySelectorIsPresented.toggle()
} label: {
Image(systemName: "building.2")
.padding(.toolkitDefault)
Expand All @@ -133,7 +133,7 @@ public struct FloorFilter: View {
}
}

/// A view that displays the level selector and the sites and facilites button.
/// A view that displays the level selector and the sites and facilities button.
private var levelSelectorContainer: some View {
VStack {
if isTopAligned {
Expand Down Expand Up @@ -185,18 +185,18 @@ public struct FloorFilter: View {
@ViewBuilder private var siteAndFacilitySelector: some View {
if horizontalSizeClass == .compact {
Color.clear
.sheet(isPresented: .constant(!$isSitesAndFacilitiesHidden.wrappedValue)) {
SiteAndFacilitySelector(isHidden: $isSitesAndFacilitiesHidden)
.sheet(isPresented: $siteAndFacilitySelectorIsPresented) {
SiteAndFacilitySelector(isPresented: $siteAndFacilitySelectorIsPresented)
}
} else {
ZStack {
Color.clear
.esriBorder()
SiteAndFacilitySelector(isHidden: $isSitesAndFacilitiesHidden)
SiteAndFacilitySelector(isPresented: $siteAndFacilitySelectorIsPresented)
.padding([.top, .leading, .trailing], 2.5)
.padding(.bottom)
}
.opacity(isSitesAndFacilitiesHidden ? .zero : 1)
.opacity(siteAndFacilitySelectorIsPresented ? 1 : .zero)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,33 @@ import SwiftUI
/// A view which allows selection of sites and facilities represented in a `FloorManager`.
@MainActor
struct SiteAndFacilitySelector: View {
/// Creates a `SiteAndFacilitySelector`.
/// - Parameter isHidden: A binding used to dismiss the site selector.
init(isHidden: Binding<Bool>) {
self.isHidden = isHidden
}

/// The view model used by the `SiteAndFacilitySelector`.
@EnvironmentObject var viewModel: FloorFilterViewModel

/// Allows the user to toggle the visibility of the site and facility selector.
private var isHidden: Binding<Bool>
@Binding var isPresented: Bool

var body: some View {
NavigationStack {
Group {
// If there's more than one site
if viewModel.sites.count > 1 {
// Show the list of sites for site selection
SitesList(isHidden: isHidden)
SitesList(isPresented: $isPresented)
} else {
// Otherwise there're no sites or only one site, show the list of facilities
FacilitiesList(
usesAllSitesStyling: false,
facilities: viewModel.facilities,
isHidden: isHidden
isPresented: $isPresented
)
.navigationBarBackButtonHidden(true)
}
}
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
CloseButton { isHidden.wrappedValue.toggle() }
CloseButton { isPresented = false }
}
}
}
Expand All @@ -75,7 +69,7 @@ struct SiteAndFacilitySelector: View {
@State private var userBackedOutOfSelectedSite = false

/// Allows the user to toggle the visibility of the site and facility selector.
var isHidden: Binding<Bool>
@Binding var isPresented: Bool

/// A subset of `sites` with names containing `searchPhrase` or all `sites` if
/// `searchPhrase` is empty.
Expand Down Expand Up @@ -133,11 +127,11 @@ struct SiteAndFacilitySelector: View {
FacilitiesList(
usesAllSitesStyling: true,
facilities: viewModel.sites.flatMap(\.facilities),
isHidden: isHidden
isPresented: $isPresented
)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
CloseButton { isHidden.wrappedValue.toggle() }
CloseButton { isPresented = false }
}
}
} label: {
Expand Down Expand Up @@ -213,7 +207,7 @@ struct SiteAndFacilitySelector: View {
let facilities: [FloorFacility]

/// Allows the user to toggle the visibility of the site and facility selector.
var isHidden: Binding<Bool>
@Binding var isPresented: Bool

/// A subset of `facilities` with names containing `searchPhrase` or all
/// `facilities` if `searchPhrase` is empty.
Expand Down Expand Up @@ -298,7 +292,7 @@ struct SiteAndFacilitySelector: View {
.onTapGesture {
viewModel.setFacility(facility, zoomTo: true)
if horizontalSizeClass == .compact {
isHidden.wrappedValue.toggle()
isPresented = false
}
}
}
Expand Down Expand Up @@ -340,7 +334,7 @@ extension SiteAndFacilitySelector.SitesList {
SiteAndFacilitySelector.FacilitiesList(
usesAllSitesStyling: false,
facilities: site.facilities,
isHidden: isHidden
isPresented: $isPresented
)
.navigationBarBackButtonHidden(true)
.toolbar {
Expand All @@ -354,7 +348,7 @@ extension SiteAndFacilitySelector.SitesList {
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
CloseButton { isHidden.wrappedValue.toggle() }
CloseButton { isPresented = false }
}
}
}
Expand Down