mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Media upload tweaks (#3643)
* Focus the media caption composer if a hardware keyboard is available Not worrying about live connections, this screen is short lived. * Fix a bug where you could hit the send button multiple times while waiting for the media to be converted. * Begin processing media as soon as the media upload screen is shown.
This commit is contained in:
+26
-2
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Compound
|
||||
import GameController
|
||||
import QuickLook
|
||||
import SwiftUI
|
||||
|
||||
@@ -15,6 +16,7 @@ struct MediaUploadPreviewScreen: View {
|
||||
@ObservedObject var context: MediaUploadPreviewScreenViewModel.Context
|
||||
|
||||
@State private var captionWarningFrame: CGRect = .zero
|
||||
@FocusState private var isComposerFocussed
|
||||
|
||||
private var title: String { ProcessInfo.processInfo.isiOSAppOnMac ? context.viewState.title ?? "" : "" }
|
||||
private var colorSchemeOverride: ColorScheme { ProcessInfo.processInfo.isiOSAppOnMac ? colorScheme : .dark }
|
||||
@@ -36,6 +38,7 @@ struct MediaUploadPreviewScreen: View {
|
||||
.interactiveDismissDisabled()
|
||||
.presentationBackground(.background) // Fix a bug introduced by the caption warning.
|
||||
.preferredColorScheme(colorSchemeOverride)
|
||||
.onAppear(perform: focusComposerIfHardwareKeyboardConnected)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
@@ -58,8 +61,8 @@ struct MediaUploadPreviewScreen: View {
|
||||
text: $context.caption,
|
||||
presendCallback: $context.presendCallback,
|
||||
maxHeight: ComposerConstant.maxHeight,
|
||||
keyHandler: { _ in },
|
||||
pasteHandler: { _ in })
|
||||
keyHandler: handleKeyPress) { _ in }
|
||||
.focused($isComposerFocussed)
|
||||
|
||||
if context.viewState.shouldShowCaptionWarning {
|
||||
captionWarningButton
|
||||
@@ -125,6 +128,27 @@ struct MediaUploadPreviewScreen: View {
|
||||
.tint(.compound.textActionPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleKeyPress(_ key: UIKeyboardHIDUsage) {
|
||||
switch key {
|
||||
case .keyboardReturnOrEnter:
|
||||
context.send(viewAction: .send)
|
||||
case .keyboardEscape:
|
||||
context.send(viewAction: .cancel)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
isComposerFocussed = true
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private struct PreviewView: UIViewControllerRepresentable {
|
||||
|
||||
Reference in New Issue
Block a user