-
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.
- Loading branch information
1 parent
78bfcfc
commit acd8923
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Projects/DesignSystem/DesignCore/Sources/KeyboardResponder.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,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
55
Projects/Features/DesignPreview/Sources/DesignButtonView.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,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() | ||
} |
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