This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import Combine
|
import Combine
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import GameKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import WysiwygComposer
|
import WysiwygComposer
|
||||||
|
|
||||||
@@ -100,8 +101,10 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
|||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|
||||||
setupMentionsHandling(mentionDisplayHelper: mentionDisplayHelper)
|
setupMentionsHandling(mentionDisplayHelper: mentionDisplayHelper)
|
||||||
|
|
||||||
|
focusComposerIfHardwareKeyboardConnected()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Public
|
// MARK: - Public
|
||||||
|
|
||||||
override func process(viewAction: ComposerToolbarViewAction) {
|
override func process(viewAction: ComposerToolbarViewAction) {
|
||||||
@@ -361,6 +364,23 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
|
|||||||
private func removeLinks() {
|
private func removeLinks() {
|
||||||
wysiwygViewModel.applyLinkOperation(.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 {
|
private extension LinkAction {
|
||||||
|
|||||||
@@ -190,6 +190,9 @@ struct ComposerToolbar: View {
|
|||||||
.onChange(of: composerFocused) { newValue in
|
.onChange(of: composerFocused) { newValue in
|
||||||
context.composerFocused = newValue
|
context.composerFocused = newValue
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
composerFocused = context.composerFocused
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var placeholder: String {
|
private var placeholder: String {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ struct MessageComposer: View {
|
|||||||
let replyCancellationAction: () -> Void
|
let replyCancellationAction: () -> Void
|
||||||
let editCancellationAction: () -> Void
|
let editCancellationAction: () -> Void
|
||||||
let onAppearAction: () -> Void
|
let onAppearAction: () -> Void
|
||||||
@FocusState private var focused: Bool
|
|
||||||
|
|
||||||
@State private var composerTranslation: CGFloat = 0
|
@State private var composerTranslation: CGFloat = 0
|
||||||
private let composerShape = RoundedRectangle(cornerRadius: 21, style: .circular)
|
private let composerShape = RoundedRectangle(cornerRadius: 21, style: .circular)
|
||||||
@@ -77,7 +76,6 @@ struct MessageComposer: View {
|
|||||||
alignment: .top)
|
alignment: .top)
|
||||||
.tint(.compound.iconAccentTertiary)
|
.tint(.compound.iconAccentTertiary)
|
||||||
.padding(.vertical, 10)
|
.padding(.vertical, 10)
|
||||||
.focused($focused)
|
|
||||||
.onAppear {
|
.onAppear {
|
||||||
onAppearAction()
|
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