회원가입 페이지
This commit is contained in:
29
SodaLive/Sources/Keyboard/KeyboardHandler.swift
Normal file
29
SodaLive/Sources/Keyboard/KeyboardHandler.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// KeyboardHandler.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2023/08/09.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
final class KeyboardHandler: ObservableObject {
|
||||
@Published private(set) var keyboardHeight: CGFloat = 0
|
||||
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
private let keyboardWillShow = NotificationCenter.default
|
||||
.publisher(for: UIResponder.keyboardWillShowNotification)
|
||||
.compactMap { ($0.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect)?.height }
|
||||
|
||||
private let keyboardWillHide = NotificationCenter.default
|
||||
.publisher(for: UIResponder.keyboardWillHideNotification)
|
||||
.map { _ in CGFloat.zero }
|
||||
|
||||
init() {
|
||||
cancellable = Publishers.Merge(keyboardWillShow, keyboardWillHide)
|
||||
.subscribe(on: DispatchQueue.main)
|
||||
.assign(to: \.self.keyboardHeight, on: self)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user