Keyboard is kept dismissed when dismissing the actions or the attachments menu (#1141)

* keyboard is kept dismissed

* no need for dispatch queue
This commit is contained in:
Mauro
2023-06-23 11:39:43 +02:00
committed by GitHub
parent dba4060423
commit c77200c8f0
4 changed files with 24 additions and 13 deletions

View File

@@ -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<RoomScreenErrorType>?
@@ -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 {

View File

@@ -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()
}
}

View File

@@ -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")

View File

@@ -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 {