diff --git a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift index ed8dfd9221..efbb3c1320 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupChatInfoView.swift @@ -45,8 +45,8 @@ struct GroupChatInfoView: View { Section { if groupInfo.canEdit { editGroupButton() - addOrEditWelcomeMessage() } + addOrEditWelcomeMessage() groupPreferencesButton($groupInfo) } header: { Text("") diff --git a/apps/ios/Shared/Views/Chat/Group/GroupWelcomeView.swift b/apps/ios/Shared/Views/Chat/Group/GroupWelcomeView.swift index 7aa372d5dc..7b90a4abe7 100644 --- a/apps/ios/Shared/Views/Chat/Group/GroupWelcomeView.swift +++ b/apps/ios/Shared/Views/Chat/Group/GroupWelcomeView.swift @@ -15,43 +15,101 @@ struct GroupWelcomeView: View { var groupId: Int64 @Binding var groupInfo: GroupInfo @State private var welcomeText: String = "" + @State private var editMode = true @FocusState private var keyboardVisible: Bool @State private var showSaveDialog = false var body: some View { - List { - Section { - TextEditor(text: $welcomeText) - .focused($keyboardVisible) - .padding(.horizontal, -5) - .padding(.top, -8) - .frame(height: 90, alignment: .topLeading) - .frame(maxWidth: .infinity, alignment: .leading) - } - Section { - saveButton() + VStack { + if groupInfo.canEdit { + editorView() + .modifier(BackButton { + if welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil) { + dismiss() + } else { + showSaveDialog = true + } + }) + .confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) { + Button("Save and update group profile") { + save() + dismiss() + } + Button("Exit without saving") { dismiss() } + } + } else { + List { + Section { + textPreview() + copyButton() + } + } } } .onAppear { welcomeText = groupInfo.groupProfile.description ?? "" - } - .modifier(BackButton { - if welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil) { - dismiss() - } else { - showSaveDialog = true - } - }) - .confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) { - Button("Save and update group profile") { - save() - dismiss() - } - Button("Exit without saving") { dismiss() } + keyboardVisible = true } } - @ViewBuilder private func saveButton() -> some View { + private func textPreview() -> some View { + messageText(welcomeText, parseSimpleXMarkdown(welcomeText), nil) + .allowsHitTesting(false) + } + + private func editorView() -> some View { + List { + Section { + if editMode { + ZStack { + Group { + if welcomeText.isEmpty { + TextEditor(text: Binding.constant(NSLocalizedString("Enter welcome message…", comment: "placeholder"))) + .foregroundColor(.secondary) + .disabled(true) + } + TextEditor(text: $welcomeText) + .focused($keyboardVisible) + } + .padding(.horizontal, -5) + .padding(.top, -8) + .frame(height: 90, alignment: .topLeading) + .frame(maxWidth: .infinity, alignment: .leading) + } + } else { + textPreview() + .frame(height: 90, alignment: .topLeading) + } + + Button { + editMode = !editMode + keyboardVisible = editMode + } label: { + if editMode { + Label ("Preview", systemImage: "character") + } else { + Label ("Edit", systemImage: "pencil") + } + } + .disabled(welcomeText.isEmpty) + copyButton() + } + + Section { + saveButton() + } + } + } + + private func copyButton() -> some View { + Button { + UIPasteboard.general.string = welcomeText + } label: { + Label ("Copy", systemImage: "doc.on.doc") + } + } + + private func saveButton() -> some View { Button("Save and update group profile") { save() }