diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 139c36153..ca62b5a5a 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -107,6 +107,11 @@ struct RoomScreenViewStateBindings { var composerFocused: Bool var scrollToBottomButtonVisible = false + var showAttachmentPopover = false { + didSet { + composerFocused = false + } + } /// Information describing the currently displayed alert. var alertInfo: AlertInfo? @@ -118,7 +123,11 @@ struct RoomScreenViewStateBindings { var sendFailedConfirmationDialogInfo: SendFailedConfirmationDialogInfo? } -struct TimelineItemActionMenuInfo: Identifiable { +struct TimelineItemActionMenuInfo: Identifiable, Equatable { + static func == (lhs: TimelineItemActionMenuInfo, rhs: TimelineItemActionMenuInfo) -> Bool { + lhs.id == rhs.id + } + let item: EventBasedTimelineItemProtocol var id: String { diff --git a/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift b/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift index f48bc1d94..36137d5ec 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/MessageComposerTextField.swift @@ -81,7 +81,7 @@ private struct UITextViewWrapper: UIViewRepresentable { textView.keyboardType = .default textView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) - + return textView } @@ -110,11 +110,11 @@ private struct UITextViewWrapper: UIViewRepresentable { } } } - - DispatchQueue.main.async { // Avoid cycle detected through attribute warnings - if focused, textView.window != nil, !textView.isFirstResponder { - textView.becomeFirstResponder() - } + + if !focused, textView.isFirstResponder { + textView.resignFirstResponder() + } else if focused, textView.window != nil, !textView.isFirstResponder { + textView.becomeFirstResponder() } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomAttachmentPicker.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomAttachmentPicker.swift index ae93a7046..aa152ea1d 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomAttachmentPicker.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomAttachmentPicker.swift @@ -19,36 +19,35 @@ import SwiftUI struct RoomAttachmentPicker: View { @ObservedObject var context: RoomScreenViewModel.Context - @State private var showAttachmentPopover = false @State private var sheetContentHeight = CGFloat(0) var body: some View { Button { - showAttachmentPopover = true + context.showAttachmentPopover = true } label: { Image(systemName: "plus.circle.fill") .font(.compound.headingLG) .foregroundColor(.compound.textActionPrimary) } .accessibilityIdentifier(A11yIdentifiers.roomScreen.attachmentPicker) - .popover(isPresented: $showAttachmentPopover) { + .popover(isPresented: $context.showAttachmentPopover) { VStack(alignment: .leading, spacing: 0.0) { Button { - showAttachmentPopover = false + context.showAttachmentPopover = false context.send(viewAction: .displayMediaPicker) } label: { PickerLabel(title: L10n.screenRoomAttachmentSourceGallery, systemImageName: "photo.fill") } Button { - showAttachmentPopover = false + context.showAttachmentPopover = false context.send(viewAction: .displayDocumentPicker) } label: { PickerLabel(title: L10n.screenRoomAttachmentSourceFiles, systemImageName: "paperclip") } Button { - showAttachmentPopover = false + context.showAttachmentPopover = false context.send(viewAction: .displayCameraPicker) } label: { PickerLabel(title: L10n.screenRoomAttachmentSourceCamera, systemImageName: "camera.fill") diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index 988d164a1..306837cf0 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -99,6 +99,9 @@ struct RoomScreen: View { } editCancellationAction: { context.send(viewAction: .cancelEdit) } + .onChange(of: context.actionMenuInfo) { _ in + context.composerFocused = false + } } private var scrollToBottomButton: some View {