From c6bfb2e602f39d1ffd2497416a1dbdc263bd3021 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 15:46:43 +0700 Subject: [PATCH 1/7] Add new screen for category list --- .../WooShippingHazmatCategoryList.swift | 67 +++++++++++++++++++ .../WooCommerce.xcodeproj/project.pbxproj | 4 ++ 2 files changed, 71 insertions(+) create mode 100644 WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift new file mode 100644 index 00000000000..3a40402c2f7 --- /dev/null +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift @@ -0,0 +1,67 @@ +import SwiftUI + +struct WooShippingHazmatCategoryList: View { + private let categories: [ShippingLabelHazmatCategory] = { + ShippingLabelHazmatCategory.allCases.filter { $0 != .none } + }() + + @Binding private var selectedItem: ShippingLabelHazmatCategory? + + @Environment(\.dismiss) private var dismiss + + init(selectedCategory: Binding) { + self._selectedItem = selectedCategory + } + + var body: some View { + NavigationStack { + List(categories, id: \.self) { category in + HStack { + Image(systemName: "checkmark") + .foregroundStyle(Color.accentColor) + .opacity(selectedItem == category ? 1 : 0) + + Text(category.localizedName) + .multilineTextAlignment(.leading) + .frame(maxWidth: .infinity, alignment: .leading) + + Image(systemName: "chevron.forward") + .foregroundStyle(Color(.tertiaryLabel)) + } + .contentShape(Rectangle()) + .onTapGesture { + selectedItem = category + } + } + .listStyle(.plain) + .navigationTitle(Localization.title) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .cancellationAction) { + Button(Localization.cancel) { + dismiss() + } + } + } + } + } +} + +private extension WooShippingHazmatCategoryList { + enum Localization { + static let title = NSLocalizedString( + "wooShippingHazmatCategoryList.title", + value: "Select Category", + comment: "Title of the screen to select a category for hazardous materials in the shipping label creation flow" + ) + static let cancel = NSLocalizedString( + "wooShippingHazmatCategoryList.cancel", + value: "Cancel", + comment: "Button to dismiss the hazardous material category screen in the shipping label creation flow" + ) + } +} + +#Preview { + WooShippingHazmatCategoryList(selectedCategory: .constant(nil)) +} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 73437df3f9b..4bb563d23a8 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -2794,6 +2794,7 @@ DEC0293A29C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC0293929C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift */; }; DEC1508227F450AC00F4487C /* CouponAllowedEmails.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC1508127F450AC00F4487C /* CouponAllowedEmails.swift */; }; DEC17AE02D82C513005A6E6D /* WooShippingHazmatDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */; }; + DEC1899A2D84197C005A6E6D /* WooShippingHazmatCategoryList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */; }; DEC2961F26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2961E26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift */; }; DEC2962126BD1627005A056B /* ShippingLabelCustomsFormList.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2962026BD1627005A056B /* ShippingLabelCustomsFormList.swift */; }; DEC2962326BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC2962226BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift */; }; @@ -5996,6 +5997,7 @@ DEC0293929C41BC500FD0E2F /* ApplicationPasswordAuthorizationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationPasswordAuthorizationViewModel.swift; sourceTree = ""; }; DEC1508127F450AC00F4487C /* CouponAllowedEmails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CouponAllowedEmails.swift; sourceTree = ""; }; DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingHazmatDetailView.swift; sourceTree = ""; }; + DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WooShippingHazmatCategoryList.swift; sourceTree = ""; }; DEC2961E26BD1605005A056B /* ShippingLabelCustomsFormListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormListViewModel.swift; sourceTree = ""; }; DEC2962026BD1627005A056B /* ShippingLabelCustomsFormList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormList.swift; sourceTree = ""; }; DEC2962226BD4E6E005A056B /* ShippingLabelCustomsFormInput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShippingLabelCustomsFormInput.swift; sourceTree = ""; }; @@ -12341,6 +12343,7 @@ children = ( CE7B4A5A2CA1BF9900F764EB /* WooShippingHazmatRow.swift */, DEC17ADF2D82C513005A6E6D /* WooShippingHazmatDetailView.swift */, + DEC189992D84197C005A6E6D /* WooShippingHazmatCategoryList.swift */, ); path = "WooShipping Hazmat Section"; sourceTree = ""; @@ -16409,6 +16412,7 @@ B97C6E562B15E51A008A2BF2 /* UpdateProductInventoryView.swift in Sources */, 268EC45F26CEA50C00716F5C /* EditCustomerNote.swift in Sources */, DE7E5E862B4D11D7002E28D2 /* BlazeTargetDevicePickerViewModel.swift in Sources */, + DEC1899A2D84197C005A6E6D /* WooShippingHazmatCategoryList.swift in Sources */, CE315DC62CC93CCE00A06748 /* WooShippingCarrier.swift in Sources */, 4535EE7E281BE04A004212B4 /* CouponAmountInputFormatter.swift in Sources */, 209AD3D22AC1EDF600825D76 /* WooPaymentsPayoutsCurrencyOverviewView.swift in Sources */, From ba973fac684c40ba0672b829ad030e491f4a3751 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 15:47:05 +0700 Subject: [PATCH 2/7] Present category list from Hazmat detail view --- .../WooShippingHazmatDetailView.swift | 15 ++++++++++++--- .../WooShippingHazmatRow.swift | 14 +++++++++++--- .../WooShippingCreateLabelsView.swift | 1 + .../WooShippingCreateLabelsViewModel.swift | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift index 78cb911746c..039ccb6fa9f 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift @@ -5,10 +5,15 @@ struct WooShippingHazmatDetailView: View { @Binding private var isHazardous: Bool + @Binding private var selectedCategory: ShippingLabelHazmatCategory? + @State private var detailURL: URL? - init(isHazardous: Binding) { + @State private var isShowingCategoryList = false + + init(isHazardous: Binding, selectedCategory: Binding) { self._isHazardous = isHazardous + self._selectedCategory = selectedCategory } var body: some View { @@ -26,7 +31,7 @@ struct WooShippingHazmatDetailView: View { } Button(Localization.selectCategory) { - // TODO: navigate to category list + isShowingCategoryList = true } .buttonStyle(PrimaryButtonStyle()) .renderedIf(isHazardous) @@ -57,6 +62,9 @@ struct WooShippingHazmatDetailView: View { } .toolbarBackground(Color.clear, for: .navigationBar) } + .sheet(isPresented: $isShowingCategoryList) { + WooShippingHazmatCategoryList(selectedCategory: $selectedCategory) + } } } } @@ -166,5 +174,6 @@ private extension WooShippingHazmatDetailView { } #Preview { - WooShippingHazmatDetailView(isHazardous: .constant(true)) + WooShippingHazmatDetailView(isHazardous: .constant(true), + selectedCategory: .constant(.airEligibleEthanol)) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift index 096d99ffc5a..88a8a26ea77 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift @@ -6,10 +6,15 @@ struct WooShippingHazmatRow: View { @Binding private var isHazardous: Bool + @Binding private var selectedCategory: ShippingLabelHazmatCategory? + @State private var isShowingDetailView = false - init(isHazardous: Binding, enabled: Bool) { + init(isHazardous: Binding, + selectedCategory: Binding, + enabled: Bool) { self._isHazardous = isHazardous + self._selectedCategory = selectedCategory self.enabled = enabled } @@ -32,7 +37,8 @@ struct WooShippingHazmatRow: View { .buttonStyle(.plain) .disabled(!enabled) .sheet(isPresented: $isShowingDetailView) { - WooShippingHazmatDetailView(isHazardous: $isHazardous) + WooShippingHazmatDetailView(isHazardous: $isHazardous, + selectedCategory: $selectedCategory) } } } @@ -61,6 +67,8 @@ private extension WooShippingHazmatRow { } #Preview { - WooShippingHazmatRow(isHazardous: .constant(false), enabled: true) + WooShippingHazmatRow(isHazardous: .constant(false), + selectedCategory: .constant(nil), + enabled: true) .padding() } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift index a739e2d70fa..cf55310c628 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift @@ -107,6 +107,7 @@ private extension WooShippingCreateLabelsView { WooShippingItems(viewModel: viewModel.items) WooShippingHazmatRow(isHazardous: $viewModel.containsHazardousMaterials, + selectedCategory: $viewModel.hazmatCategory, enabled: !viewModel.canViewLabel) WooShippingCustomsRow(informationIsCompleted: viewModel.customsInformationIsCompleted, diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift index a933b2546c4..96002c04e06 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift @@ -22,6 +22,7 @@ final class WooShippingCreateLabelsViewModel: ObservableObject { private var debounceDuration: Double = 1 @Published var containsHazardousMaterials = false + @Published var hazmatCategory: ShippingLabelHazmatCategory? @Published var labelPurchaseErrorNotice: Notice? From 02b9084252cf20b6b3735998265ab0cda0a3b0b0 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 16:03:48 +0700 Subject: [PATCH 3/7] Replace bindings for selected items --- .../WooShippingHazmatCategoryList.swift | 13 +++++++++---- .../WooShippingHazmatDetailView.swift | 19 +++++++++++-------- .../WooShippingHazmatRow.swift | 4 ++-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift index 3a40402c2f7..88542aa6f92 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift @@ -5,12 +5,16 @@ struct WooShippingHazmatCategoryList: View { ShippingLabelHazmatCategory.allCases.filter { $0 != .none } }() - @Binding private var selectedItem: ShippingLabelHazmatCategory? + private let selectionHandler: (ShippingLabelHazmatCategory) -> Void + + @State private var selectedItem: ShippingLabelHazmatCategory? @Environment(\.dismiss) private var dismiss - init(selectedCategory: Binding) { - self._selectedItem = selectedCategory + init(selectedItem: ShippingLabelHazmatCategory? = nil, + selectionHandler: @escaping (ShippingLabelHazmatCategory) -> Void) { + self.selectedItem = selectedItem + self.selectionHandler = selectionHandler } var body: some View { @@ -31,6 +35,7 @@ struct WooShippingHazmatCategoryList: View { .contentShape(Rectangle()) .onTapGesture { selectedItem = category + selectionHandler(category) } } .listStyle(.plain) @@ -63,5 +68,5 @@ private extension WooShippingHazmatCategoryList { } #Preview { - WooShippingHazmatCategoryList(selectedCategory: .constant(nil)) + WooShippingHazmatCategoryList(selectionHandler: { _ in }) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift index 039ccb6fa9f..b7100622ded 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatDetailView.swift @@ -3,17 +3,17 @@ import SwiftUI struct WooShippingHazmatDetailView: View { @Environment(\.dismiss) private var dismiss - @Binding private var isHazardous: Bool + @State private var isHazardous: Bool - @Binding private var selectedCategory: ShippingLabelHazmatCategory? + @State private var selectedCategory: ShippingLabelHazmatCategory? @State private var detailURL: URL? @State private var isShowingCategoryList = false - init(isHazardous: Binding, selectedCategory: Binding) { - self._isHazardous = isHazardous - self._selectedCategory = selectedCategory + init(isHazardous: Bool, selectedCategory: ShippingLabelHazmatCategory?) { + self.isHazardous = isHazardous + self.selectedCategory = selectedCategory } var body: some View { @@ -63,7 +63,10 @@ struct WooShippingHazmatDetailView: View { .toolbarBackground(Color.clear, for: .navigationBar) } .sheet(isPresented: $isShowingCategoryList) { - WooShippingHazmatCategoryList(selectedCategory: $selectedCategory) + WooShippingHazmatCategoryList(selectedItem: selectedCategory, + selectionHandler: { category in + // TODO: dismiss view + }) } } } @@ -174,6 +177,6 @@ private extension WooShippingHazmatDetailView { } #Preview { - WooShippingHazmatDetailView(isHazardous: .constant(true), - selectedCategory: .constant(.airEligibleEthanol)) + WooShippingHazmatDetailView(isHazardous: true, + selectedCategory: .airEligibleEthanol) } diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift index 88a8a26ea77..8b2293380c6 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatRow.swift @@ -37,8 +37,8 @@ struct WooShippingHazmatRow: View { .buttonStyle(.plain) .disabled(!enabled) .sheet(isPresented: $isShowingDetailView) { - WooShippingHazmatDetailView(isHazardous: $isHazardous, - selectedCategory: $selectedCategory) + WooShippingHazmatDetailView(isHazardous: isHazardous, + selectedCategory: selectedCategory) } } } From 1e26c1d6c6b24786727ccc23e2a0ae812ccdb1d6 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 16:04:00 +0700 Subject: [PATCH 4/7] Filter out unmatched categories --- .../WooShippingHazmatCategoryList.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift index 88542aa6f92..9b5eab58041 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift @@ -2,7 +2,11 @@ import SwiftUI struct WooShippingHazmatCategoryList: View { private let categories: [ShippingLabelHazmatCategory] = { - ShippingLabelHazmatCategory.allCases.filter { $0 != .none } + ShippingLabelHazmatCategory.allCases.filter { + /// Filter out items that don't match the list on the web + let exceptions: [ShippingLabelHazmatCategory] = [.none, .class4, .class5, .class6] + return !exceptions.contains($0) + } }() private let selectionHandler: (ShippingLabelHazmatCategory) -> Void From fafa835fdfd10476cad91383431c703ceddd99cf Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 16:30:01 +0700 Subject: [PATCH 5/7] Add search bar for category list --- .../WooShippingHazmatCategoryList.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift index 9b5eab58041..ce44c3a60ed 100644 --- a/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift +++ b/WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Hazmat Section/WooShippingHazmatCategoryList.swift @@ -13,8 +13,18 @@ struct WooShippingHazmatCategoryList: View { @State private var selectedItem: ShippingLabelHazmatCategory? + @State private var query: String = "" + @Environment(\.dismiss) private var dismiss + var filteredCategories: [ShippingLabelHazmatCategory] { + if query.isEmpty { + return categories + } else { + return categories.filter { $0.localizedName.lowercased().contains(query.lowercased()) } + } + } + init(selectedItem: ShippingLabelHazmatCategory? = nil, selectionHandler: @escaping (ShippingLabelHazmatCategory) -> Void) { self.selectedItem = selectedItem @@ -23,7 +33,7 @@ struct WooShippingHazmatCategoryList: View { var body: some View { NavigationStack { - List(categories, id: \.self) { category in + List(filteredCategories, id: \.self) { category in HStack { Image(systemName: "checkmark") .foregroundStyle(Color.accentColor) @@ -52,6 +62,7 @@ struct WooShippingHazmatCategoryList: View { } } } + .searchable(text: $query) } } } From 2b85552cbc9d6f935027b239b6af3781a0fb4449 Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 16:54:01 +0700 Subject: [PATCH 6/7] Remove outdated appearance customization for search bar --- WooCommerce/Classes/AppDelegate.swift | 1 - .../Extensions/UISearchBar+Appearance.swift | 38 ------------------- .../WooCommerce.xcodeproj/project.pbxproj | 4 -- 3 files changed, 43 deletions(-) delete mode 100644 WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift diff --git a/WooCommerce/Classes/AppDelegate.swift b/WooCommerce/Classes/AppDelegate.swift index b11e8fa2a2c..1e9a2fb5a16 100644 --- a/WooCommerce/Classes/AppDelegate.swift +++ b/WooCommerce/Classes/AppDelegate.swift @@ -294,7 +294,6 @@ private extension AppDelegate { func setupWooAppearance() { UINavigationBar.applyWooAppearance() UILabel.applyWooAppearance() - UISearchBar.applyWooAppearance() UITabBar.applyWooAppearance() // Take advantage of a bug in UIAlertController to style all UIAlertControllers with WC color diff --git a/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift b/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift deleted file mode 100644 index 7dedc79141a..00000000000 --- a/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift +++ /dev/null @@ -1,38 +0,0 @@ -import UIKit - - -// MARK: - UISearchBar + Woo -// -extension UISearchBar { - - /// Applies the default WC's Appearance - /// - class func applyWooAppearance() { - let appearance = UISearchBar.appearance() - appearance.barTintColor = .basicBackground - - appearance.layer.borderColor = UIColor.listSmallIcon.cgColor - appearance.layer.borderWidth = 1.0 - - let brandColor = UIColor.primary - appearance.tintColor = brandColor - - let cancelButtonAttributes = [NSAttributedString.Key.foregroundColor: brandColor] - UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(cancelButtonAttributes, for: .normal) - - let textAttributes = [NSAttributedString.Key.foregroundColor: UIColor.textTertiary] - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = textAttributes - } -} - - -// Setting the UITextField background color via the appearance proxy does not seem to work -// As a workaround, this property exposes the texfield, so the background color can be set manually -// -extension UISearchBar { - var textField: UITextField? { - return subviews.map { $0.subviews.first(where: { $0 is UITextInputTraits}) as? UITextField } - .compactMap { $0 } - .first - } -} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 4bb563d23a8..0648b04ba27 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -2463,7 +2463,6 @@ D81F2D35225F0CF70084BF9C /* EmptyListMessageWithActionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D81F2D34225F0CF70084BF9C /* EmptyListMessageWithActionView.xib */; }; D81F2D37225F0D160084BF9C /* EmptyListMessageWithActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81F2D36225F0D160084BF9C /* EmptyListMessageWithActionView.swift */; }; D82BB3AA26454F3300A82741 /* CardPresentModalProcessing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82BB3A926454F3300A82741 /* CardPresentModalProcessing.swift */; }; - D82DFB4A225F22D400EFE2CB /* UISearchBar+Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */; }; D82DFB4C225F303200EFE2CB /* EmptyListMessageWithActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82DFB4B225F303200EFE2CB /* EmptyListMessageWithActionTests.swift */; }; D831E2DC230E0558000037D0 /* Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = D831E2DB230E0558000037D0 /* Authentication.swift */; }; D831E2E0230E0BA7000037D0 /* Logs.swift in Sources */ = {isa = PBXBuildFile; fileRef = D831E2DF230E0BA7000037D0 /* Logs.swift */; }; @@ -5671,7 +5670,6 @@ D81F2D34225F0CF70084BF9C /* EmptyListMessageWithActionView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EmptyListMessageWithActionView.xib; sourceTree = ""; }; D81F2D36225F0D160084BF9C /* EmptyListMessageWithActionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyListMessageWithActionView.swift; sourceTree = ""; }; D82BB3A926454F3300A82741 /* CardPresentModalProcessing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalProcessing.swift; sourceTree = ""; }; - D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISearchBar+Appearance.swift"; sourceTree = ""; }; D82DFB4B225F303200EFE2CB /* EmptyListMessageWithActionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EmptyListMessageWithActionTests.swift; path = WooCommerceTests/ViewRelated/EmptyListMessageWithActionTests.swift; sourceTree = SOURCE_ROOT; }; D831E2DB230E0558000037D0 /* Authentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authentication.swift; sourceTree = ""; }; D831E2DF230E0BA7000037D0 /* Logs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logs.swift; sourceTree = ""; }; @@ -12043,7 +12041,6 @@ B586906521A5F4B1001F1EFC /* UINavigationController+Woo.swift */, D88CA755237CE515005D2F44 /* UITabBar+Appearance.swift */, D8149F552251EE300006A245 /* UITextField+Helpers.swift */, - D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */, 02820F3322C257B700DE0D37 /* UITableView+HeaderFooterHelpers.swift */, 456417F3247D5434001203F6 /* UITableView+Helpers.swift */, 02D45646231CB1FB008CF0A9 /* UIImage+Dot.swift */, @@ -16292,7 +16289,6 @@ CED9BCD12D412E2400C063B8 /* WooShippingAddressField.swift in Sources */, 867644A62B55121A0044ACAA /* BlazeCampaignCreationCoordinator.swift in Sources */, 45527A412472C6160078D609 /* SwitchStoreUseCase.swift in Sources */, - D82DFB4A225F22D400EFE2CB /* UISearchBar+Appearance.swift in Sources */, E1308381270311E200D5A68D /* CardPresentModalUpdateFailedLowBattery.swift in Sources */, CC254F3026C2A53D005F3C82 /* ShippingLabelAddNewPackage.swift in Sources */, 7441E1D221503F77004E6ECE /* IntrinsicTableView.swift in Sources */, From ac938f2b8c501dfd8d8127bd77eff324d3b32d3a Mon Sep 17 00:00:00 2001 From: Huong Do Date: Fri, 14 Mar 2025 17:17:13 +0700 Subject: [PATCH 7/7] Restore UISearchBar extension to fix build failure --- .../Classes/Extensions/UISearchBar+Appearance.swift | 12 ++++++++++++ WooCommerce/WooCommerce.xcodeproj/project.pbxproj | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift diff --git a/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift b/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift new file mode 100644 index 00000000000..14d8a1f9b42 --- /dev/null +++ b/WooCommerce/Classes/Extensions/UISearchBar+Appearance.swift @@ -0,0 +1,12 @@ +import UIKit + +// Setting the UITextField background color via the appearance proxy does not seem to work +// As a workaround, this property exposes the texfield, so the background color can be set manually +// +extension UISearchBar { + var textField: UITextField? { + return subviews.map { $0.subviews.first(where: { $0 is UITextInputTraits}) as? UITextField } + .compactMap { $0 } + .first + } +} diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index 0648b04ba27..4bb563d23a8 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -2463,6 +2463,7 @@ D81F2D35225F0CF70084BF9C /* EmptyListMessageWithActionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D81F2D34225F0CF70084BF9C /* EmptyListMessageWithActionView.xib */; }; D81F2D37225F0D160084BF9C /* EmptyListMessageWithActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D81F2D36225F0D160084BF9C /* EmptyListMessageWithActionView.swift */; }; D82BB3AA26454F3300A82741 /* CardPresentModalProcessing.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82BB3A926454F3300A82741 /* CardPresentModalProcessing.swift */; }; + D82DFB4A225F22D400EFE2CB /* UISearchBar+Appearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */; }; D82DFB4C225F303200EFE2CB /* EmptyListMessageWithActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D82DFB4B225F303200EFE2CB /* EmptyListMessageWithActionTests.swift */; }; D831E2DC230E0558000037D0 /* Authentication.swift in Sources */ = {isa = PBXBuildFile; fileRef = D831E2DB230E0558000037D0 /* Authentication.swift */; }; D831E2E0230E0BA7000037D0 /* Logs.swift in Sources */ = {isa = PBXBuildFile; fileRef = D831E2DF230E0BA7000037D0 /* Logs.swift */; }; @@ -5670,6 +5671,7 @@ D81F2D34225F0CF70084BF9C /* EmptyListMessageWithActionView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EmptyListMessageWithActionView.xib; sourceTree = ""; }; D81F2D36225F0D160084BF9C /* EmptyListMessageWithActionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyListMessageWithActionView.swift; sourceTree = ""; }; D82BB3A926454F3300A82741 /* CardPresentModalProcessing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardPresentModalProcessing.swift; sourceTree = ""; }; + D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISearchBar+Appearance.swift"; sourceTree = ""; }; D82DFB4B225F303200EFE2CB /* EmptyListMessageWithActionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EmptyListMessageWithActionTests.swift; path = WooCommerceTests/ViewRelated/EmptyListMessageWithActionTests.swift; sourceTree = SOURCE_ROOT; }; D831E2DB230E0558000037D0 /* Authentication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Authentication.swift; sourceTree = ""; }; D831E2DF230E0BA7000037D0 /* Logs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logs.swift; sourceTree = ""; }; @@ -12041,6 +12043,7 @@ B586906521A5F4B1001F1EFC /* UINavigationController+Woo.swift */, D88CA755237CE515005D2F44 /* UITabBar+Appearance.swift */, D8149F552251EE300006A245 /* UITextField+Helpers.swift */, + D82DFB49225F22D400EFE2CB /* UISearchBar+Appearance.swift */, 02820F3322C257B700DE0D37 /* UITableView+HeaderFooterHelpers.swift */, 456417F3247D5434001203F6 /* UITableView+Helpers.swift */, 02D45646231CB1FB008CF0A9 /* UIImage+Dot.swift */, @@ -16289,6 +16292,7 @@ CED9BCD12D412E2400C063B8 /* WooShippingAddressField.swift in Sources */, 867644A62B55121A0044ACAA /* BlazeCampaignCreationCoordinator.swift in Sources */, 45527A412472C6160078D609 /* SwitchStoreUseCase.swift in Sources */, + D82DFB4A225F22D400EFE2CB /* UISearchBar+Appearance.swift in Sources */, E1308381270311E200D5A68D /* CardPresentModalUpdateFailedLowBattery.swift in Sources */, CC254F3026C2A53D005F3C82 /* ShippingLabelAddNewPackage.swift in Sources */, 7441E1D221503F77004E6ECE /* IntrinsicTableView.swift in Sources */,