199 lines
5.3 KiB
Swift
199 lines
5.3 KiB
Swift
//
|
|
// ContentView.swift
|
|
// AppClientBaseSwift
|
|
//
|
|
// Main tab container with TabView
|
|
// Container tab chính với TabView
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
// MARK: - Content View
|
|
// View Content
|
|
|
|
/// Main content view with tab-based navigation
|
|
/// View content chính với điều hướng tab
|
|
struct ContentView: View {
|
|
|
|
// MARK: - Properties
|
|
|
|
/// Currently selected tab
|
|
/// Tab đang được chọn
|
|
@State private var selectedTab: Tab = .home
|
|
|
|
/// Auth manager for authentication state
|
|
/// Quản lý xác thực cho trạng thái authentication
|
|
@StateObject private var authManager = AuthManager.shared
|
|
|
|
/// Whether to show welcome screen
|
|
/// Có hiển thị màn hình welcome không
|
|
@AppStorage(StorageKeys.isFirstLaunch) private var isFirstLaunch: Bool = true
|
|
|
|
// MARK: - Tab Enum
|
|
|
|
/// Available tabs
|
|
/// Các tab có sẵn
|
|
enum Tab: String, CaseIterable {
|
|
case home
|
|
case explore
|
|
case profile
|
|
|
|
/// Tab title
|
|
/// Tiêu đề tab
|
|
var title: String {
|
|
switch self {
|
|
case .home:
|
|
return "tab_home".localized
|
|
case .explore:
|
|
return "tab_explore".localized
|
|
case .profile:
|
|
return "tab_profile".localized
|
|
}
|
|
}
|
|
|
|
/// Tab icon
|
|
/// Icon tab
|
|
var icon: String {
|
|
switch self {
|
|
case .home:
|
|
return "house"
|
|
case .explore:
|
|
return "magnifyingglass"
|
|
case .profile:
|
|
return "person"
|
|
}
|
|
}
|
|
|
|
/// Selected tab icon
|
|
/// Icon tab khi được chọn
|
|
var selectedIcon: String {
|
|
switch self {
|
|
case .home:
|
|
return "house.fill"
|
|
case .explore:
|
|
return "magnifyingglass"
|
|
case .profile:
|
|
return "person.fill"
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Body
|
|
|
|
var body: some View {
|
|
Group {
|
|
switch authManager.authState {
|
|
case .unknown:
|
|
// Show loading while checking auth state
|
|
// Hiển thị loading khi đang kiểm tra trạng thái auth
|
|
loadingView
|
|
case .unauthenticated:
|
|
// Show auth flow
|
|
// Hiển thị luồng auth
|
|
AuthContainerView()
|
|
case .authenticated:
|
|
// Show main app content
|
|
// Hiển thị nội dung app chính
|
|
if isFirstLaunch {
|
|
WelcomeView {
|
|
withAnimation {
|
|
isFirstLaunch = false
|
|
}
|
|
}
|
|
} else {
|
|
mainTabView
|
|
}
|
|
}
|
|
}
|
|
.task {
|
|
await authManager.initialize()
|
|
}
|
|
}
|
|
|
|
// MARK: - Subviews
|
|
|
|
/// Loading view while checking auth
|
|
/// View loading khi đang kiểm tra auth
|
|
private var loadingView: some View {
|
|
ZStack {
|
|
Color.appBackground
|
|
.ignoresSafeArea()
|
|
|
|
VStack(spacing: 16) {
|
|
// App logo
|
|
ZStack {
|
|
Circle()
|
|
.fill(AppTheme.primaryGradient)
|
|
.frame(width: 80, height: 80)
|
|
|
|
Image(systemName: "location.fill")
|
|
.font(.system(size: 32))
|
|
.foregroundStyle(Color.textPrimary)
|
|
}
|
|
.shadow(color: AppTheme.cardShadow, radius: 20, x: 0, y: 10)
|
|
|
|
ProgressView()
|
|
.scaleEffect(1.2)
|
|
.tint(Color.brandAccent)
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Subviews
|
|
|
|
/// Main tab view container
|
|
/// Container tab view chính
|
|
private var mainTabView: some View {
|
|
TabView(selection: $selectedTab) {
|
|
// Home Tab
|
|
// Tab Home
|
|
HomeView()
|
|
.tabItem {
|
|
Label {
|
|
Text(Tab.home.title)
|
|
} icon: {
|
|
Image(
|
|
systemName: selectedTab == .home ? Tab.home.selectedIcon : Tab.home.icon
|
|
)
|
|
}
|
|
}
|
|
.tag(Tab.home)
|
|
|
|
// Explore Tab
|
|
// Tab Khám phá
|
|
ExploreView()
|
|
.tabItem {
|
|
Label {
|
|
Text(Tab.explore.title)
|
|
} icon: {
|
|
Image(
|
|
systemName: selectedTab == .explore
|
|
? Tab.explore.selectedIcon : Tab.explore.icon)
|
|
}
|
|
}
|
|
.tag(Tab.explore)
|
|
|
|
// Profile Tab
|
|
// Tab Profile
|
|
ProfileView()
|
|
.tabItem {
|
|
Label {
|
|
Text(Tab.profile.title)
|
|
} icon: {
|
|
Image(
|
|
systemName: selectedTab == .profile
|
|
? Tab.profile.selectedIcon : Tab.profile.icon)
|
|
}
|
|
}
|
|
.tag(Tab.profile)
|
|
}
|
|
.tint(Color.brandAccent)
|
|
}
|
|
}
|
|
|
|
// MARK: - Preview
|
|
|
|
#Preview {
|
|
ContentView()
|
|
}
|