From 15ddefe86b0577e18aff2082280bb2201e32464d Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Tue, 31 May 2022 20:55:19 +0400 Subject: [PATCH] mobile: close modal views (#715) --- .../java/chat/simplex/app/MainActivity.kt | 5 +++- apps/ios/Shared/ContentView.swift | 27 ++++++++++--------- apps/ios/Shared/Model/ChatModel.swift | 1 + apps/ios/Shared/Views/Chat/ChatInfoView.swift | 7 +++-- apps/ios/Shared/Views/Chat/ChatView.swift | 7 +++-- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt index 829839ec7..a724d0fda 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt @@ -100,6 +100,7 @@ class MainActivity: FragmentActivity(), LifecycleEventObserver { userAuthorized.value = true } else { userAuthorized.value = false + ModalManager.shared.closeModals() authenticate( generalGetString(R.string.auth_unlock), generalGetString(R.string.auth_log_in_using_credential), @@ -241,7 +242,9 @@ fun MainPage( // this with LaunchedEffect(userAuthorized.value) fixes bottom sheet visibly collapsing after authentication var chatsAccessAuthorized by remember { mutableStateOf(false) } LaunchedEffect(userAuthorized.value) { - delay(500L) + if (chatModel.controller.appPrefs.performLA.get()) { + delay(500L) + } chatsAccessAuthorized = userAuthorized.value == true } var showAdvertiseLAAlert by remember { mutableStateOf(false) } diff --git a/apps/ios/Shared/ContentView.swift b/apps/ios/Shared/ContentView.swift index f9ba1bbaa..bb5ab76aa 100644 --- a/apps/ios/Shared/ContentView.swift +++ b/apps/ios/Shared/ContentView.swift @@ -70,18 +70,21 @@ struct ContentView: View { if !prefPerformLA { userAuthorized = true } else { - userAuthorized = false - authenticate(reason: NSLocalizedString("Unlock", comment: "authentication reason")) { laResult in - switch (laResult) { - case .success: - userAuthorized = true - case .failed: - laFailed = true - AlertManager.shared.showAlert(laFailedAlert()) - case .unavailable: - userAuthorized = true - prefPerformLA = false - AlertManager.shared.showAlert(laUnavailableTurningOffAlert()) + chatModel.showChatInfo = false + DispatchQueue.main.async() { + userAuthorized = false + authenticate(reason: NSLocalizedString("Unlock", comment: "authentication reason")) { laResult in + switch (laResult) { + case .success: + userAuthorized = true + case .failed: + laFailed = true + AlertManager.shared.showAlert(laFailedAlert()) + case .unavailable: + userAuthorized = true + prefPerformLA = false + AlertManager.shared.showAlert(laUnavailableTurningOffAlert()) + } } } } diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 4d4ae6ad9..ebb3f6731 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -14,6 +14,7 @@ import WebKit final class ChatModel: ObservableObject { @Published var onboardingStage: OnboardingStage? @Published var currentUser: User? + @Published var showChatInfo: Bool = false // TODO comprehensively close modal views on authentication // list of chat "previews" @Published var chats: [Chat] = [] // current chat diff --git a/apps/ios/Shared/Views/Chat/ChatInfoView.swift b/apps/ios/Shared/Views/Chat/ChatInfoView.swift index b7bd7ef58..18e253b89 100644 --- a/apps/ios/Shared/Views/Chat/ChatInfoView.swift +++ b/apps/ios/Shared/Views/Chat/ChatInfoView.swift @@ -12,7 +12,6 @@ struct ChatInfoView: View { @EnvironmentObject var chatModel: ChatModel @ObservedObject var alertManager = AlertManager.shared @ObservedObject var chat: Chat - @Binding var showChatInfo: Bool @State var alert: ChatInfoViewAlert? = nil @State var deletingContact: Contact? @@ -99,7 +98,7 @@ struct ChatInfoView: View { try await apiDeleteChat(type: .direct, id: contact.apiId) DispatchQueue.main.async { chatModel.removeChat(contact.id) - showChatInfo = false + chatModel.showChatInfo = false } } catch let error { logger.error("ChatInfoView.deleteContactAlert apiDeleteChat error: \(error.localizedDescription)") @@ -118,7 +117,7 @@ struct ChatInfoView: View { Task { await clearChat(chat) DispatchQueue.main.async { - showChatInfo = false + chatModel.showChatInfo = false } } }, @@ -130,6 +129,6 @@ struct ChatInfoView: View { struct ChatInfoView_Previews: PreviewProvider { static var previews: some View { @State var showChatInfo = true - return ChatInfoView(chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: []), showChatInfo: $showChatInfo) + return ChatInfoView(chat: Chat(chatInfo: ChatInfo.sampleData.direct, chatItems: [])) } } diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index 48d581d2c..b93252b53 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -18,7 +18,6 @@ struct ChatView: View { @State private var composeState = ComposeState() @State private var deletingItem: ChatItem? = nil @FocusState private var keyboardVisible: Bool - @State private var showChatInfo = false @State private var showDeleteMessage = false var body: some View { @@ -98,12 +97,12 @@ struct ChatView: View { } ToolbarItem(placement: .principal) { Button { - showChatInfo = true + chatModel.showChatInfo = true } label: { ChatInfoToolbar(chat: chat) } - .sheet(isPresented: $showChatInfo) { - ChatInfoView(chat: chat, showChatInfo: $showChatInfo) + .sheet(isPresented: $chatModel.showChatInfo) { + ChatInfoView(chat: chat) } } ToolbarItem(placement: .navigationBarTrailing) {