From 0d22b2de8a99ab62da212ffa0485b5593d5099d3 Mon Sep 17 00:00:00 2001 From: Manu R Date: Tue, 3 Dec 2024 22:28:39 +0530 Subject: [PATCH 1/2] Update RegionPickerView.swift --- .../RegionPicker/RegionPickerView.swift | 131 ++++++++++-------- 1 file changed, 73 insertions(+), 58 deletions(-) diff --git a/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift b/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift index 111cf83c..43ab4761 100644 --- a/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift +++ b/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift @@ -59,74 +59,89 @@ public struct RegionPickerView: View, OnboardingView { @State var isShowingCustomRegionSheet: Bool = false public var body: some View { - List { - Toggle("Automatically select region", isOn: $regionProvider.automaticallySelectRegion) - Picker("", selection: $selectedRegion) { - ForEach(filteredRegions, id: \.self) { region in - cell(for: region) - .tag(Optional(region)) // The tag type must match the selection type (an *optional* Region) + NavigationStack { + List { + Toggle( + "Automatically select region", + isOn: $regionProvider.automaticallySelectRegion) + Picker("", selection: $selectedRegion) { + ForEach(filteredRegions, id: \.self) { region in + cell(for: region) + .tag(Optional(region)) // The tag type must match the selection type (an *optional* Region) + } } + .disabled(regionProvider.automaticallySelectRegion) + .pickerStyle(.inline) + .labelsHidden() // Hide picker header (title) } - .disabled(regionProvider.automaticallySelectRegion) - .pickerStyle(.inline) - .labelsHidden() // Hide picker header (title) - } - // List modifiers - .listSectionSeparator(.hidden) - .listStyle(.plain) - .refreshable(action: doRefreshRegions) - .disabled(disableInteractions) - - // Lifecycle-related modifiers - .onAppear(perform: setCurrentRegionIfPresent) - .onChange(of: regionProvider.currentRegion, initial: false) { _, newRegion in - // When the user selects to automatically select a region, update - // selectedRegion with the new current region. - if regionProvider.automaticallySelectRegion { - self.selectedRegion = newRegion + // List modifiers + .listSectionSeparator(.hidden) + .listStyle(.plain) + .refreshable(action: doRefreshRegions) + .disabled(disableInteractions) + .navigationDestination(isPresented: $isShowingCustomRegionSheet) { + RegionCustomForm( + regionProvider: regionProvider, + editingRegion: $editingRegion + ) } - } - // Presentation-related modifiers - .errorAlert(error: $taskError) - .background { - // TODO: I hate this. iOS 16 has NavigationStack, so use it when we drop iOS 15. - NavigationLink(destination: RegionCustomForm(regionProvider: regionProvider, editingRegion: $editingRegion), isActive: $isShowingCustomRegionSheet) { - EmptyView() + // Lifecycle-related modifiers + .onAppear(perform: setCurrentRegionIfPresent) + .onChange(of: regionProvider.currentRegion) { [regionProvider] _ in + // When the user selects to automatically select a region, update + // selectedRegion with the new current region. + if regionProvider.automaticallySelectRegion { + self.selectedRegion = regionProvider.currentRegion + } } - .accessibilityHidden(true) - } - // Supplementary views - .safeAreaInset(edge: .top) { - OnboardingHeaderView(imageSystemName: "globe", headerText: OBALoc("region_picker.title", value: "Choose Region", comment: "Title of the Region Picker Item, which lets the user choose a new region from the map.")) - } - .safeAreaInset(edge: .bottom) { - VStack(spacing: 14) { - RegionPickerMap(mapRect: Binding(get: { - selectedRegion?.serviceRect - }, set: { _ in }), mapHeight: 200) - .zIndex(-1) // Make the Map moving transition occur below the [Continue] button. - - TaskButton(action: doSetCurrentRegion) { - Text(Strings.continue) - .font(.headline) - .frame(maxWidth: .infinity, minHeight: 32) - } - .disabled(selectedRegion == nil || disableInteractions) - .buttonStyle(.borderedProminent) + // Presentation-related modifiers + .errorAlert(error: $taskError) + .background(.background) - regionOptions + // Supplementary views + .safeAreaInset(edge: .top) { + OnboardingHeaderView( + imageSystemName: "globe", + headerText: OBALoc( + "region_picker.title", value: "Choose Region", + comment: + "Title of the Region Picker Item, which lets the user choose a new region from the map." + )) + } + .safeAreaInset(edge: .bottom) { + VStack(spacing: 14) { + RegionPickerMap( + mapRect: Binding( + get: { + selectedRegion?.serviceRect + }, set: { _ in }), mapHeight: 200 + ) + .zIndex(-1) // Make the Map moving transition occur below the [Continue] button. + + TaskButton(action: doSetCurrentRegion) { + Text(Strings.continue) + .font(.headline) + .frame(maxWidth: .infinity, minHeight: 32) + } + .disabled(selectedRegion == nil || disableInteractions) + .buttonStyle(.borderedProminent) + + regionOptions + } + .background(.background) } - .background(.background) - } - // Global - .interactiveDismissDisabled(selectedRegion == nil || disableInteractions) - .navigationBarHidden(true) - .padding() + // Global + .interactiveDismissDisabled( + selectedRegion == nil || disableInteractions + ) + .navigationBarHidden(true) + .padding() + } } - + @ViewBuilder func cell(for region: Region) -> some View { Label { From 8fcf198b139ef0df4d59ea137cb9f01dff3cd13f Mon Sep 17 00:00:00 2001 From: Manu R Date: Wed, 4 Dec 2024 22:25:11 +0530 Subject: [PATCH 2/2] remove extra whitespace --- OBAKit/Onboarding/RegionPicker/RegionPickerView.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift b/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift index 43ab4761..1889a0aa 100644 --- a/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift +++ b/OBAKit/Onboarding/RegionPicker/RegionPickerView.swift @@ -141,7 +141,7 @@ public struct RegionPickerView: View, OnboardingView { .padding() } } - + @ViewBuilder func cell(for region: Region) -> some View { Label {