This commit is contained in:
fmodf 2024-08-07 10:36:33 +02:00
parent 3685ee56e2
commit 0aafcf6362
5 changed files with 113 additions and 49 deletions

View file

@ -7,6 +7,7 @@ enum AppFlow: Codable {
case contacts case contacts
case settings case settings
case conversation case conversation
case createConversation
} }
struct AppState: Stateable { struct AppState: Stateable {

View file

@ -33,6 +33,9 @@ struct BaseNavigationView: View {
case .conversation: case .conversation:
ConversationScreen() ConversationScreen()
case .createConversation:
CreateConversationMainScreen()
} }
} }
} }

View file

@ -12,7 +12,15 @@ struct ChatsListScreen: View {
// Content // Content
VStack(spacing: 0) { VStack(spacing: 0) {
// Header // Header
ChatsScreenHeader() SharedNavigationBar(
centerText: SharedNavBarText(text: L10n.Chats.title),
rightButton: SharedNavBarButton(
image: Image(systemName: "square.and.pencil"),
action: {
store.dispatch(.changeFlow(.createConversation))
}
)
)
// Chats list // Chats list
if !store.state.chatsState.chats.isEmpty { 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 { private struct ChatsRow: View {
@EnvironmentObject var store: AppStore @EnvironmentObject var store: AppStore

View file

@ -1,8 +1,7 @@
import SwiftUI import SwiftUI
struct CreateRoomScreen: View { struct CreateConversationMainScreen: View {
@EnvironmentObject var store: AppStore @EnvironmentObject var store: AppStore
@Environment(\.presentationMode) var presentationMode
var body: some View { var body: some View {
ZStack { ZStack {
@ -13,29 +12,30 @@ struct CreateRoomScreen: View {
// Content // Content
VStack(spacing: 0) { VStack(spacing: 0) {
// Header // Header
CreateRoomScreenHeader(presentationMode: presentationMode) CreateConversationHeader()
// List with buttons // Chats list
List { // if !store.state.chatsState.chats.isEmpty {
CreateRoomRowButton(title: "Create group chat", image: "person.2.square.stack") { // List {
print("Create chat") // ForEach(store.state.chatsState.chats) { chat in
} // ChatsRow(chat: chat)
CreateRoomRowButton(title: "Find public chats", image: "magnifyingglass") { // }
print("Create group chat") // }
} // .listStyle(.plain)
} // .background(Color.Material.Background.light)
.listStyle(.plain) // } else {
.background(Color.Material.Background.light) // Spacer()
// }
// Tab bar //
Spacer() // // Tab bar
// SharedTabBar()
} }
} }
} }
} }
private struct CreateRoomScreenHeader: View { private struct CreateConversationHeader: View {
@Binding var presentationMode: PresentationMode @EnvironmentObject var store: AppStore
var body: some View { var body: some View {
ZStack { ZStack {
@ -44,11 +44,11 @@ private struct CreateRoomScreenHeader: View {
.ignoresSafeArea() .ignoresSafeArea()
HStack(spacing: 0) { HStack(spacing: 0) {
Image(systemName: "xmark") Image(systemName: "arrow.left")
.foregroundColor(.Material.Elements.active) .foregroundColor(.Material.Elements.active)
.padding(.trailing, 16) .padding(.leading, 16)
.tappablePadding(.symmetric(12)) { .tappablePadding(.symmetric(12)) {
presentationMode.dismiss() store.dispatch(.changeFlow(store.state.previousFlow))
} }
Spacer() Spacer()
} }

View file

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