From 768f505559eb4930acc03f152d00e1d0561d0aa5 Mon Sep 17 00:00:00 2001 From: "benoit.martins" Date: Wed, 10 May 2023 18:37:34 +0200 Subject: [PATCH] Add leading and trailing SwipeActions for bubbles --- .../ChatConversationTableViewSwift.swift | 50 ++++++++++++++----- .../Chat/Views/MultilineMessageCell.swift | 15 ++---- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift index 89227435a..880fb4b60 100644 --- a/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift +++ b/Classes/Swift/Chat/Views/ChatConversationTableViewSwift.swift @@ -22,8 +22,38 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour func compositeViewDescription() -> UICompositeViewDescription! { return type(of: self).compositeDescription } var collectionView: UICollectionView = { - let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) - return collectionView + if #available(iOS 14.0, *) { + var listConfiguration = UICollectionLayoutListConfiguration(appearance: .plain) + + listConfiguration.leadingSwipeActionsConfigurationProvider = { indexPath in + let rep = UIContextualAction(style: .normal, title: "Reply") { + action, view, completion in + //self?.deleteMessage(at: indexPath) + completion(true) + } + return UISwipeActionsConfiguration(actions: [rep]) + } + + listConfiguration.trailingSwipeActionsConfigurationProvider = { indexPath in + let del = UIContextualAction(style: .destructive, title: "Delete") { + action, view, completion in + //self?.deleteMessage(at: indexPath) + completion(true) + } + return UISwipeActionsConfiguration(actions: [del]) + } + + listConfiguration.showsSeparators = false + + let layout = UICollectionViewCompositionalLayout.list(using: listConfiguration) + layout.configuration.contentInsetsReference = .layoutMargins + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) + collectionView.layoutMargins = .init(top: 100, left: 100, bottom: 100, right: 100) + return collectionView + } else { + let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout()) + return collectionView + } }() var menu: DropDown? = nil @@ -90,9 +120,12 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour collectionView.delegate = self collectionView.register(MultilineMessageCell.self, forCellWithReuseIdentifier: MultilineMessageCell.reuseId) - (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).estimatedItemSize = UICollectionViewFlowLayout.automaticSize - (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).minimumLineSpacing = 2 - + if #available(iOS 14.0, *) { + collectionView.autoresizingMask = [.flexibleHeight, .flexibleWidth] + } else { + (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).estimatedItemSize = UICollectionViewFlowLayout.automaticSize + (collectionView.collectionViewLayout as! UICollectionViewFlowLayout).minimumLineSpacing = 2 + } collectionView.transform = CGAffineTransform(scaleX: 1, y: -1) } @@ -234,13 +267,6 @@ class ChatConversationTableViewSwift: UIViewController, UICollectionViewDataSour return ChatConversationTableViewModel.sharedModel.getNBMessages() } - // MARK: - UICollectionViewDelegateFlowLayout - - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let referenceHeight: CGFloat = 100 - let referenceWidth: CGFloat = 100 - return CGSize(width: referenceWidth, height: referenceHeight) - } - func isBasicChatRoom(_ room: OpaquePointer?) -> Bool { if room == nil { return true diff --git a/Classes/Swift/Chat/Views/MultilineMessageCell.swift b/Classes/Swift/Chat/Views/MultilineMessageCell.swift index d620cf63b..afebd6c3b 100644 --- a/Classes/Swift/Chat/Views/MultilineMessageCell.swift +++ b/Classes/Swift/Chat/Views/MultilineMessageCell.swift @@ -173,7 +173,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI eventMessageView.isHidden = true - //Message contentView.addSubview(contactDateLabel) @@ -204,20 +203,18 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI contentBubble.addSubview(bubble) bubble.translatesAutoresizingMaskIntoConstraints = false - bubble.topAnchor.constraint(equalTo: contactDateLabel.bottomAnchor).isActive = true - bubble.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true + bubble.topAnchor.constraint(equalTo: contactDateLabel.bottomAnchor, constant: 2).isActive = true + bubble.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -2).isActive = true bubble.leadingAnchor.constraint(equalTo: contentBubble.leadingAnchor).isActive = true bubble.trailingAnchor.constraint(equalTo: contentBubble.trailingAnchor).isActive = true bubble.layer.cornerRadius = 10.0 contentBubble.addSubview(chatRead) - chatRead.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -2).isActive = true + chatRead.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -4).isActive = true chatRead.trailingAnchor.constraint(equalTo: deleteItemCheckBox.leadingAnchor, constant: -8).isActive = true chatRead.size(w: 10, h: 10).done() chatRead.isHidden = true - - //PreContentViewBubble bubble.addSubview(preContentViewBubble) preContentViewBubble.translatesAutoresizingMaskIntoConstraints = false @@ -317,8 +314,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI replyView.isHidden = true - - //ContentViewBubble bubble.addSubview(contentViewBubble) contentViewBubble.translatesAutoresizingMaskIntoConstraints = false @@ -1004,10 +999,6 @@ class MultilineMessageCell: UICollectionViewCell, UICollectionViewDataSource, UI let regex = try! NSRegularExpression(pattern: "sips:(\\S+)") - - //matches = detector.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count)) - //let matchesSips = regex.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count)) - let matchesSips = detector.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count)) matches = regex.matches(in: input, options: [], range: NSRange(location: 0, length: input.utf16.count))