From a06596db16bbfe13033c9aa2fe5cf55bb856ea35 Mon Sep 17 00:00:00 2001 From: Graeme Arthur Date: Sat, 24 Feb 2024 19:49:44 +0100 Subject: [PATCH] Fix locations screen crash and selection bug (#2252) Task/Issue URL: https://app.asana.com/0/1203137811378537/1206668692602262/f https://app.asana.com/0/1203137811378537/1206676963602574/f **Description**: There were two issues found on the VPN Locations screen. 1. It crashes on opening (possibly only with specific screen sizes) on Big Sur 2. The selection state is not cleared from the UI on cancelling --- .../xcschemes/DuckDuckGo Privacy Browser.xcscheme | 3 +++ .../BothAppTargets/VPNLocation/VPNLocationView.swift | 7 ++++++- .../BothAppTargets/VPNLocation/VPNLocationViewModel.swift | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/DuckDuckGo Privacy Browser.xcscheme b/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/DuckDuckGo Privacy Browser.xcscheme index eaa06a07ec..a36b236226 100644 --- a/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/DuckDuckGo Privacy Browser.xcscheme +++ b/DuckDuckGo.xcodeproj/xcshareddata/xcschemes/DuckDuckGo Privacy Browser.xcscheme @@ -150,6 +150,9 @@ + + diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationView.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationView.swift index 3d693ff0f7..59dd198fbc 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationView.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationView.swift @@ -56,8 +56,13 @@ struct VPNLocationView: View { await model.onViewAppeared() } } + .onDisappear { + Task { + await model.onViewDisappered() + } + } } - .frame(minWidth: 624, maxWidth: .infinity, minHeight: 640, maxHeight: .infinity, alignment: .top) + .frame(width: 624, height: 640, alignment: .top) } @ViewBuilder diff --git a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationViewModel.swift b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationViewModel.swift index 38da4de2f8..bc0a0e042f 100644 --- a/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationViewModel.swift +++ b/DuckDuckGo/NetworkProtection/AppTargets/BothAppTargets/VPNLocation/VPNLocationViewModel.swift @@ -69,6 +69,11 @@ final class VPNLocationViewModel: ObservableObject { await reloadList() } + func onViewDisappered() async { + selectedLocation = settings.selectedLocation + await reloadList() + } + func onNearestItemSelection() async { DailyPixel.fire(pixel: .networkProtectionGeoswitchingSetNearest, frequency: .dailyAndCount, includeAppVersionParameter: true) selectedLocation = .nearest