105 lines
3.7 KiB
Swift
105 lines
3.7 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@StateObject private var identity = IdentityManager.shared
|
|
@StateObject private var chats = ChatsStore.shared
|
|
|
|
var body: some View {
|
|
Group {
|
|
if identity.identity == nil {
|
|
OnboardingView()
|
|
.environmentObject(identity)
|
|
} else {
|
|
MainTabs()
|
|
.environmentObject(identity)
|
|
}
|
|
}
|
|
.onChange(of: identity.identity?.accountID) { _, newID in
|
|
if newID != nil, let id = identity.identity {
|
|
chats.startPolling(identity: id)
|
|
chats.attachWebSocket(identity: id)
|
|
} else {
|
|
chats.stopPolling()
|
|
WebSocketLink.shared.disconnect()
|
|
}
|
|
}
|
|
.task {
|
|
if let id = identity.identity {
|
|
chats.startPolling(identity: id)
|
|
chats.attachWebSocket(identity: id)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct MainTabs: View {
|
|
@State private var selection: Tab = .chats
|
|
|
|
enum Tab { case contacts, chats, settings }
|
|
|
|
init() {
|
|
let appearance = UITabBarAppearance()
|
|
appearance.configureWithOpaqueBackground()
|
|
appearance.backgroundColor = UIColor.black
|
|
appearance.shadowColor = UIColor(ClaudeTheme.Palette.gold).withAlphaComponent(0.18)
|
|
|
|
let normal = UIColor(ClaudeTheme.Palette.textTertiary)
|
|
let active = UIColor(ClaudeTheme.Palette.gold)
|
|
appearance.stackedLayoutAppearance.normal.iconColor = normal
|
|
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [
|
|
.foregroundColor: normal,
|
|
.font: UIFont.systemFont(ofSize: 10, weight: .medium)
|
|
]
|
|
appearance.stackedLayoutAppearance.selected.iconColor = active
|
|
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [
|
|
.foregroundColor: active,
|
|
.font: UIFont.systemFont(ofSize: 10, weight: .semibold)
|
|
]
|
|
UITabBar.appearance().standardAppearance = appearance
|
|
UITabBar.appearance().scrollEdgeAppearance = appearance
|
|
|
|
let nav = UINavigationBarAppearance()
|
|
nav.configureWithOpaqueBackground()
|
|
nav.backgroundColor = UIColor.black
|
|
nav.shadowColor = UIColor(ClaudeTheme.Palette.gold).withAlphaComponent(0.18)
|
|
nav.titleTextAttributes = [
|
|
.foregroundColor: UIColor(ClaudeTheme.Palette.textPrimary),
|
|
.font: UIFont.systemFont(ofSize: 17, weight: .semibold)
|
|
]
|
|
UINavigationBar.appearance().standardAppearance = nav
|
|
UINavigationBar.appearance().scrollEdgeAppearance = nav
|
|
UINavigationBar.appearance().compactAppearance = nav
|
|
UINavigationBar.appearance().tintColor = UIColor(ClaudeTheme.Palette.gold)
|
|
}
|
|
|
|
var body: some View {
|
|
TabView(selection: $selection) {
|
|
ContactsView()
|
|
.tabItem {
|
|
Image(systemName: selection == .contacts ? "person.2.fill" : "person.2")
|
|
Text("Контакты")
|
|
}
|
|
.tag(Tab.contacts)
|
|
|
|
ChatsView()
|
|
.tabItem {
|
|
Image(systemName: selection == .chats ? "bubble.left.and.bubble.right.fill" : "bubble.left.and.bubble.right")
|
|
Text("Чаты")
|
|
}
|
|
.tag(Tab.chats)
|
|
|
|
SettingsView()
|
|
.tabItem {
|
|
Image(systemName: selection == .settings ? "gearshape.fill" : "gearshape")
|
|
Text("Настройки")
|
|
}
|
|
.tag(Tab.settings)
|
|
}
|
|
.tint(ClaudeTheme.Palette.gold)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ContentView()
|
|
}
|