From 65d6e30469d217dd70c297f1d94d35b93227892b Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 23 Jul 2023 15:17:28 +0200 Subject: [PATCH] Consider text length in endpoint rows (#336) --- .../App/Views/EndpointView+OpenVPN.swift | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/Passepartout/App/Views/EndpointView+OpenVPN.swift b/Passepartout/App/Views/EndpointView+OpenVPN.swift index 36426a9c..84f19ab6 100644 --- a/Passepartout/App/Views/EndpointView+OpenVPN.swift +++ b/Passepartout/App/Views/EndpointView+OpenVPN.swift @@ -115,12 +115,6 @@ private extension EndpointView.OpenVPNView { } } -private extension Endpoint { - var linearDescription: String { - "\(address) → \(proto.rawValue)" - } -} - // MARK: - private extension EndpointView.OpenVPNView { @@ -148,7 +142,7 @@ private extension EndpointView.OpenVPNView { var endpointsSection: some View { Section { ForEach(builder.remotes ?? []) { endpoint in - fullRowForEndpoint(endpoint) + rowForEndpoint(endpoint) .swipeActions(edge: .trailing, allowsFullSwipe: false) { actions(forEndpoint: endpoint) } @@ -157,13 +151,13 @@ private extension EndpointView.OpenVPNView { } } - func fullRowForEndpoint(_ endpoint: Endpoint) -> some View { + func rowForEndpoint(_ endpoint: Endpoint) -> some View { Button { withAnimation { currentProfile.value.customEndpoint = endpoint } } label: { - Text(endpoint.linearDescription) + labelForEndpoint(endpoint) }.sheet(item: $editedEndpoint) { endpoint in NavigationView { EndpointView.AddView(L10n.Global.Strings.edit, endpoint: endpoint, onSave: commitEndpoint) @@ -171,6 +165,15 @@ private extension EndpointView.OpenVPNView { }.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint) } + func labelForEndpoint(_ endpoint: Endpoint) -> some View { + VStack { + Text(endpoint.address) + .frame(maxWidth: .infinity, alignment: .leading) + Text(endpoint.proto.rawValue) + .frame(maxWidth: .infinity, alignment: .leading) + } + } + @ViewBuilder func actions(forEndpoint endpoint: Endpoint) -> some View { if !isConfigurationReadonly { @@ -255,31 +258,38 @@ private extension EndpointView.OpenVPNView { private extension EndpointView.OpenVPNView { var groupedEndpointsSections: some View { - ForEach(endpointsByAddress, content: endpointsGroup(forSection:)) + ForEach(endpointsByAddress, content: group(forEndpointsSection:)) .disabled(isAutomatic) } - func endpointsGroup(forSection section: EndpointsByAddress) -> some View { + func group(forEndpointsSection section: EndpointsByAddress) -> some View { Section { DisclosureGroup(isExpanded: isExpandedBinding(address: section.address)) { - ForEach(section.endpoints, content: groupedRowForEndpoint) + ForEach(section.endpoints, content: rowForEndpointProtocol) } label: { - Text(L10n.Global.Strings.address) - .withTrailingText(section.address) + labelForEndpointAddress(section.address) } } } - func groupedRowForEndpoint(_ endpoint: Endpoint) -> some View { + func labelForEndpointAddress(_ address: String) -> some View { + Text(address) + } + + func rowForEndpointProtocol(_ endpoint: Endpoint) -> some View { Button { withAnimation { currentProfile.value.customEndpoint = endpoint } } label: { - Text(endpoint.proto.rawValue) + labelForEndpointProtocol(endpoint.proto) }.withTrailingCheckmark(when: currentProfile.value.customEndpoint == endpoint) } + func labelForEndpointProtocol(_ proto: EndpointProtocol) -> some View { + Text(proto.rawValue) + } + var endpointsByAddress: [EndpointsByAddress] { guard let remotes = builder.remotes, !remotes.isEmpty else { return []