From 6d25a0e29170e3b86ccab51fe264aef1c2eac4a2 Mon Sep 17 00:00:00 2001 From: SeungHyun Hong Date: Mon, 4 Mar 2024 13:58:43 +0900 Subject: [PATCH 1/4] :recycle: Refactor `HomeProductDetailSelectionView` for better readability --- .../View/HomeProductDetailSelectionView.swift | 110 +++++++++--------- 1 file changed, 58 insertions(+), 52 deletions(-) diff --git a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift index 1393832..16ab3ec 100644 --- a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift +++ b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift @@ -17,63 +17,69 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView var body: some View { HStack { - Button { - convenienceStoreModalPresented = true - } label: { - Group { - convenienceImageView() - .resizable() - .scaledToFit() - Image.chevronDown - .renderingMode(.template) - .foregroundStyle(.gray300) - .accessibilityHidden(true) - } - } - .accessibilityHint("더블 탭하여 편의점을 선택하세요") - .sheet(isPresented: $convenienceStoreModalPresented) { - ConvenienceSelectBottomSheetView() - .presentationDetents([.height(Metrics.convenienceBottomSheetHeight)]) - .presentationCornerRadius(20) - .presentationBackground(.regularMaterial) - } - + convenienceStoreButton Spacer() + promotionButton + } + .frame(height: Metrics.height) + } - Button { - promotionModalPresented = true - } label: { - HStack(spacing: Metrics.buttonSpacing) { - Text(verbatim: "All") - .font(.title2) - Image.arrowTriangleDownFill - .renderingMode(.template) - } - .frame(height: Metrics.textHeight) - .foregroundStyle(.gray400) - .padding( - .init( - top: Metrics.promotionButtonPaddingTop, - leading: Metrics.promotionButtonPaddingLeading, - bottom: Metrics.promotionButtonPaddingBottom, - trailing: Metrics.promotionButtonPaddingTrailing - ) - ) - } - .accessibilityHint("더블 탭하여 할인 조건을 선택하세요") - .overlay { - RoundedRectangle(cornerRadius: Metrics.promotionButtonCornerRadius) - .stroke() - .foregroundStyle(.gray400) + private var convenienceStoreButton: some View { + Button { + convenienceStoreModalPresented = true + } label: { + Group { + convenienceImageView() + .resizable() + .scaledToFit() + Image.chevronDown + .renderingMode(.template) + .foregroundStyle(.gray300) + .accessibilityHidden(true) } - .sheet(isPresented: $promotionModalPresented) { - PromotionSelectBottomSheetView() - .presentationDetents([.height(Metrics.promotionBottomSheetHeight)]) - .presentationCornerRadius(20) - .presentationBackground(.regularMaterial) + } + .accessibilityHint("더블 탭하여 편의점을 선택하세요") + .sheet(isPresented: $convenienceStoreModalPresented) { + ConvenienceSelectBottomSheetView() + .presentationDetents([.height(Metrics.convenienceBottomSheetHeight)]) + .presentationCornerRadius(20) + .presentationBackground(.regularMaterial) + } + } + + private var promotionButton: some View { + Button { + promotionModalPresented = true + } label: { + HStack(spacing: Metrics.buttonSpacing) { + Text(verbatim: viewModel.state.productConfiguration.promotion.rawValue) + .font(.title2) + Image.arrowTriangleDownFill + .renderingMode(.template) } + .frame(height: Metrics.textHeight) + .foregroundStyle(.gray400) + .padding( + .init( + top: Metrics.promotionButtonPaddingTop, + leading: Metrics.promotionButtonPaddingLeading, + bottom: Metrics.promotionButtonPaddingBottom, + trailing: Metrics.promotionButtonPaddingTrailing + ) + ) + } + .accessibilityHint("더블 탭하여 할인 조건을 선택하세요") + .overlay { + RoundedRectangle(cornerRadius: Metrics.promotionButtonCornerRadius) + .stroke() + .foregroundStyle(.gray400) + } + .sheet(isPresented: $promotionModalPresented) { + PromotionSelectBottomSheetView() + .presentationDetents([.height(Metrics.promotionBottomSheetHeight)]) + .presentationCornerRadius(20) + .presentationBackground(.regularMaterial) } - .frame(height: Metrics.height) } private func convenienceImageView() -> Image { From 4ed5b0983cb00c47a88204c699a40a1d09957cb6 Mon Sep 17 00:00:00 2001 From: SeungHyun Hong Date: Mon, 4 Mar 2024 13:59:41 +0900 Subject: [PATCH 2/4] :recycle: Refactor to unify bottom sheet methods --- .../View/HomeProductDetailSelectionView.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift index 16ab3ec..738f3da 100644 --- a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift +++ b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift @@ -41,9 +41,7 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView .accessibilityHint("더블 탭하여 편의점을 선택하세요") .sheet(isPresented: $convenienceStoreModalPresented) { ConvenienceSelectBottomSheetView() - .presentationDetents([.height(Metrics.convenienceBottomSheetHeight)]) - .presentationCornerRadius(20) - .presentationBackground(.regularMaterial) + .bottomSheetPresentation(height: Metrics.convenienceBottomSheetHeight) } } @@ -76,9 +74,7 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView } .sheet(isPresented: $promotionModalPresented) { PromotionSelectBottomSheetView() - .presentationDetents([.height(Metrics.promotionBottomSheetHeight)]) - .presentationCornerRadius(20) - .presentationBackground(.regularMaterial) + .bottomSheetPresentation(height: Metrics.promotionBottomSheetHeight) } } @@ -98,6 +94,14 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView } } +extension View { + func bottomSheetPresentation(height: CGFloat) -> some View { + presentationDetents([.height(height)]) + .presentationCornerRadius(20) + .presentationBackground(.regularMaterial) + } +} + // MARK: - Metrics private enum Metrics { From d255b4469995dcebf6a91b0f22f20b5710114a26 Mon Sep 17 00:00:00 2001 From: SeungHyun Hong Date: Mon, 4 Mar 2024 14:31:12 +0900 Subject: [PATCH 3/4] :sparkles: Change to primary color when promotion selected --- .../HomeScene/View/HomeProductDetailSelectionView.swift | 9 ++++++--- .../Scenes/HomeScene/View/HomeProductSorterView.swift | 4 ++-- .../Sources/Extensions/ShapeStyle+Color.swift | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift index 738f3da..735cfeb 100644 --- a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift +++ b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductDetailSelectionView.swift @@ -56,7 +56,7 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView .renderingMode(.template) } .frame(height: Metrics.textHeight) - .foregroundStyle(.gray400) + .foregroundStyle(viewModel.state.productConfiguration.promotion == .allItems ? .gray400 : .white) .padding( .init( top: Metrics.promotionButtonPaddingTop, @@ -67,10 +67,13 @@ struct HomeProductDetailSelectionView: View where ViewModel: HomeView ) } .accessibilityHint("더블 탭하여 할인 조건을 선택하세요") + .background( + RoundedRectangle(cornerRadius: Metrics.promotionButtonCornerRadius) + .fill(viewModel.state.productConfiguration.promotion == .allItems ? .clear : .pyeonHaengPrimary) + ) .overlay { RoundedRectangle(cornerRadius: Metrics.promotionButtonCornerRadius) - .stroke() - .foregroundStyle(.gray400) + .stroke(viewModel.state.productConfiguration.promotion == .allItems ? .gray400 : .clear) } .sheet(isPresented: $promotionModalPresented) { PromotionSelectBottomSheetView() diff --git a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductSorterView.swift b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductSorterView.swift index 55e9ff3..6c08c99 100644 --- a/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductSorterView.swift +++ b/PyeonHaeng-iOS/Sources/Scenes/HomeScene/View/HomeProductSorterView.swift @@ -38,7 +38,7 @@ private extension HomeProductSorterView { var string = AttributedString(localized: "총 \(viewModel.state.totalCount)개의 상품이 있어요!") if let range = string.range(of: "\(viewModel.state.totalCount.formatted())") { - string[range].foregroundColor = .green500 + string[range].foregroundColor = .pyeonHaengPrimary } return string @@ -61,7 +61,7 @@ private extension HomeProductSorterView { .gray200 case .ascending, .descending: - .green500 + .pyeonHaengPrimary } } diff --git a/Shared/Sources/DesignSystem/Sources/Extensions/ShapeStyle+Color.swift b/Shared/Sources/DesignSystem/Sources/Extensions/ShapeStyle+Color.swift index fdaa323..d04fe68 100644 --- a/Shared/Sources/DesignSystem/Sources/Extensions/ShapeStyle+Color.swift +++ b/Shared/Sources/DesignSystem/Sources/Extensions/ShapeStyle+Color.swift @@ -78,5 +78,5 @@ public extension ShapeStyle where Self == Color { // Semantic Colors - static var primary: Color { .green500 } + static var pyeonHaengPrimary: Color { .green500 } } From 1602f9045bc1f1ad56c4b787acbc7ae87a16b300 Mon Sep 17 00:00:00 2001 From: SeungHyun Hong Date: Mon, 4 Mar 2024 16:14:59 +0900 Subject: [PATCH 4/4] :bug: Fix issue with encoding `+` symbol Resolved a bug where the `+` symbol was not being correctly encoded --- Core/Sources/Network/NetworkProvider.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Sources/Network/NetworkProvider.swift b/Core/Sources/Network/NetworkProvider.swift index c56db78..984b5c6 100644 --- a/Core/Sources/Network/NetworkProvider.swift +++ b/Core/Sources/Network/NetworkProvider.swift @@ -41,7 +41,7 @@ public struct NetworkProvider: Networking { case let .query(data): var components = URLComponents(string: url.absoluteString) components?.queryItems = data.toDictionary.map { URLQueryItem(name: $0, value: "\($1)") } - request.url = components?.url + request.url = URL(string: components?.url?.absoluteString.replacingOccurrences(of: "+", with: "%2B") ?? "") } } catch { throw NetworkError.encodeError