From 63393eaf0bd7ba099ed5ec9be35eeaf92049f453 Mon Sep 17 00:00:00 2001 From: Arturs Krumins Date: Fri, 5 Jul 2024 14:34:03 +0200 Subject: [PATCH] ios: make theme wallpaper visible on iOS15, further improve scrolling (#4408) --- apps/ios/Shared/Model/ChatModel.swift | 4 ++-- apps/ios/Shared/Views/Chat/ChatView.swift | 6 +++--- apps/ios/Shared/Views/Chat/ReverseList.swift | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/apps/ios/Shared/Model/ChatModel.swift b/apps/ios/Shared/Model/ChatModel.swift index 02a31ecda4..141e6d5c42 100644 --- a/apps/ios/Shared/Model/ChatModel.swift +++ b/apps/ios/Shared/Model/ChatModel.swift @@ -702,7 +702,7 @@ final class ChatModel: ObservableObject { } i += 1 } - return UnreadChatItemCounts(totalBelow: totalBelow, unreadBelow: unreadBelow) + return UnreadChatItemCounts(isNearBottom: totalBelow < 16, unreadBelow: unreadBelow) } func topItemInView(itemsInView: Set) -> ChatItem? { @@ -740,7 +740,7 @@ struct NTFContactRequest { } struct UnreadChatItemCounts: Equatable { - var totalBelow: Int + var isNearBottom: Bool var unreadBelow: Int } diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index 40c97202b4..d0e73adccd 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -410,7 +410,7 @@ struct ChatView: View { init() { unreadChatItemCounts = UnreadChatItemCounts( - totalBelow: .zero, + isNearBottom: true, unreadBelow: .zero ) events @@ -425,9 +425,9 @@ struct ChatView: View { itemsInView } } - .throttle(for: .seconds(0.2), scheduler: DispatchQueue.main, latest: true) .map { ChatModel.shared.unreadChatItemCounts(itemsInView: $0) } .removeDuplicates() + .throttle(for: .seconds(0.2), scheduler: DispatchQueue.main, latest: true) .assign(to: \.unreadChatItemCounts, on: self) .store(in: &bag) } @@ -479,7 +479,7 @@ struct ChatView: View { scrollModel.scrollToItem(id: latestUnreadItem.id) } } - } else if counts.totalBelow > 16 { + } else if !counts.isNearBottom { circleButton { Image(systemName: "chevron.down") .foregroundColor(theme.colors.primary) diff --git a/apps/ios/Shared/Views/Chat/ReverseList.swift b/apps/ios/Shared/Views/Chat/ReverseList.swift index d8a362e847..ae6d900eb6 100644 --- a/apps/ios/Shared/Views/Chat/ReverseList.swift +++ b/apps/ios/Shared/Views/Chat/ReverseList.swift @@ -181,6 +181,7 @@ struct ReverseList: UIV /// Updates content of the cell /// For reference: https://noahgilmore.com/blog/swiftui-self-sizing-cells/ func set(content: Hosted, parent: UIViewController) { + hostingController.view.backgroundColor = .clear hostingController.rootView = content if let hostingView = hostingController.view { hostingView.invalidateIntrinsicContentSize()