Expand selected server country on iOS (#853)
Add isExpanded binding to DisclosureGroup.
This commit is contained in:
parent
4ac524eb01
commit
83d77fafbb
|
@ -75,7 +75,7 @@ extension VPNProviderServerView {
|
|||
apis: apis,
|
||||
moduleId: moduleId,
|
||||
providerId: providerId,
|
||||
selectedServerId: selectedEntity?.server.id,
|
||||
selectedServer: selectedEntity?.server,
|
||||
initialFilters: {
|
||||
guard let selectedEntity, filtersWithSelection else {
|
||||
return nil
|
||||
|
@ -117,7 +117,7 @@ extension VPNProviderServerView {
|
|||
|
||||
let providerId: ProviderID
|
||||
|
||||
let selectedServerId: String?
|
||||
let selectedServer: VPNServer?
|
||||
|
||||
let initialFilters: VPNFilters?
|
||||
|
||||
|
@ -144,7 +144,7 @@ extension VPNProviderServerView {
|
|||
debugChanges()
|
||||
return ServersSubview(
|
||||
servers: filteredServers,
|
||||
selectedServerId: selectedServerId,
|
||||
selectedServer: selectedServer,
|
||||
isFiltering: isFiltering,
|
||||
filtersViewModel: filtersViewModel,
|
||||
favoritesManager: favoritesManager,
|
||||
|
|
|
@ -95,7 +95,7 @@ extension VPNProviderServerView {
|
|||
struct ServersSubview: View {
|
||||
let servers: [VPNServer]
|
||||
|
||||
let selectedServerId: String?
|
||||
let selectedServer: VPNServer?
|
||||
|
||||
let isFiltering: Bool
|
||||
|
||||
|
@ -109,6 +109,9 @@ extension VPNProviderServerView {
|
|||
|
||||
let onSelect: (VPNServer) -> Void
|
||||
|
||||
@State
|
||||
private var expandedCodes: Set<String> = []
|
||||
|
||||
var body: some View {
|
||||
debugChanges()
|
||||
return listView
|
||||
|
@ -138,6 +141,11 @@ private extension VPNProviderServerView.ServersSubview {
|
|||
.themeSection(
|
||||
header: filtersViewModel.filters.categoryName ?? Strings.Providers.Vpn.Category.any
|
||||
)
|
||||
.onLoad {
|
||||
if let selectedServer {
|
||||
expandedCodes.insert(selectedServer.provider.countryCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,6 +161,18 @@ private extension VPNProviderServerView.ServersSubview {
|
|||
.map(\.code)
|
||||
}
|
||||
|
||||
func isExpandedCountry(_ code: String) -> Binding<Bool> {
|
||||
Binding {
|
||||
expandedCodes.contains(code)
|
||||
} set: {
|
||||
if $0 {
|
||||
expandedCodes.insert(code)
|
||||
} else {
|
||||
expandedCodes.remove(code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func countryServers(for code: String) -> [VPNServer]? {
|
||||
servers
|
||||
.filter {
|
||||
|
@ -164,7 +184,7 @@ private extension VPNProviderServerView.ServersSubview {
|
|||
func countryView(for code: String) -> some View {
|
||||
countryServers(for: code)
|
||||
.map { servers in
|
||||
DisclosureGroup {
|
||||
DisclosureGroup(isExpanded: isExpandedCountry(code)) {
|
||||
ForEach(servers, id: \.id, content: serverView)
|
||||
} label: {
|
||||
ThemeCountryText(code)
|
||||
|
@ -178,7 +198,7 @@ private extension VPNProviderServerView.ServersSubview {
|
|||
} label: {
|
||||
HStack {
|
||||
ThemeImage(.marked)
|
||||
.opaque(server.id == selectedServerId)
|
||||
.opaque(server.id == selectedServer?.id)
|
||||
VStack(alignment: .leading) {
|
||||
if let area = server.provider.area {
|
||||
Text(area)
|
||||
|
|
|
@ -46,7 +46,7 @@ extension VPNProviderServerView {
|
|||
struct ServersSubview: View {
|
||||
let servers: [VPNServer]
|
||||
|
||||
let selectedServerId: String?
|
||||
let selectedServer: VPNServer?
|
||||
|
||||
let isFiltering: Bool
|
||||
|
||||
|
@ -68,7 +68,7 @@ extension VPNProviderServerView {
|
|||
return Table(servers) {
|
||||
TableColumn("") { server in
|
||||
ThemeImage(.marked)
|
||||
.opaque(server.id == selectedServerId)
|
||||
.opaque(server.id == selectedServer?.id)
|
||||
}
|
||||
.width(10.0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue