From 0aafcf63624a087a6a8259e98d0f116236e16679 Mon Sep 17 00:00:00 2001 From: fmodf Date: Wed, 7 Aug 2024 10:36:33 +0200 Subject: [PATCH] wip --- .../AppCore/State/AppState.swift | 1 + .../View/BaseNavigationView.swift | 3 + .../View/Screens/ChatsListScreen.swift | 36 +++------ ...ift => CreateConversationMainScreen.swift} | 44 +++++------ .../SharedNavigationBar.swift | 78 +++++++++++++++++++ 5 files changed, 113 insertions(+), 49 deletions(-) rename ConversationsClassic/View/Screens/Create/{CreateRoomScreen.swift => CreateConversationMainScreen.swift} (58%) create mode 100644 ConversationsClassic/View/SharedComponents/SharedNavigationBar.swift diff --git a/ConversationsClassic/AppCore/State/AppState.swift b/ConversationsClassic/AppCore/State/AppState.swift index 56f589f..ff00206 100644 --- a/ConversationsClassic/AppCore/State/AppState.swift +++ b/ConversationsClassic/AppCore/State/AppState.swift @@ -7,6 +7,7 @@ enum AppFlow: Codable { case contacts case settings case conversation + case createConversation } struct AppState: Stateable { diff --git a/ConversationsClassic/View/BaseNavigationView.swift b/ConversationsClassic/View/BaseNavigationView.swift index 558b471..9df484b 100644 --- a/ConversationsClassic/View/BaseNavigationView.swift +++ b/ConversationsClassic/View/BaseNavigationView.swift @@ -33,6 +33,9 @@ struct BaseNavigationView: View { case .conversation: ConversationScreen() + + case .createConversation: + CreateConversationMainScreen() } } } diff --git a/ConversationsClassic/View/Screens/ChatsListScreen.swift b/ConversationsClassic/View/Screens/ChatsListScreen.swift index 83e181d..7fde7bc 100644 --- a/ConversationsClassic/View/Screens/ChatsListScreen.swift +++ b/ConversationsClassic/View/Screens/ChatsListScreen.swift @@ -12,7 +12,15 @@ struct ChatsListScreen: View { // Content VStack(spacing: 0) { // Header - ChatsScreenHeader() + SharedNavigationBar( + centerText: SharedNavBarText(text: L10n.Chats.title), + rightButton: SharedNavBarButton( + image: Image(systemName: "square.and.pencil"), + action: { + store.dispatch(.changeFlow(.createConversation)) + } + ) + ) // Chats list if !store.state.chatsState.chats.isEmpty { @@ -34,32 +42,6 @@ struct ChatsListScreen: View { } } -private struct ChatsScreenHeader: View { - var body: some View { - ZStack { - // bg - Color.Material.Background.dark - .ignoresSafeArea() - - // title - Text(L10n.Chats.title) - .font(.head2) - .foregroundColor(Color.Material.Text.main) - - HStack { - Spacer() - Image(systemName: "square.and.pencil") - .foregroundColor(.Material.Elements.active) - .tappablePadding(.symmetric(12)) { - // print("Create new chat") - } - } - .padding(.horizontal, 16) - } - .frame(height: 44) - } -} - private struct ChatsRow: View { @EnvironmentObject var store: AppStore diff --git a/ConversationsClassic/View/Screens/Create/CreateRoomScreen.swift b/ConversationsClassic/View/Screens/Create/CreateConversationMainScreen.swift similarity index 58% rename from ConversationsClassic/View/Screens/Create/CreateRoomScreen.swift rename to ConversationsClassic/View/Screens/Create/CreateConversationMainScreen.swift index e5b0a00..8a8bf03 100644 --- a/ConversationsClassic/View/Screens/Create/CreateRoomScreen.swift +++ b/ConversationsClassic/View/Screens/Create/CreateConversationMainScreen.swift @@ -1,8 +1,7 @@ import SwiftUI -struct CreateRoomScreen: View { +struct CreateConversationMainScreen: View { @EnvironmentObject var store: AppStore - @Environment(\.presentationMode) var presentationMode var body: some View { ZStack { @@ -13,29 +12,30 @@ struct CreateRoomScreen: View { // Content VStack(spacing: 0) { // Header - CreateRoomScreenHeader(presentationMode: presentationMode) + CreateConversationHeader() - // List with buttons - List { - CreateRoomRowButton(title: "Create group chat", image: "person.2.square.stack") { - print("Create chat") - } - CreateRoomRowButton(title: "Find public chats", image: "magnifyingglass") { - print("Create group chat") - } - } - .listStyle(.plain) - .background(Color.Material.Background.light) - - // Tab bar - Spacer() + // Chats list + // if !store.state.chatsState.chats.isEmpty { + // List { + // ForEach(store.state.chatsState.chats) { chat in + // ChatsRow(chat: chat) + // } + // } + // .listStyle(.plain) + // .background(Color.Material.Background.light) + // } else { + // Spacer() + // } + // + // // Tab bar + // SharedTabBar() } } } } -private struct CreateRoomScreenHeader: View { - @Binding var presentationMode: PresentationMode +private struct CreateConversationHeader: View { + @EnvironmentObject var store: AppStore var body: some View { ZStack { @@ -44,11 +44,11 @@ private struct CreateRoomScreenHeader: View { .ignoresSafeArea() HStack(spacing: 0) { - Image(systemName: "xmark") + Image(systemName: "arrow.left") .foregroundColor(.Material.Elements.active) - .padding(.trailing, 16) + .padding(.leading, 16) .tappablePadding(.symmetric(12)) { - presentationMode.dismiss() + store.dispatch(.changeFlow(store.state.previousFlow)) } Spacer() } diff --git a/ConversationsClassic/View/SharedComponents/SharedNavigationBar.swift b/ConversationsClassic/View/SharedComponents/SharedNavigationBar.swift new file mode 100644 index 0000000..f6e651a --- /dev/null +++ b/ConversationsClassic/View/SharedComponents/SharedNavigationBar.swift @@ -0,0 +1,78 @@ +import SwiftUI + +struct SharedNavBarButton: View { + let image: Image? + let action: () -> Void + var isEnabled: Bool = true + + init( + image: Image, + action: @escaping () -> Void, + isEnabled: Bool = true + ) { + self.image = image + self.action = action + self.isEnabled = isEnabled + } + + var body: some View { + Button { + action() + } label: { + image + .foregroundColor(isEnabled ? .Material.Elements.active : .Material.Elements.inactive) + .tappablePadding(.symmetric(12)) { + action() + } + } + .disabled(!isEnabled) + } +} + +struct SharedNavBarText: View { + let text: String + + var body: some View { + Text(text) + .font(.head2) + .foregroundColor(.Material.Text.main) + } +} + +struct SharedNavigationBar: View { + var leftButton: SharedNavBarButton? + var centerText: SharedNavBarText? + var rightButton: SharedNavBarButton? + + var body: some View { + ZStack { + Color.Material.Background.dark + .ignoresSafeArea() + + VStack { + if centerText != nil { + centerText + } + } + Spacer() + + HStack(alignment: .center) { + VStack { + if leftButton != nil { + leftButton?.padding() + } + } + .frame(minWidth: 40) + Spacer() + VStack { + if rightButton != nil { + rightButton? + .padding() + } + } + .frame(minWidth: 40) + } + } + .frame(height: 44) + } +}