forked from mirrors/linphone-iphone
Fix message list animation
This commit is contained in:
parent
b46c2ef778
commit
14daf5bd40
3 changed files with 41 additions and 32 deletions
|
|
@ -217,6 +217,7 @@ struct ConversationFragment: View {
|
|||
conversationViewModel.resetMessage()
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
ScrollViewReader { proxy in
|
||||
List {
|
||||
ForEach(0..<conversationViewModel.conversationMessagesList.count, id: \.self) { index in
|
||||
|
|
@ -265,6 +266,7 @@ struct ConversationFragment: View {
|
|||
conversationViewModel.resetMessage()
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
HStack(spacing: 0) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ struct ConversationsListFragment: View {
|
|||
|
||||
@Binding var showingSheet: Bool
|
||||
|
||||
@State var canChangeChatRoom: Bool = true
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
|
|
@ -134,16 +136,35 @@ struct ConversationsListFragment: View {
|
|||
.listRowSeparator(.hidden)
|
||||
.background(.white)
|
||||
.onTapGesture {
|
||||
if conversationViewModel.displayedConversation != nil {
|
||||
conversationViewModel.displayedConversation = nil
|
||||
conversationViewModel.resetMessage()
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
conversationViewModel.getMessages()
|
||||
} else {
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
if canChangeChatRoom {
|
||||
if conversationViewModel.displayedConversation != nil {
|
||||
conversationViewModel.displayedConversation = nil
|
||||
conversationViewModel.resetMessage()
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
|
||||
let firstScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
||||
if firstScene != nil {
|
||||
let firstWindow = firstScene!.windows.first
|
||||
if firstWindow != nil {
|
||||
firstWindow!.layer.speed = 20.0
|
||||
canChangeChatRoom = false
|
||||
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
|
||||
firstWindow!.layer.speed = 1.0
|
||||
canChangeChatRoom = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conversationViewModel.getMessages()
|
||||
} else {
|
||||
withAnimation {
|
||||
conversationViewModel.changeDisplayedChatRoom(conversationModel: conversationsListViewModel.conversationsList[index])
|
||||
}
|
||||
}
|
||||
conversationsListViewModel.conversationsList[index].markAsRead()
|
||||
conversationsListViewModel.updateUnreadMessagesCount()
|
||||
}
|
||||
conversationsListViewModel.conversationsList[index].markAsRead()
|
||||
conversationsListViewModel.updateUnreadMessagesCount()
|
||||
}
|
||||
.onLongPressGesture(minimumDuration: 0.2) {
|
||||
conversationsListViewModel.selectedConversation = conversationsListViewModel.conversationsList[index]
|
||||
|
|
|
|||
|
|
@ -36,9 +36,8 @@ class ConversationViewModel: ObservableObject {
|
|||
|
||||
private var chatRoomSuscriptions = Set<AnyCancellable?>()
|
||||
|
||||
@Published var conversationMessagesList: [LinphoneCustomEventLog] = []
|
||||
@Published var conversationMessagesSection: [MessagesSection] = []
|
||||
@Published var conversationMessagesIds: [String] = []
|
||||
@Published var conversationMessagesSection: [MessagesSection] = []
|
||||
|
||||
init() {}
|
||||
|
||||
|
|
@ -97,13 +96,10 @@ class ConversationViewModel: ObservableObject {
|
|||
self.getUnreadMessagesCount()
|
||||
coreContext.doOnCoreQueue { _ in
|
||||
if self.displayedConversation != nil {
|
||||
let historyEvents = self.displayedConversation!.chatRoom.getHistoryRangeEvents(begin: self.conversationMessagesList.count, end: self.conversationMessagesList.count + 30)
|
||||
let historyEvents = self.displayedConversation!.chatRoom.getHistoryRangeEvents(begin: 0, end: 30)
|
||||
|
||||
var conversationMessage: [Message] = []
|
||||
historyEvents.enumerated().forEach { index, eventLog in
|
||||
DispatchQueue.main.async {
|
||||
self.conversationMessagesList.append(LinphoneCustomEventLog(eventLog: eventLog))
|
||||
}
|
||||
|
||||
var attachmentList: [Attachment] = []
|
||||
var contentText = ""
|
||||
|
|
@ -130,12 +126,11 @@ class ConversationViewModel: ObservableObject {
|
|||
isOutgoing: eventLog.chatMessage?.isOutgoing ?? false,
|
||||
text: contentText,
|
||||
attachments: attachmentList))
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if index == historyEvents.count - 1 {
|
||||
self.conversationMessagesSection.append(MessagesSection(date: Date(), rows: conversationMessage.reversed()))
|
||||
self.conversationMessagesIds.append(UUID().uuidString)
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if self.conversationMessagesSection.isEmpty {
|
||||
self.conversationMessagesSection.append(MessagesSection(date: Date(), rows: conversationMessage.reversed()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -145,14 +140,11 @@ class ConversationViewModel: ObservableObject {
|
|||
func getOldMessages() {
|
||||
coreContext.doOnCoreQueue { _ in
|
||||
if self.displayedConversation != nil {
|
||||
let historyEvents = self.displayedConversation!.chatRoom.getHistoryRangeEvents(begin: self.conversationMessagesList.count, end: self.conversationMessagesList.count + 30)
|
||||
var conversationMessagesListTmp: [LinphoneCustomEventLog] = []
|
||||
let historyEvents = self.displayedConversation!.chatRoom.getHistoryRangeEvents(begin: self.conversationMessagesSection[0].rows.count, end: self.conversationMessagesSection[0].rows.count + 30)
|
||||
var conversationMessagesTmp: [Message] = []
|
||||
|
||||
historyEvents.reversed().forEach { eventLog in
|
||||
conversationMessagesListTmp.insert(LinphoneCustomEventLog(eventLog: eventLog), at: 0)
|
||||
|
||||
var attachmentList: [Attachment] = []
|
||||
let attachmentList: [Attachment] = []
|
||||
var contentText = ""
|
||||
|
||||
if eventLog.chatMessage != nil && !eventLog.chatMessage!.contents.isEmpty {
|
||||
|
|
@ -175,7 +167,6 @@ class ConversationViewModel: ObservableObject {
|
|||
|
||||
if !conversationMessagesTmp.isEmpty {
|
||||
DispatchQueue.main.async {
|
||||
self.conversationMessagesList.insert(contentsOf: conversationMessagesListTmp, at: 0)
|
||||
self.conversationMessagesSection[0].rows.append(contentsOf: conversationMessagesTmp.reversed())
|
||||
}
|
||||
}
|
||||
|
|
@ -186,10 +177,6 @@ class ConversationViewModel: ObservableObject {
|
|||
func getNewMessages(eventLogs: [EventLog]) {
|
||||
var conversationMessage: [Message] = []
|
||||
eventLogs.enumerated().forEach { index, eventLog in
|
||||
DispatchQueue.main.async {
|
||||
self.conversationMessagesList.append(LinphoneCustomEventLog(eventLog: eventLog))
|
||||
}
|
||||
|
||||
var attachmentList: [Attachment] = []
|
||||
var contentText = ""
|
||||
|
||||
|
|
@ -230,7 +217,6 @@ class ConversationViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func resetMessage() {
|
||||
conversationMessagesList = []
|
||||
conversationMessagesSection = []
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue