|
| 1 | +// |
| 2 | +// PokitKeywordBottomSheet.swift |
| 3 | +// Feature |
| 4 | +// |
| 5 | +// Created by 김민호 on 1/23/25. |
| 6 | +// |
| 7 | + |
| 8 | +import SwiftUI |
| 9 | + |
| 10 | +import Util |
| 11 | + |
| 12 | +public struct PokitKeywordBottomSheet: View { |
| 13 | + @State |
| 14 | + private var height: CGFloat = 0 |
| 15 | + @State |
| 16 | + private var selectedKeywordType: BaseInterestType |
| 17 | + @State |
| 18 | + private var keywordSheetBottomButtonState: PokitButtonStyle.State = .disable |
| 19 | + private let action: (BaseInterestType) -> Void |
| 20 | + |
| 21 | + public init( |
| 22 | + selectedKeywordType: BaseInterestType, |
| 23 | + action: @escaping (BaseInterestType) -> Void |
| 24 | + ) { |
| 25 | + self.selectedKeywordType = selectedKeywordType |
| 26 | + self.keywordSheetBottomButtonState = selectedKeywordType == .default |
| 27 | + ? .disable |
| 28 | + : .filled(.primary) |
| 29 | + self.action = action |
| 30 | + } |
| 31 | + |
| 32 | + public var body: some View { |
| 33 | + VStack(alignment: .leading, spacing: 0) { |
| 34 | + Text("포킷의 키워드를 선택해 주세요") |
| 35 | + .pokitFont(.title1) |
| 36 | + .foregroundStyle(.pokit(.text(.primary))) |
| 37 | + Text("키워드 기반으로 다른 사용자에게\n링크가 추천됩니다") |
| 38 | + .pokitFont(.title3) |
| 39 | + .foregroundStyle(.pokit(.text(.secondary))) |
| 40 | + .padding(.top, 12) |
| 41 | + PokitFlowLayout(rowSpacing: 12, colSpacing: 10) { |
| 42 | + ForEach(BaseInterestType.allCases, id: \.self) { field in |
| 43 | + let isSelected = selectedKeywordType != .default |
| 44 | + if field != .default { |
| 45 | + PokitTextChip( |
| 46 | + field.title, |
| 47 | + state: isSelected && field == selectedKeywordType |
| 48 | + ? .filled(.primary) |
| 49 | + : .default(.primary), |
| 50 | + size: .medium |
| 51 | + ) { |
| 52 | + selectedKeywordType = field |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + .animation(.pokitDissolve, value: selectedKeywordType) |
| 57 | + } |
| 58 | + .padding(.top, 36) |
| 59 | + .padding(.bottom, 40) |
| 60 | + |
| 61 | + PokitBottomButton( |
| 62 | + "키워드 선택", |
| 63 | + state: keywordSheetBottomButtonState, |
| 64 | + action: { action(selectedKeywordType) } |
| 65 | + ) |
| 66 | + .padding(.top, 16) |
| 67 | + } |
| 68 | + .padding(.horizontal, 20) |
| 69 | + .padding(.top, 48) |
| 70 | + .onChange(of: selectedKeywordType) { _ in |
| 71 | + keywordSheetBottomButtonState = .filled(.primary) |
| 72 | + } |
| 73 | + .background(.pokit(.bg(.base))) |
| 74 | + .pokitPresentationCornerRadius() |
| 75 | + .pokitPresentationBackground() |
| 76 | + .presentationDragIndicator(.visible) |
| 77 | + .readHeight() |
| 78 | + .onPreferenceChange(HeightPreferenceKey.self) { height in |
| 79 | + if let height { |
| 80 | + self.height = height |
| 81 | + } |
| 82 | + } |
| 83 | + .presentationDetents([.height(height)]) |
| 84 | + .ignoresSafeArea(edges: [.bottom, .top]) |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +#Preview { |
| 89 | + ZStack { |
| 90 | + Color.black |
| 91 | + .sheet(isPresented: .constant(true)) { |
| 92 | + PokitKeywordBottomSheet( |
| 93 | + selectedKeywordType: .default, |
| 94 | + action: { _ in } |
| 95 | + ) |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | + |
0 commit comments