mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-23 15:03:16 +00:00
fade in chat item
This commit is contained in:
4 files changed
+33
-14
No files matched your search
@@ -61,7 +61,7 @@ class ItemsModel: ObservableObject {
|
||||
|
||||
init() {
|
||||
publisher
|
||||
.throttle(for: 0.25, scheduler: DispatchQueue.main, latest: true)
|
||||
.throttle(for: 1, scheduler: DispatchQueue.main, latest: true)
|
||||
.sink { self.objectWillChange.send() }
|
||||
.store(in: &bag)
|
||||
}
|
||||
@@ -452,14 +452,13 @@ final class ChatModel: ObservableObject {
|
||||
}
|
||||
return false
|
||||
} else {
|
||||
withConditionalAnimation(itemAnimation()) {
|
||||
var ci = cItem
|
||||
if let status = chatItemStatuses.removeValue(forKey: ci.id), case .sndNew = ci.meta.itemStatus {
|
||||
ci.meta.itemStatus = status
|
||||
}
|
||||
im.reversedChatItems.insert(ci, at: hasLiveDummy ? 1 : 0)
|
||||
im.itemAdded = true
|
||||
var ci = cItem
|
||||
if let status = chatItemStatuses.removeValue(forKey: ci.id), case .sndNew = ci.meta.itemStatus {
|
||||
ci.meta.itemStatus = status
|
||||
}
|
||||
if itemAnimation() != nil { FadeInChatItem.items.insert(ci.id) }
|
||||
im.reversedChatItems.insert(ci, at: hasLiveDummy ? 1 : 0)
|
||||
im.itemAdded = true
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -414,6 +414,7 @@ struct ChatView: View {
|
||||
revealedChatItem: $revealedChatItem,
|
||||
selectedChatItems: $selectedChatItems
|
||||
)
|
||||
.modifier(FadeInChatItem(id: ci.id))
|
||||
.onAppear {
|
||||
floatingButtonModel.appeared(viewId: ci.viewId)
|
||||
}
|
||||
@@ -1551,6 +1552,28 @@ private func buildTheme() -> AppTheme {
|
||||
}
|
||||
}
|
||||
|
||||
struct FadeInChatItem: ViewModifier {
|
||||
static var items = Set<ChatItem.ID>()
|
||||
private let chatItemId: ChatItem.ID
|
||||
@State private var isVisible: Bool
|
||||
|
||||
init(id: ChatItem.ID) {
|
||||
chatItemId = id
|
||||
isVisible = !Self.items.contains(chatItemId)
|
||||
}
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.opacity(isVisible ? 1 : 0)
|
||||
.onAppear {
|
||||
if !isVisible {
|
||||
Self.items.remove(chatItemId)
|
||||
withAnimation { isVisible = true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ToggleNtfsButton: View {
|
||||
@ObservedObject var chat: Chat
|
||||
|
||||
|
||||
@@ -175,9 +175,7 @@ struct ReverseList<Item: Identifiable & Hashable & Sendable, Content: View>: UIV
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||
snapshot.appendSections([.main])
|
||||
snapshot.appendItems(items)
|
||||
dataSource.defaultRowAnimation = items.count > itemCount
|
||||
? .top // Added items slide in from the bottom (top reversed)
|
||||
: .none // Replaced or removed rows are not animated
|
||||
dataSource.defaultRowAnimation = .none
|
||||
let countChange = abs(items.count - itemCount)
|
||||
dataSource.apply(snapshot, animatingDifferences:
|
||||
countChange > 0 && // Avoid animating initial load
|
||||
|
||||
+2
-3
@@ -6,8 +6,8 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/twostraws/CodeScanner",
|
||||
"state" : {
|
||||
"revision" : "c27a66149b7483fe42e2ec6aad61d5c3fffe522d",
|
||||
"version" : "2.1.1"
|
||||
"revision" : "34da57fb63b47add20de8a85da58191523ccce57",
|
||||
"version" : "2.5.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -23,7 +23,6 @@
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/kirualex/SwiftyGif",
|
||||
"state" : {
|
||||
"branch" : "master",
|
||||
"revision" : "5e8619335d394901379c9add5c4c1c2f420b3800"
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user