From 54f1c2a27d819da522f2219c938efe9f0d0671cf Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 14 Oct 2024 12:33:14 +0200 Subject: [PATCH] Move enteredForeground variable to CoreContext and add a check before using prepareBottomSheetForDeliveryStatus --- Linphone/Core/CoreContext.swift | 1 + Linphone/UI/Call/CallView.swift | 8 ++------ Linphone/UI/Main/ContentView.swift | 13 ++++--------- .../UI/Main/Conversations/ConversationsView.swift | 7 ++----- .../Conversations/Fragments/ChatBubbleView.swift | 8 ++++++-- .../Fragments/ConversationFragment.swift | 7 +++---- .../Fragments/ConversationsFragment.swift | 8 +++----- .../Fragments/ConversationsListFragment.swift | 9 +++------ 8 files changed, 24 insertions(+), 37 deletions(-) diff --git a/Linphone/Core/CoreContext.swift b/Linphone/Core/CoreContext.swift index b2a95fdd0..5f168ff1f 100644 --- a/Linphone/Core/CoreContext.swift +++ b/Linphone/Core/CoreContext.swift @@ -41,6 +41,7 @@ final class CoreContext: ObservableObject { @Published var loggingInProgress: Bool = false @Published var coreIsStarted: Bool = false @Published var accounts: [AccountModel] = [] + @Published var enteredForeground = false private var mCore: Core! private var mIterateSuscription: AnyCancellable? diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index 494c46680..d0e46d4b6 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -68,8 +68,6 @@ struct CallView: View { @State var buttonSize = 60.0 - @Binding var enteredForeground: Bool - var body: some View { GeometryReader { geo in ZStack { @@ -199,8 +197,7 @@ struct CallView: View { conversationViewModel: conversationViewModel, conversationsListViewModel: conversationsListViewModel, conversationForwardMessageViewModel: conversationForwardMessageViewModel, - isShowConversationFragment: $isShowConversationFragment, - enteredForeground: $enteredForeground + isShowConversationFragment: $isShowConversationFragment ) .frame(maxWidth: .infinity) .background(Color.gray100) @@ -2788,8 +2785,7 @@ struct PressedButtonStyle: ButtonStyle { conversationForwardMessageViewModel: ConversationForwardMessageViewModel(), fullscreenVideo: .constant(false), isShowStartCallFragment: .constant(false), - isShowConversationFragment: .constant(false), - enteredForeground: .constant(false) + isShowConversationFragment: .constant(false) ) } // swiftlint:enable type_body_length diff --git a/Linphone/UI/Main/ContentView.swift b/Linphone/UI/Main/ContentView.swift index 497b8ea6f..776f6f0bd 100644 --- a/Linphone/UI/Main/ContentView.swift +++ b/Linphone/UI/Main/ContentView.swift @@ -75,8 +75,6 @@ struct ContentView: View { @State var isShowScheduleMeetingFragment = false @State private var isShowLoginFragment: Bool = false - @State private var enteredForeground: Bool = false - var body: some View { let pub = NotificationCenter.default .publisher(for: NSNotification.Name("ContactLoaded")) @@ -599,8 +597,7 @@ struct ContentView: View { conversationViewModel: conversationViewModel, conversationsListViewModel: conversationsListViewModel, text: $text, - isShowStartConversationFragment: $isShowStartConversationFragment, - enteredForeground: $enteredForeground + isShowStartConversationFragment: $isShowStartConversationFragment ) .roundedCorner(25, corners: [.topRight, .topLeft]) .shadow( @@ -864,8 +861,7 @@ struct ContentView: View { conversationViewModel: conversationViewModel, conversationsListViewModel: conversationsListViewModel, conversationForwardMessageViewModel: conversationForwardMessageViewModel, - isShowConversationFragment: $isShowConversationFragment, - enteredForeground: $enteredForeground + isShowConversationFragment: $isShowConversationFragment ) .frame(maxWidth: .infinity) .background(Color.gray100) @@ -1180,8 +1176,7 @@ struct ContentView: View { conversationForwardMessageViewModel: conversationForwardMessageViewModel, fullscreenVideo: $fullscreenVideo, isShowStartCallFragment: $isShowStartCallFragment, - isShowConversationFragment: $isShowConversationFragment, - enteredForeground: $enteredForeground + isShowConversationFragment: $isShowConversationFragment ) .zIndex(5) .transition(.scale.combined(with: .move(edge: .top))) @@ -1235,7 +1230,7 @@ struct ContentView: View { orientation = newOrientation } .onChange(of: scenePhase) { newPhase in - enteredForeground = newPhase == .active + CoreContext.shared.enteredForeground = newPhase == .active } } diff --git a/Linphone/UI/Main/Conversations/ConversationsView.swift b/Linphone/UI/Main/Conversations/ConversationsView.swift index 06a120dd5..3918ed6c8 100644 --- a/Linphone/UI/Main/Conversations/ConversationsView.swift +++ b/Linphone/UI/Main/Conversations/ConversationsView.swift @@ -27,12 +27,10 @@ struct ConversationsView: View { @Binding var isShowStartConversationFragment: Bool - @Binding var enteredForeground: Bool - var body: some View { NavigationView { ZStack(alignment: .bottomTrailing) { - ConversationsFragment(conversationViewModel: conversationViewModel, conversationsListViewModel: conversationsListViewModel, text: $text, enteredForeground: $enteredForeground) + ConversationsFragment(conversationViewModel: conversationViewModel, conversationsListViewModel: conversationsListViewModel, text: $text) Button { withAnimation { @@ -64,7 +62,6 @@ struct ConversationsView: View { conversationViewModel: ConversationViewModel(), conversationsListViewModel: ConversationsListViewModel(), showingSheet: .constant(false), - text: .constant(""), - enteredForeground: .constant(false) + text: .constant("") ) } diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index e4a4c0c4d..fab330f10 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -24,6 +24,8 @@ import WebKit // swiftlint:disable cyclomatic_complexity struct ChatBubbleView: View { + @ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared + @ObservedObject var conversationViewModel: ConversationViewModel let eventLogMessage: EventLogMessage @@ -255,8 +257,10 @@ struct ChatBubbleView: View { } } .onTapGesture { - conversationViewModel.selectedMessageToDisplayDetails = eventLogMessage - conversationViewModel.prepareBottomSheetForDeliveryStatus() + if !CoreContext.shared.enteredForeground { + conversationViewModel.selectedMessageToDisplayDetails = eventLogMessage + conversationViewModel.prepareBottomSheetForDeliveryStatus() + } } .disabled(conversationViewModel.selectedMessage != nil) .padding(.top, -4) diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift index c0b1707b5..4a60f942e 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift @@ -28,6 +28,7 @@ struct ConversationFragment: View { private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom } @ObservedObject var contactsManager = ContactsManager.shared + @ObservedObject private var sharedMainViewModel = SharedMainViewModel.shared @ObservedObject var conversationViewModel: ConversationViewModel @ObservedObject var conversationsListViewModel: ConversationsListViewModel @@ -58,8 +59,6 @@ struct ConversationFragment: View { @State private var selectedCategoryIndex = 0 - @Binding var enteredForeground: Bool - var body: some View { NavigationView { GeometryReader { geometry in @@ -575,7 +574,7 @@ struct ConversationFragment: View { .focused($isMessageTextFocused) .padding(.vertical, 5) .onChange(of: conversationViewModel.messageText) { text in - if !text.isEmpty && !enteredForeground { + if !text.isEmpty && !CoreContext.shared.enteredForeground { conversationViewModel.compose() } } @@ -588,7 +587,7 @@ struct ConversationFragment: View { .default_text_style(styleSize: 15) .focused($isMessageTextFocused) .onChange(of: conversationViewModel.messageText) { text in - if !text.isEmpty && !enteredForeground { + if !text.isEmpty && !CoreContext.shared.enteredForeground { conversationViewModel.compose() } } diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationsFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationsFragment.swift index 22e62e055..b91bf86e0 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationsFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationsFragment.swift @@ -29,13 +29,11 @@ struct ConversationsFragment: View { @State var showingSheet: Bool = false @Binding var text: String - @Binding var enteredForeground: Bool - var body: some View { ZStack { if #available(iOS 16.0, *), idiom != .pad { ConversationsListFragment(conversationViewModel: conversationViewModel, - conversationsListViewModel: conversationsListViewModel, showingSheet: $showingSheet, text: $text, enteredForeground: $enteredForeground) + conversationsListViewModel: conversationsListViewModel, showingSheet: $showingSheet, text: $text) .sheet(isPresented: $showingSheet) { ConversationsListBottomSheet( conversationsListViewModel: conversationsListViewModel, @@ -45,7 +43,7 @@ struct ConversationsFragment: View { } } else { ConversationsListFragment(conversationViewModel: conversationViewModel, - conversationsListViewModel: conversationsListViewModel, showingSheet: $showingSheet, text: $text, enteredForeground: $enteredForeground) + conversationsListViewModel: conversationsListViewModel, showingSheet: $showingSheet, text: $text) .halfSheet(showSheet: $showingSheet) { ConversationsListBottomSheet( conversationsListViewModel: conversationsListViewModel, @@ -58,5 +56,5 @@ struct ConversationsFragment: View { } #Preview { - ConversationsFragment(conversationViewModel: ConversationViewModel(), conversationsListViewModel: ConversationsListViewModel(), text: .constant(""), enteredForeground: .constant(false)) + ConversationsFragment(conversationViewModel: ConversationViewModel(), conversationsListViewModel: ConversationsListViewModel(), text: .constant("")) } diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationsListFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationsListFragment.swift index 2e4e8fc75..e4cdd1fcd 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationsListFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationsListFragment.swift @@ -30,8 +30,6 @@ struct ConversationsListFragment: View { @Binding var showingSheet: Bool @Binding var text: String - @Binding var enteredForeground: Bool - var body: some View { let pub = NotificationCenter.default .publisher(for: NSNotification.Name("ChatRoomsComputed")) @@ -143,14 +141,14 @@ struct ConversationsListFragment: View { .listRowSeparator(.hidden) .background(.white) .onReceive(pub) { _ in - if enteredForeground && conversationViewModel.displayedConversation != nil + if CoreContext.shared.enteredForeground && conversationViewModel.displayedConversation != nil && (navigationManager.peerAddr == nil || navigationManager.peerAddr == conversationViewModel.displayedConversation!.remoteSipUri) { if conversationViewModel.displayedConversation != nil { conversationViewModel.resetDisplayedChatRoom(conversationsList: conversationsListViewModel.conversationsList) } } - enteredForeground = false + CoreContext.shared.enteredForeground = false if navigationManager.peerAddr != nil && index < conversationsListViewModel.conversationsList.count @@ -206,7 +204,6 @@ struct ConversationsListFragment: View { conversationViewModel: ConversationViewModel(), conversationsListViewModel: ConversationsListViewModel(), showingSheet: .constant(false), - text: .constant(""), - enteredForeground: .constant(false) + text: .constant("") ) }