From 4caad72d7d4103645f7109c33556d6a8fe8bf7c4 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:10:55 +0400 Subject: [PATCH] new chat menu --- apps/ios/Shared/Views/ChatList/ChatHelp.swift | 9 ++-- .../Shared/Views/ChatList/ChatListView.swift | 29 ++--------- .../Views/NewChat/NewChatInviteButton.swift | 31 ------------ .../Views/NewChat/NewChatMenuButton.swift | 50 +++++++++++++++++++ apps/ios/SimpleX.xcodeproj/project.pbxproj | 8 +-- 5 files changed, 63 insertions(+), 64 deletions(-) delete mode 100644 apps/ios/Shared/Views/NewChat/NewChatInviteButton.swift create mode 100644 apps/ios/Shared/Views/NewChat/NewChatMenuButton.swift diff --git a/apps/ios/Shared/Views/ChatList/ChatHelp.swift b/apps/ios/Shared/Views/ChatList/ChatHelp.swift index 7c6fe94ac6..a48a61b6bf 100644 --- a/apps/ios/Shared/Views/ChatList/ChatHelp.swift +++ b/apps/ios/Shared/Views/ChatList/ChatHelp.swift @@ -11,7 +11,7 @@ import SwiftUI struct ChatHelp: View { @EnvironmentObject var chatModel: ChatModel @Binding var showSettings: Bool - @State private var showNewChatSheet = false + @State private var newChatMenuOption: NewChatMenuOption? = nil var body: some View { ScrollView { chatHelp() } @@ -39,13 +39,12 @@ struct ChatHelp: View { HStack(spacing: 8) { Text("Tap button ") - NewChatInviteButton(showNewChatSheet: $showNewChatSheet) + NewChatMenuButton(newChatMenuOption: $newChatMenuOption) Text("above, then choose:") } - Text("**Create link / QR code** for your contact to use.") - Text("**Paste received link** or open it in the browser and tap **Open in mobile app**.") - Text("**Scan QR code**: to connect to your contact in person or via video call.") + Text("**New contact**: to create a new invitation link, or connect via a link you received.") + Text("**New group**: to create a new group.") } .padding(.top, 24) diff --git a/apps/ios/Shared/Views/ChatList/ChatListView.swift b/apps/ios/Shared/Views/ChatList/ChatListView.swift index c2aedebafa..59d0d9285a 100644 --- a/apps/ios/Shared/Views/ChatList/ChatListView.swift +++ b/apps/ios/Shared/Views/ChatList/ChatListView.swift @@ -14,10 +14,9 @@ struct ChatListView: View { @Binding var showSettings: Bool @State private var searchMode = false @State private var searchText = "" - @State private var showNewChatSheet = false + @State private var newChatMenuOption: NewChatMenuOption? = nil @State private var userPickerVisible = false @State private var showConnectDesktop = false - @State private var showCreateGroupSheet = false @AppStorage(DEFAULT_SHOW_UNREAD_AND_FAVORITES) private var showUnreadAndFavorites = false var body: some View { @@ -85,9 +84,6 @@ struct ChatListView: View { } .listStyle(.plain) .navigationBarTitleDisplayMode(.inline) - .sheet(isPresented: $showCreateGroupSheet) { - AddGroupView() - } .toolbar { ToolbarItem(placement: .navigationBarLeading) { let user = chatModel.currentUser ?? User.sampleData @@ -114,21 +110,17 @@ struct ChatListView: View { } ToolbarItem(placement: .principal) { HStack(spacing: 4) { + Text("Chats") + .font(.headline) if chatModel.chats.count > 0 { toggleFilterButton() } - Text("Chats") - .font(.headline) } .frame(maxWidth: .infinity, alignment: .center) } ToolbarItem(placement: .navigationBarTrailing) { switch chatModel.chatRunning { - case .some(true): - HStack(spacing: 12) { - createGroupButton() - NewChatInviteButton(showNewChatSheet: $showNewChatSheet) - } + case .some(true): NewChatMenuButton(newChatMenuOption: $newChatMenuOption) case .some(false): chatStoppedIcon() case .none: EmptyView() } @@ -137,17 +129,6 @@ struct ChatListView: View { .navigationBarHidden(searchMode) } - private func createGroupButton() -> some View { - Button { - showCreateGroupSheet = true - } label: { - Image(systemName: "plus") - .resizable() - .scaledToFit() - .frame(width: 20, height: 20) - } - } - private func toggleFilterButton() -> some View { Button { showUnreadAndFavorites = !showUnreadAndFavorites @@ -206,7 +187,7 @@ struct ChatListView: View { .padding(.trailing, 12) connectButton("Tap to start a new chat") { - showNewChatSheet = true + newChatMenuOption = .newContact } Spacer() diff --git a/apps/ios/Shared/Views/NewChat/NewChatInviteButton.swift b/apps/ios/Shared/Views/NewChat/NewChatInviteButton.swift deleted file mode 100644 index 98ec215eea..0000000000 --- a/apps/ios/Shared/Views/NewChat/NewChatInviteButton.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// NewChatInviteButton.swift -// SimpleX (iOS) -// -// Created by spaced4ndy on 28.11.2023. -// Copyright © 2023 SimpleX Chat. All rights reserved. -// - -import SwiftUI - -struct NewChatInviteButton: View { - @Binding var showNewChatSheet: Bool - - var body: some View { - Button { - showNewChatSheet = true - } label: { - Image(systemName: "square.and.pencil") - .resizable() - .scaledToFit() - .frame(width: 24, height: 24) - } - .sheet(isPresented: $showNewChatSheet) { - NewChatView(selection: .invite) - } - } -} - -//#Preview { -// NewChatInviteButton() -//} diff --git a/apps/ios/Shared/Views/NewChat/NewChatMenuButton.swift b/apps/ios/Shared/Views/NewChat/NewChatMenuButton.swift new file mode 100644 index 0000000000..f18257bee6 --- /dev/null +++ b/apps/ios/Shared/Views/NewChat/NewChatMenuButton.swift @@ -0,0 +1,50 @@ +// +// NewChatMenuButton.swift +// SimpleX (iOS) +// +// Created by spaced4ndy on 28.11.2023. +// Copyright © 2023 SimpleX Chat. All rights reserved. +// + +import SwiftUI + +enum NewChatMenuOption: Identifiable { + case newContact + case newGroup + + var id: Self { self } +} + +struct NewChatMenuButton: View { + @Binding var newChatMenuOption: NewChatMenuOption? + + var body: some View { + Menu { + Button { + newChatMenuOption = .newContact + } label: { + Text("New contact") + } + Button { + newChatMenuOption = .newGroup + } label: { + Text("New group") + } + } label: { + Image(systemName: "square.and.pencil") + .resizable() + .scaledToFit() + .frame(width: 24, height: 24) + } + .sheet(item: $newChatMenuOption) { opt in + switch opt { + case .newContact: NewChatView(selection: .invite) + case .newGroup: AddGroupView() + } + } + } +} + +//#Preview { +// NewChatMenuButton() +//} diff --git a/apps/ios/SimpleX.xcodeproj/project.pbxproj b/apps/ios/SimpleX.xcodeproj/project.pbxproj index 4eb8dacf43..9a8cfd9e4a 100644 --- a/apps/ios/SimpleX.xcodeproj/project.pbxproj +++ b/apps/ios/SimpleX.xcodeproj/project.pbxproj @@ -168,7 +168,7 @@ 64AA1C6927EE10C800AC7277 /* ContextItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AA1C6827EE10C800AC7277 /* ContextItemView.swift */; }; 64AA1C6C27F3537400AC7277 /* DeletedItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AA1C6B27F3537400AC7277 /* DeletedItemView.swift */; }; 64AEA4ED2B15D2A400334292 /* NewChatView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AEA4EC2B15D2A400334292 /* NewChatView.swift */; }; - 64AEA4EF2B15FEE100334292 /* NewChatInviteButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AEA4EE2B15FEE100334292 /* NewChatInviteButton.swift */; }; + 64AEA4EF2B15FEE100334292 /* NewChatMenuButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AEA4EE2B15FEE100334292 /* NewChatMenuButton.swift */; }; 64AEA4F72B1901AE00334292 /* libgmp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64AEA4F22B1901AE00334292 /* libgmp.a */; }; 64AEA4F82B1901AE00334292 /* libHSsimplex-chat-5.4.0.6-CwRTIkaIEVTLXC76NTPbOy-ghc9.6.3.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64AEA4F32B1901AE00334292 /* libHSsimplex-chat-5.4.0.6-CwRTIkaIEVTLXC76NTPbOy-ghc9.6.3.a */; }; 64AEA4F92B1901AE00334292 /* libffi.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 64AEA4F42B1901AE00334292 /* libffi.a */; }; @@ -448,7 +448,7 @@ 64AA1C6827EE10C800AC7277 /* ContextItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextItemView.swift; sourceTree = ""; }; 64AA1C6B27F3537400AC7277 /* DeletedItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeletedItemView.swift; sourceTree = ""; }; 64AEA4EC2B15D2A400334292 /* NewChatView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatView.swift; sourceTree = ""; }; - 64AEA4EE2B15FEE100334292 /* NewChatInviteButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatInviteButton.swift; sourceTree = ""; }; + 64AEA4EE2B15FEE100334292 /* NewChatMenuButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewChatMenuButton.swift; sourceTree = ""; }; 64AEA4F22B1901AE00334292 /* libgmp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgmp.a; sourceTree = ""; }; 64AEA4F32B1901AE00334292 /* libHSsimplex-chat-5.4.0.6-CwRTIkaIEVTLXC76NTPbOy-ghc9.6.3.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libHSsimplex-chat-5.4.0.6-CwRTIkaIEVTLXC76NTPbOy-ghc9.6.3.a"; sourceTree = ""; }; 64AEA4F42B1901AE00334292 /* libffi.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libffi.a; sourceTree = ""; }; @@ -723,7 +723,7 @@ 6442E0B9287F169300CEC0F9 /* AddGroupView.swift */, 64D0C2C529FAC1EC00B38D5F /* AddContactLearnMore.swift */, 64AEA4EC2B15D2A400334292 /* NewChatView.swift */, - 64AEA4EE2B15FEE100334292 /* NewChatInviteButton.swift */, + 64AEA4EE2B15FEE100334292 /* NewChatMenuButton.swift */, ); path = NewChat; sourceTree = ""; @@ -1102,7 +1102,7 @@ 5C13730B28156D2700F43030 /* ContactConnectionView.swift in Sources */, 644EFFE0292CFD7F00525D5B /* CIVoiceView.swift in Sources */, 6432857C2925443C00FBE5C8 /* GroupPreferencesView.swift in Sources */, - 64AEA4EF2B15FEE100334292 /* NewChatInviteButton.swift in Sources */, + 64AEA4EF2B15FEE100334292 /* NewChatMenuButton.swift in Sources */, 5C93293129239BED0090FFF9 /* ProtocolServerView.swift in Sources */, 5C9CC7AD28C55D7800BEF955 /* DatabaseEncryptionView.swift in Sources */, 5CBD285A295711D700EC2CF4 /* ImageUtils.swift in Sources */,