Impressia/Vernissage/Extensions/View+Keyboard.swift

27 lines
799 B
Swift
Raw Normal View History

2023-02-27 16:20:07 +01:00
//
// https://mczachurski.dev
// Copyright © 2023 Marcin Czachurski and the repository contributors.
2023-03-28 10:35:38 +02:00
// Licensed under the Apache License 2.0.
2023-02-27 16:20:07 +01:00
//
import SwiftUI
import Combine
2023-04-07 14:20:12 +02:00
// TODO: Move to shared views.
2023-02-27 16:20:07 +01:00
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()
}
}