From 57ba06a94e602e9a0719f3b84c0d5b387a92a7c7 Mon Sep 17 00:00:00 2001 From: fmodf Date: Tue, 2 Jul 2024 10:32:14 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/ConversationActions.swift | 2 ++ .../AppCore/Reducers/ConversationReducer.swift | 3 +++ .../AppCore/State/ConversationState.swift | 2 ++ .../View/Screens/AttachmentPickerScreen.swift | 16 ++++++++++++++++ .../Conversation/ConversationScreen.swift | 2 +- .../Conversation/ConversationTextInput.swift | 12 ++++++++++-- 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ConversationsClassic/View/Screens/AttachmentPickerScreen.swift diff --git a/ConversationsClassic/AppCore/Actions/ConversationActions.swift b/ConversationsClassic/AppCore/Actions/ConversationActions.swift index 9294677..f299693 100644 --- a/ConversationsClassic/AppCore/Actions/ConversationActions.swift +++ b/ConversationsClassic/AppCore/Actions/ConversationActions.swift @@ -5,4 +5,6 @@ enum ConversationAction: Codable { case sendMessage(from: String, to: String, body: String) case setReplyText(String) + + case showAttachmentPicker(Bool) } diff --git a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift index cc76c62..a4d980a 100644 --- a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift @@ -17,6 +17,9 @@ extension ConversationState { state.replyText = text.makeReply } + case .showAttachmentPicker(let flag): + state.attachmentPickerVisible = flag + default: break } diff --git a/ConversationsClassic/AppCore/State/ConversationState.swift b/ConversationsClassic/AppCore/State/ConversationState.swift index 9267bbd..bfb03ce 100644 --- a/ConversationsClassic/AppCore/State/ConversationState.swift +++ b/ConversationsClassic/AppCore/State/ConversationState.swift @@ -4,6 +4,7 @@ struct ConversationState: Stateable { var currentMessages: [Message] var replyText: String + var attachmentPickerVisible: Bool } // MARK: Init @@ -11,5 +12,6 @@ extension ConversationState { init() { currentMessages = [] replyText = "" + attachmentPickerVisible = false } } diff --git a/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift b/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift new file mode 100644 index 0000000..9bf47f3 --- /dev/null +++ b/ConversationsClassic/View/Screens/AttachmentPickerScreen.swift @@ -0,0 +1,16 @@ +import SwiftUI + +struct AttachmentPickerScreen: View { + @EnvironmentObject var store: AppStore + + var body: some View { + VStack { + Button { + store.dispatch(.conversationAction(.showAttachmentPicker(false))) + } label: { + Text("Back") + } + Text("Do It") + } + } +} diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift b/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift index f1b53e2..cc667df 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationScreen.swift @@ -89,7 +89,7 @@ struct ConversationScreen: View { } } .safeAreaInset(edge: .bottom, spacing: 0) { - ConversationTextInput() + ConversationTextInput(autoScroll: $autoScroll) } } } diff --git a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift index a7ba660..4ea3961 100644 --- a/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift +++ b/ConversationsClassic/View/Screens/Conversation/ConversationTextInput.swift @@ -6,6 +6,7 @@ struct ConversationTextInput: View { @State private var messageStr = "" @FocusState private var isFocused: Bool + @Binding var autoScroll: Bool var body: some View { VStack(spacing: 0) { @@ -19,7 +20,7 @@ struct ConversationTextInput: View { Text(replyText) .font(.body3) .foregroundColor(Color.Main.black) - .multilineTextAlignment(/*@START_MENU_TOKEN@*/ .leading/*@END_MENU_TOKEN@*/) + .multilineTextAlignment(.leading) .lineLimit(3) .padding(8) Spacer() @@ -48,7 +49,7 @@ struct ConversationTextInput: View { .foregroundColor(.Tango.blueLight) .padding(.leading, 8) .tappablePadding(.symmetric(8)) { - print("Attach file") + store.dispatch(.conversationAction(.showAttachmentPicker(true))) } TextField(L10n.Chat.textfieldPrompt, text: $messageStr) .font(.body1) @@ -75,6 +76,7 @@ struct ConversationTextInput: View { messageStr = "" // UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) store.dispatch(.conversationAction(.setReplyText(""))) + autoScroll = true } } } @@ -86,6 +88,12 @@ struct ConversationTextInput: View { isFocused = true } } + .fullScreenCover(isPresented: Binding( + get: { store.state.conversationsState.attachmentPickerVisible }, + set: { _ in } + )) { + AttachmentPickerScreen() + } } private var replyText: String {