Fix compose toolbar being hidden by software keyboard on iPadOS 15
Closes #252
This commit is contained in:
parent
c8319d8af2
commit
7178473f34
|
@ -49,6 +49,7 @@ struct ComposeView: View {
|
||||||
@State private var globalFrameOutsideList: CGRect = .zero
|
@State private var globalFrameOutsideList: CGRect = .zero
|
||||||
@State private var contentWarningBecomeFirstResponder = false
|
@State private var contentWarningBecomeFirstResponder = false
|
||||||
@State private var mainComposeTextViewBecomeFirstResponder = false
|
@State private var mainComposeTextViewBecomeFirstResponder = false
|
||||||
|
@StateObject private var keyboardReader = KeyboardReader()
|
||||||
|
|
||||||
@OptionalStateObject private var poster: PostService?
|
@OptionalStateObject private var poster: PostService?
|
||||||
@State private var isShowingPostErrorAlert = false
|
@State private var isShowingPostErrorAlert = false
|
||||||
|
@ -107,6 +108,8 @@ struct ComposeView: View {
|
||||||
|
|
||||||
ComposeToolbar(draft: draft)
|
ComposeToolbar(draft: draft)
|
||||||
}
|
}
|
||||||
|
// on iPadOS15, the toolbar ends up below the keyboard's toolbar without this
|
||||||
|
.padding(.bottom, keyboardInset)
|
||||||
.transition(.move(edge: .bottom))
|
.transition(.move(edge: .bottom))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +138,17 @@ struct ComposeView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS, obsoleted: 16.0)
|
||||||
|
private var keyboardInset: CGFloat {
|
||||||
|
if #unavailable(iOS 16.0),
|
||||||
|
UIDevice.current.userInterfaceIdiom == .pad,
|
||||||
|
keyboardReader.isVisible {
|
||||||
|
return 44
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var autocompleteSuggestions: some View {
|
private var autocompleteSuggestions: some View {
|
||||||
if let state = uiState.autocompleteState {
|
if let state = uiState.autocompleteState {
|
||||||
|
@ -316,6 +330,26 @@ private struct GlobalFrameOutsideListPrefKey: PreferenceKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(iOS, obsoleted: 16.0)
|
||||||
|
private class KeyboardReader: ObservableObject {
|
||||||
|
@Published var isVisible = false
|
||||||
|
|
||||||
|
init() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(willShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(willHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func willShow(_ notification: Foundation.Notification) {
|
||||||
|
// when a hardware keyboard is connected, the height is very short, so we don't consider that being "visible"
|
||||||
|
let endFrame = notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
|
||||||
|
isVisible = endFrame.height > 72
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func willHide() {
|
||||||
|
isVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//struct ComposeView_Previews: PreviewProvider {
|
//struct ComposeView_Previews: PreviewProvider {
|
||||||
// static var previews: some View {
|
// static var previews: some View {
|
||||||
// ComposeView()
|
// ComposeView()
|
||||||
|
|
Loading…
Reference in New Issue