-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContentView.swift
More file actions
63 lines (58 loc) · 3.25 KB
/
ContentView.swift
File metadata and controls
63 lines (58 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import SwiftUI
import AVFoundation
struct ContentView: View {
@StateObject private var audioRecorder = AudioRecorder()
@State private var transcribedText = ""
@State private var chatResponse = ""
@State private var audioPlayer: AVAudioPlayer?
private let apiManager = APIManager()
@State private var selectedLanguage = "English"
@State private var showMainMenu = true
@State private var showLanguageSelection = false
@State private var showTranslateScreen = false
@State private var showTranslatorScreen = false
@State private var showSettings = false
@State private var durationTime = 0.4
@EnvironmentObject var userAuth: UserAuth
var body: some View {
ZStack {
Color.black.edgesIgnoringSafeArea(.all) // Ensures the background is always black
if !userAuth.isLoggedIn {
LoginPage(userAuth: userAuth)
.transition(.move(edge: .trailing).combined(with: .opacity))
.animation(.easeInOut(duration: durationTime), value: userAuth.isLoggedIn)
} else if showMainMenu {
MainMenuPage(showMainMenu: $showMainMenu, showLanguageSelection: $showLanguageSelection, showTranslateScreen: $showTranslateScreen, showTranslatorScreen: $showTranslatorScreen, showSettings: $showSettings)
.transition(.move(edge: .leading)) // Move from right to left
.animation(.easeInOut(duration: durationTime), value: showMainMenu)
} else if showLanguageSelection {
LanguageSelectionView(selectedLanguage: $selectedLanguage, showLanguageSelection: $showLanguageSelection, showMainMenu: $showMainMenu, showTranslatorScreen: $showTranslatorScreen, showTranslateScreen: $showTranslateScreen)
.transition(.move(edge: showTranslatorScreen ? .leading : .trailing))
.animation(.easeInOut(duration: durationTime), value: showLanguageSelection)
} else if showTranslateScreen {
TranslateScreenView(showMainMenu: $showMainMenu)
.transition(.move(edge: .trailing)) // Move from left to right
.animation(.easeInOut(duration: durationTime), value: showTranslateScreen)
} else if showTranslatorScreen {
TranslatorView(selectedLanguage: $selectedLanguage, showLanguageSelection: $showLanguageSelection)
.transition(.move(edge: .trailing)) // Move from left to right
.animation(.easeInOut(duration: durationTime), value: showTranslatorScreen)
} else if showSettings {
SettingsPage(showSettings: $showSettings, showMainMenu: $showMainMenu)
.transition(.move(edge: .trailing)) // Move from left to right
.animation(.easeInOut(duration: durationTime), value: showSettings)
}
}
.edgesIgnoringSafeArea(.top) // Ignore top safe area to prevent the dynamic island from blocking the content
}
private func resetState() {
showMainMenu = true
showLanguageSelection = false
showTranslateScreen = false
showTranslatorScreen = false
showSettings = false
}
}
#Preview {
ContentView().environmentObject(UserAuth())
}