mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-02 05:36:28 +00:00
rework, sheets
This commit is contained in:
@@ -9,13 +9,6 @@ import SwiftUI
|
||||
import Intents
|
||||
import SimpleXChat
|
||||
|
||||
enum HomeTab {
|
||||
case settings
|
||||
case contacts
|
||||
case chats
|
||||
case newChat
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@ObservedObject var alertManager = AlertManager.shared
|
||||
@@ -34,7 +27,7 @@ struct ContentView: View {
|
||||
@AppStorage(DEFAULT_PERFORM_LA) private var prefPerformLA = false
|
||||
@AppStorage(DEFAULT_PRIVACY_PROTECT_SCREEN) private var protectScreen = false
|
||||
@AppStorage(DEFAULT_NOTIFICATION_ALERT_SHOWN) private var notificationAlertShown = false
|
||||
@State private var homeTab: HomeTab = .chats
|
||||
@State private var showSettings = false
|
||||
@State private var showWhatsNew = false
|
||||
@State private var showChooseLAMode = false
|
||||
@State private var showSetPasscode = false
|
||||
@@ -81,7 +74,7 @@ struct ContentView: View {
|
||||
callView(call)
|
||||
}
|
||||
|
||||
if homeTab != .settings, let la = chatModel.laRequest {
|
||||
if !showSettings, let la = chatModel.laRequest {
|
||||
LocalAuthView(authRequest: la)
|
||||
.onDisappear {
|
||||
// this flag is separate from accessAuthenticated to show initializationView while we wait for authentication
|
||||
@@ -104,6 +97,9 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $alertManager.presentAlert) { alertManager.alertView! }
|
||||
.sheet(isPresented: $showSettings) {
|
||||
SettingsView(showSettings: $showSettings)
|
||||
}
|
||||
.confirmationDialog("SimpleX Lock mode", isPresented: $showChooseLAMode, titleVisibility: .visible) {
|
||||
Button("System authentication") { initialEnableLA() }
|
||||
Button("Passcode entry") { showSetPasscode = true }
|
||||
@@ -234,7 +230,7 @@ struct ContentView: View {
|
||||
|
||||
private func mainView() -> some View {
|
||||
ZStack(alignment: .top) {
|
||||
HomeView(homeTab: $homeTab).privacySensitive(protectScreen)
|
||||
HomeView(showSettings: $showSettings).privacySensitive(protectScreen)
|
||||
.onAppear {
|
||||
requestNtfAuthorization()
|
||||
// Local Authentication notice is to be shown on next start after onboarding is complete
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
|
||||
struct ChatHelp: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@State private var newChatMenuOption: NewChatMenuOption? = nil
|
||||
|
||||
var body: some View {
|
||||
@@ -24,7 +24,7 @@ struct ChatHelp: View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
Text("To ask any questions and to receive updates:")
|
||||
Button("connect to SimpleX Chat developers.") {
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
DispatchQueue.main.async {
|
||||
UIApplication.shared.open(simplexTeamURL)
|
||||
}
|
||||
@@ -63,6 +63,6 @@ struct ChatHelp: View {
|
||||
|
||||
struct ChatHelp_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
return ChatHelp(homeTab: Binding.constant(.chats))
|
||||
return ChatHelp(showSettings: Binding.constant(false))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ struct ChatListView: View {
|
||||
}
|
||||
}
|
||||
UserPicker(
|
||||
homeTab: Binding.constant(.chats),
|
||||
showSettings: $showSettings,
|
||||
showConnectDesktop: $showConnectDesktop,
|
||||
userPickerVisible: $userPickerVisible
|
||||
)
|
||||
|
||||
@@ -13,7 +13,7 @@ struct UserPicker: View {
|
||||
@EnvironmentObject var m: ChatModel
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@Environment(\.scenePhase) var scenePhase
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@Binding var showConnectDesktop: Bool
|
||||
@Binding var userPickerVisible: Bool
|
||||
@State var scrollViewContentSize: CGSize = .zero
|
||||
@@ -72,7 +72,7 @@ struct UserPicker: View {
|
||||
}
|
||||
Divider()
|
||||
menuButton("Settings", icon: "gearshape") {
|
||||
homeTab = .settings
|
||||
showSettings = true
|
||||
withAnimation {
|
||||
userPickerVisible.toggle()
|
||||
}
|
||||
@@ -106,7 +106,7 @@ struct UserPicker: View {
|
||||
let user = u.user
|
||||
return Button(action: {
|
||||
if user.activeUser {
|
||||
homeTab = .settings
|
||||
showSettings = true
|
||||
withAnimation {
|
||||
userPickerVisible.toggle()
|
||||
}
|
||||
@@ -181,7 +181,7 @@ struct UserPicker_Previews: PreviewProvider {
|
||||
let m = ChatModel()
|
||||
m.users = [UserInfo.sampleData, UserInfo.sampleData]
|
||||
return UserPicker(
|
||||
homeTab: Binding.constant(.chats),
|
||||
showSettings: Binding.constant(false),
|
||||
showConnectDesktop: Binding.constant(false),
|
||||
userPickerVisible: Binding.constant(true)
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ enum DatabaseAlert: Identifiable {
|
||||
|
||||
struct DatabaseView: View {
|
||||
@EnvironmentObject var m: ChatModel
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@State private var runChat = false
|
||||
@State private var alert: DatabaseAlert? = nil
|
||||
@State private var showFileImporter = false
|
||||
@@ -409,7 +409,7 @@ struct DatabaseView: View {
|
||||
|
||||
private func startChat() {
|
||||
if m.chatDbChanged {
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||
resetChatCtrl()
|
||||
do {
|
||||
@@ -493,6 +493,6 @@ func deleteChatAsync() async throws {
|
||||
|
||||
struct DatabaseView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
DatabaseView(homeTab: Binding.constant(.chats), chatItemTTL: .none)
|
||||
DatabaseView(showSettings: Binding.constant(false), chatItemTTL: .none)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,15 @@
|
||||
import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
enum HomeTab {
|
||||
case contacts
|
||||
case chats
|
||||
}
|
||||
|
||||
struct HomeView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@State private var homeTab: HomeTab = .chats
|
||||
@State private var userPickerVisible = false
|
||||
@State private var showConnectDesktop = false
|
||||
@State private var newChatMenuOption: NewChatMenuOption? = nil
|
||||
@@ -44,10 +50,8 @@ struct HomeView: View {
|
||||
// ZStack {
|
||||
VStack {
|
||||
switch homeTab {
|
||||
case .settings: settingsView()
|
||||
case .contacts: contactsView()
|
||||
case .chats: chatsView()
|
||||
case .newChat: newChatView()
|
||||
}
|
||||
}
|
||||
.toolbar {
|
||||
@@ -95,7 +99,7 @@ struct HomeView: View {
|
||||
}
|
||||
}
|
||||
UserPicker(
|
||||
homeTab: $homeTab,
|
||||
showSettings: $showSettings,
|
||||
showConnectDesktop: $showConnectDesktop,
|
||||
userPickerVisible: $userPickerVisible
|
||||
)
|
||||
@@ -129,7 +133,7 @@ struct HomeView: View {
|
||||
userPickerVisible.toggle()
|
||||
}
|
||||
} else {
|
||||
homeTab = .settings
|
||||
showSettings = true
|
||||
}
|
||||
} label: {
|
||||
if user.image != nil {
|
||||
@@ -150,7 +154,7 @@ struct HomeView: View {
|
||||
)
|
||||
}
|
||||
}
|
||||
.foregroundColor(homeTab == .settings ? .accentColor : .secondary)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
private func userUnreadBadge(_ text: Text? = Text(" "), size: CGFloat = 18) -> some View {
|
||||
@@ -177,30 +181,27 @@ struct HomeView: View {
|
||||
.foregroundColor(homeTab == .chats ? .accentColor : .secondary)
|
||||
}
|
||||
|
||||
@ViewBuilder private func newChatButton() -> some View {
|
||||
if homeTab != .newChat {
|
||||
Menu {
|
||||
Button {
|
||||
newChatMenuOption = .newContact
|
||||
homeTab = .newChat
|
||||
} label: {
|
||||
Text("Add contact")
|
||||
}
|
||||
Button {
|
||||
newChatMenuOption = .newGroup
|
||||
homeTab = .newChat
|
||||
} label: {
|
||||
Text("Create group")
|
||||
}
|
||||
private func newChatButton() -> some View {
|
||||
Menu {
|
||||
Button {
|
||||
newChatMenuOption = .newContact
|
||||
} label: {
|
||||
iconLabel("square.and.pencil", "New chat")
|
||||
Text("Add contact")
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
} else {
|
||||
Button {} label: {
|
||||
iconLabel("square.and.pencil", "New chat")
|
||||
Button {
|
||||
newChatMenuOption = .newGroup
|
||||
} label: {
|
||||
Text("Create group")
|
||||
}
|
||||
} label: {
|
||||
iconLabel("square.and.pencil", "New chat")
|
||||
}
|
||||
.foregroundColor(.secondary)
|
||||
.sheet(item: $newChatMenuOption) { opt in
|
||||
switch opt {
|
||||
case .newContact: NewChatView(selection: .invite)
|
||||
case .newGroup: AddGroupView()
|
||||
}
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +217,7 @@ struct HomeView: View {
|
||||
}
|
||||
|
||||
private func settingsView() -> some View {
|
||||
SettingsView(homeTab: $homeTab)
|
||||
SettingsView(showSettings: $showSettings)
|
||||
}
|
||||
|
||||
private func contactsView() -> some View {
|
||||
@@ -275,5 +276,5 @@ struct BlurView: UIViewRepresentable {
|
||||
}
|
||||
|
||||
#Preview {
|
||||
HomeView(homeTab: Binding.constant(.chats))
|
||||
HomeView(showSettings: Binding.constant(false))
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ private enum MigrateFromDeviceViewAlert: Identifiable {
|
||||
struct MigrateFromDevice: View {
|
||||
@EnvironmentObject var m: ChatModel
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@Binding var showProgressOnSettings: Bool
|
||||
@State private var migrationState: MigrationFromState = .chatStopInProgress
|
||||
@State private var useKeychain = storeDBPassphraseGroupDefault.get()
|
||||
@@ -555,7 +555,7 @@ struct MigrateFromDevice: View {
|
||||
} catch let error {
|
||||
fatalError("Error starting chat \(responseError(error))")
|
||||
}
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
}
|
||||
} catch let error {
|
||||
alert = .error(title: "Error deleting database", error: responseError(error))
|
||||
@@ -579,7 +579,7 @@ struct MigrateFromDevice: View {
|
||||
// Hide settings anyway if chatDbStatus is not ok, probably passphrase needs to be entered
|
||||
if dismiss || m.chatDbStatus != .ok {
|
||||
await MainActor.run {
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -729,6 +729,6 @@ private class MigrationChatReceiver {
|
||||
|
||||
struct MigrateFromDevice_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MigrateFromDevice(homeTab: Binding.constant(.chats), showProgressOnSettings: Binding.constant(false))
|
||||
MigrateFromDevice(showSettings: Binding.constant(false), showProgressOnSettings: Binding.constant(false))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ struct SettingsView: View {
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@EnvironmentObject var sceneDelegate: SceneDelegate
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@State private var showProgress: Bool = false
|
||||
|
||||
var body: some View {
|
||||
@@ -187,7 +187,7 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
UserProfilesView(homeTab: $homeTab)
|
||||
UserProfilesView(showSettings: $showSettings)
|
||||
} label: {
|
||||
settingsRow("person.crop.rectangle.stack") { Text("Your chat profiles") }
|
||||
}
|
||||
@@ -217,7 +217,7 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
MigrateFromDevice(homeTab: $homeTab, showProgressOnSettings: $showProgress)
|
||||
MigrateFromDevice(showSettings: $showSettings, showProgressOnSettings: $showProgress)
|
||||
.navigationTitle("Migrate device")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
} label: {
|
||||
@@ -278,7 +278,7 @@ struct SettingsView: View {
|
||||
Section("Help") {
|
||||
if let user = user {
|
||||
NavigationLink {
|
||||
ChatHelp(homeTab: $homeTab)
|
||||
ChatHelp(showSettings: $showSettings)
|
||||
.navigationTitle("Welcome \(user.displayName)!")
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
} label: {
|
||||
@@ -300,7 +300,7 @@ struct SettingsView: View {
|
||||
}
|
||||
settingsRow("number") {
|
||||
Button("Send questions and ideas") {
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
DispatchQueue.main.async {
|
||||
UIApplication.shared.open(simplexTeamURL)
|
||||
}
|
||||
@@ -354,7 +354,7 @@ struct SettingsView: View {
|
||||
|
||||
private func chatDatabaseRow() -> some View {
|
||||
NavigationLink {
|
||||
DatabaseView(homeTab: $homeTab, chatItemTTL: chatModel.chatItemTTL)
|
||||
DatabaseView(showSettings: $showSettings, chatItemTTL: chatModel.chatItemTTL)
|
||||
.navigationTitle("Your chat database")
|
||||
} label: {
|
||||
let color: Color = chatModel.chatDbEncrypted == false ? .orange : .secondary
|
||||
@@ -449,7 +449,7 @@ struct SettingsView_Previews: PreviewProvider {
|
||||
let chatModel = ChatModel()
|
||||
chatModel.currentUser = User.sampleData
|
||||
|
||||
return SettingsView(homeTab: Binding.constant(.chats))
|
||||
return SettingsView(showSettings: Binding.constant(false))
|
||||
.environmentObject(chatModel)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import SimpleXChat
|
||||
|
||||
struct UserProfilesView: View {
|
||||
@EnvironmentObject private var m: ChatModel
|
||||
@Binding var homeTab: HomeTab
|
||||
@Binding var showSettings: Bool
|
||||
@Environment(\.editMode) private var editMode
|
||||
@AppStorage(DEFAULT_SHOW_HIDDEN_PROFILES_NOTICE) private var showHiddenProfilesNotice = true
|
||||
@AppStorage(DEFAULT_SHOW_MUTE_PROFILE_ALERT) private var showMuteProfileAlert = true
|
||||
@@ -280,7 +280,7 @@ struct UserProfilesView: View {
|
||||
await MainActor.run {
|
||||
onboardingStageDefault.set(.step1_SimpleXInfo)
|
||||
m.onboardingStage = .step1_SimpleXInfo
|
||||
homeTab = .chats
|
||||
showSettings = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -403,6 +403,6 @@ public func chatPasswordHash(_ pwd: String, _ salt: String) -> String {
|
||||
|
||||
struct UserProfilesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
UserProfilesView(homeTab: Binding.constant(.settings))
|
||||
UserProfilesView(showSettings: Binding.constant(false))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user