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 settings
case conversation
case createConversation
}
struct AppState: Stateable {

View file

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

View file

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

View file

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

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