This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
import GameKit
|
||||
import SwiftUI
|
||||
import WysiwygComposer
|
||||
|
||||
@@ -100,6 +101,8 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
.store(in: &cancellables)
|
||||
|
||||
setupMentionsHandling(mentionDisplayHelper: mentionDisplayHelper)
|
||||
|
||||
focusComposerIfHardwareKeyboardConnected()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -361,6 +364,23 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
||||
private func removeLinks() {
|
||||
wysiwygViewModel.applyLinkOperation(.removeLinks)
|
||||
}
|
||||
|
||||
private func focusComposerIfHardwareKeyboardConnected() {
|
||||
// The simulator always detects the hardware keyboard as connected
|
||||
#if !targetEnvironment(simulator)
|
||||
if GCKeyboard.coalesced != nil {
|
||||
MXLog.info("Hardware keyboard is connected")
|
||||
state.bindings.composerFocused = true
|
||||
}
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(hardwareKeyboardDidConnect), name: .GCKeyboardDidConnect, object: nil)
|
||||
#endif
|
||||
}
|
||||
|
||||
@objc private func hardwareKeyboardDidConnect(_ notification: Notification) {
|
||||
MXLog.info("Did connect hardware keyboard")
|
||||
state.bindings.composerFocused = true
|
||||
}
|
||||
}
|
||||
|
||||
private extension LinkAction {
|
||||
|
||||
@@ -190,6 +190,9 @@ struct ComposerToolbar: View {
|
||||
.onChange(of: composerFocused) { newValue in
|
||||
context.composerFocused = newValue
|
||||
}
|
||||
.onAppear {
|
||||
composerFocused = context.composerFocused
|
||||
}
|
||||
}
|
||||
|
||||
private var placeholder: String {
|
||||
|
||||
@@ -31,7 +31,6 @@ struct MessageComposer: View {
|
||||
let replyCancellationAction: () -> Void
|
||||
let editCancellationAction: () -> Void
|
||||
let onAppearAction: () -> Void
|
||||
@FocusState private var focused: Bool
|
||||
|
||||
@State private var composerTranslation: CGFloat = 0
|
||||
private let composerShape = RoundedRectangle(cornerRadius: 21, style: .circular)
|
||||
@@ -77,7 +76,6 @@ struct MessageComposer: View {
|
||||
alignment: .top)
|
||||
.tint(.compound.iconAccentTertiary)
|
||||
.padding(.vertical, 10)
|
||||
.focused($focused)
|
||||
.onAppear {
|
||||
onAppearAction()
|
||||
}
|
||||
|
||||
1
changelog.d/1911.feature
Normal file
1
changelog.d/1911.feature
Normal file
@@ -0,0 +1 @@
|
||||
Automatically focus the composer when a hardware keyboards is connected
|
||||
Reference in New Issue
Block a user