26 lines
761 B
Swift
26 lines
761 B
Swift
//
|
|
// https://mczachurski.dev
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
|
// Licensed under the MIT License.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Combine
|
|
|
|
extension View {
|
|
var keyboardPublisher: AnyPublisher<Bool, Never> {
|
|
Publishers
|
|
.Merge(
|
|
NotificationCenter
|
|
.default
|
|
.publisher(for: UIResponder.keyboardWillShowNotification)
|
|
.map { _ in true },
|
|
NotificationCenter
|
|
.default
|
|
.publisher(for: UIResponder.keyboardWillHideNotification)
|
|
.map { _ in false })
|
|
.debounce(for: .seconds(0.1), scheduler: RunLoop.main)
|
|
.eraseToAnyPublisher()
|
|
}
|
|
}
|