diff --git a/Projects/DesignSystem/DesignCore/Sources/KeyboardResponder.swift b/Projects/DesignSystem/DesignCore/Sources/KeyboardResponder.swift new file mode 100644 index 0000000..00bdc60 --- /dev/null +++ b/Projects/DesignSystem/DesignCore/Sources/KeyboardResponder.swift @@ -0,0 +1,38 @@ +// +// KeyboardResponder.swift +// DesignCore +// +// Created by 김지수 on 9/21/24. +// Copyright © 2024 com.weave. All rights reserved. +// + +import SwiftUI +import Combine + +public class KeyboardResponder: ObservableObject { + @Published public var keyboardHeight: CGFloat = 0 + @Published public var isKeyboardShown: Bool = false + + private var cancellables = Set() + + public init() { + let willShow = NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification) + let willHide = NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification) + + willShow + .merge(with: willHide) + .sink { [weak self] notification in + guard let self = self else { return } + if notification.name == UIResponder.keyboardWillShowNotification { + if let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect { + self.keyboardHeight = keyboardFrame.height + self.isKeyboardShown = true // 키보드가 올라온 상태 + } + } else { + self.keyboardHeight = 0 + self.isKeyboardShown = false // 키보드가 내려간 상태 + } + } + .store(in: &cancellables) + } +} diff --git a/Projects/Features/DesignPreview/Sources/DesignButtonView.swift b/Projects/Features/DesignPreview/Sources/DesignButtonView.swift new file mode 100644 index 0000000..5ef0ed9 --- /dev/null +++ b/Projects/Features/DesignPreview/Sources/DesignButtonView.swift @@ -0,0 +1,55 @@ +// +// DesignButtonView.swift +// DesignPreview +// +// Created by 김지수 on 9/21/24. +// Copyright © 2024 com.weave. All rights reserved. +// + +import SwiftUI +import DesignCore + +struct DesignButtonView: View { + + @FocusState var isTextFieldFocused + @State var text = "" + + var body: some View { + VStack(alignment: .center) { + Spacer() + TextField("Placeholder", text: $text) + .focused($isTextFieldFocused) + CTAButton( + title: "타이틀", + backgroundStyle: DesignCore.Colors.blue300 + ) {} + .padding(.horizontal, 36) + + CTAButton( + title: "타이틀", + backgroundStyle: DesignCore.Colors.darkGreen + ) {} + .padding(.horizontal, 36) + + Spacer() + + CTABottomButton( + title: "다음", + backgroundStyle: LinearGradient.gradientA, + isActive: true, + keyboardShown: isTextFieldFocused + ) { + if isTextFieldFocused { + isTextFieldFocused.toggle() + } + } + } + .ignoresSafeArea(.container, edges: .bottom) + .navigationTitle("CTA Button") + .navigationBarTitleDisplayMode(.inline) + } +} + +#Preview { + DesignButtonView() +} diff --git a/Projects/Features/DesignPreview/Sources/DesignPreview.swift b/Projects/Features/DesignPreview/Sources/DesignPreview.swift index 453f5cd..88fe6be 100644 --- a/Projects/Features/DesignPreview/Sources/DesignPreview.swift +++ b/Projects/Features/DesignPreview/Sources/DesignPreview.swift @@ -12,12 +12,14 @@ fileprivate enum PreviewTypes: CaseIterable { case colors case typography case textureBackground + case ctaButton var name: String { switch self { case .colors: return "Colors" case .typography: return "Typography" case .textureBackground: return "Texture Background" + case .ctaButton: return "CTA Button" } } @@ -30,6 +32,8 @@ fileprivate enum PreviewTypes: CaseIterable { DesignTypographyPreview() case .textureBackground: DesignBackgroundTextureView() + case .ctaButton: + DesignButtonView() } } }