-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Implement convenience store selection bottom sheet view * ✨ Implement convenience store selection modal - Added a bottom sheet view to display the convenience store selection modal. * 🎨 Refactor hardcoded constants to Metrics enum * 🎨 Refactor `isPresented` state to subview - Moved isPresented state variable to HomeProductDetailSelectionView for better state management. - Renamed isPresented variable to convenienceStoreModalPresented for improved clarity and readability. * ♻️ Refactor modal presentation using `@Environment(\.dismiss)` - Replaced `@Binding` with `@Environment(\.dismiss)` for modal presentation management.
- Loading branch information
Showing
7 changed files
with
256 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
PyeonHaeng-iOS/Sources/Scenes/HomeScene/BottomSheet/ConvenienceSelectBottomSheetView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// ConvenienceSelectBottomSheetView.swift | ||
// PyeonHaeng-iOS | ||
// | ||
// Created by 홍승현 on 2/21/24. | ||
// | ||
|
||
import Entity | ||
import SwiftUI | ||
|
||
// MARK: - ConvenienceSelectBottomSheetView | ||
|
||
struct ConvenienceSelectBottomSheetView<ViewModel>: View where ViewModel: HomeViewModelRepresentable { | ||
@EnvironmentObject private var viewModel: ViewModel | ||
@Environment(\.dismiss) private var dismiss | ||
|
||
var body: some View { | ||
VStack(spacing: Metrics.itemSpacing) { | ||
Text("편의점 브랜드 선택") | ||
.font(.h3) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding(.horizontal, Metrics.horizontalPadding) | ||
|
||
ForEach(ConvenienceStore.allCases, id: \.self) { store in | ||
Button { | ||
viewModel.trigger(.changeConvenienceStore(store)) | ||
dismiss() | ||
} label: { | ||
ConvenienceSelectItem(convenience: store) | ||
.frame(maxWidth: .infinity, minHeight: Metrics.itemHeight, alignment: .leading) | ||
} | ||
} | ||
.padding(.horizontal, Metrics.itemHorizontalPadding) | ||
} | ||
.padding(.top, Metrics.topPadding) | ||
.padding(.bottom, Metrics.bottomPadding) | ||
} | ||
} | ||
|
||
// MARK: - ConvenienceSelectItem | ||
|
||
private struct ConvenienceSelectItem: View { | ||
private let convenience: ConvenienceStore | ||
|
||
init(convenience: ConvenienceStore) { | ||
self.convenience = convenience | ||
} | ||
|
||
var body: some View { | ||
HStack(spacing: Metrics.itemHorizontalSpacing) { | ||
convenienceImageView() | ||
convenienceText() | ||
} | ||
} | ||
|
||
private func convenienceImageView() -> Image { | ||
switch convenience { | ||
case .cu: | ||
.cu | ||
case .gs25: | ||
.gs25 | ||
case ._7Eleven: | ||
._7Eleven | ||
case .emart24: | ||
.emart24 | ||
case .ministop: | ||
.ministop | ||
} | ||
} | ||
|
||
private func convenienceText() -> Text { | ||
switch convenience { | ||
case .cu: | ||
Text("CU") | ||
case .gs25: | ||
Text("GS25") | ||
case ._7Eleven: | ||
Text("7-Eleven") | ||
case .emart24: | ||
Text("Emart 24") | ||
case .ministop: | ||
Text("Ministop") | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Metrics | ||
|
||
private enum Metrics { | ||
static let topPadding: CGFloat = 12 | ||
static let bottomPadding: CGFloat = 4 | ||
static let horizontalPadding: CGFloat = 20 | ||
|
||
// MARK: Item | ||
|
||
static let itemHorizontalPadding: CGFloat = 24 | ||
static let itemHorizontalSpacing: CGFloat = 12 | ||
static let itemSpacing: CGFloat = 4 | ||
static let itemHeight: CGFloat = 44 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.