Skip to content

Commit

Permalink
[WEAV-48] CTA Button Preview 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
jisu15-kim committed Sep 21, 2024
1 parent 78bfcfc commit acd8923
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Projects/DesignSystem/DesignCore/Sources/KeyboardResponder.swift
Original file line number Diff line number Diff line change
@@ -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<AnyCancellable>()

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)
}
}
55 changes: 55 additions & 0 deletions Projects/Features/DesignPreview/Sources/DesignButtonView.swift
Original file line number Diff line number Diff line change
@@ -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()
}
4 changes: 4 additions & 0 deletions Projects/Features/DesignPreview/Sources/DesignPreview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand All @@ -30,6 +32,8 @@ fileprivate enum PreviewTypes: CaseIterable {
DesignTypographyPreview()
case .textureBackground:
DesignBackgroundTextureView()
case .ctaButton:
DesignButtonView()
}
}
}
Expand Down

0 comments on commit acd8923

Please sign in to comment.