session-ios/Session/Conversations/Message Cells/TypingIndicatorCell.swift

101 lines
3.1 KiB
Swift
Raw Normal View History

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import UIKit
import SessionUIKit
import SessionMessagingKit
2021-01-29 01:46:32 +01:00
// Assumptions
// We'll never encounter an outgoing typing indicator.
// Typing indicators are only sent in contact threads.
final class TypingIndicatorCell: MessageCell {
// MARK: - UI
2021-01-29 01:46:32 +01:00
private lazy var bubbleView: UIView = {
let result: UIView = UIView()
2021-01-29 01:46:32 +01:00
result.layer.cornerRadius = VisibleMessageCell.smallCornerRadius
result.themeBackgroundColor = .messageBubble_incomingBackground
2021-01-29 01:46:32 +01:00
return result
}()
private let bubbleViewMaskLayer: CAShapeLayer = CAShapeLayer()
2021-01-29 01:46:32 +01:00
public lazy var typingIndicatorView: TypingIndicatorView = TypingIndicatorView()
2021-01-29 01:46:32 +01:00
// MARK: - Lifecycle
2021-01-29 01:46:32 +01:00
override func setUpViewHierarchy() {
super.setUpViewHierarchy()
2021-01-29 01:46:32 +01:00
// Bubble view
addSubview(bubbleView)
bubbleView.pin(.left, to: .left, of: self, withInset: VisibleMessageCell.contactThreadHSpacing)
bubbleView.pin(.top, to: .top, of: self, withInset: 1)
2021-01-29 01:46:32 +01:00
// Typing indicator view
bubbleView.addSubview(typingIndicatorView)
typingIndicatorView.pin(to: bubbleView, withInset: 12)
}
// MARK: - Updating
Merge branch 'feature/database-refactor' into emoji-reacts # Conflicts: # Session.xcodeproj/project.pbxproj # Session/Conversations/Context Menu/ContextMenuVC+Action.swift # Session/Conversations/Context Menu/ContextMenuVC+ActionView.swift # Session/Conversations/Context Menu/ContextMenuVC.swift # Session/Conversations/ConversationVC+Interaction.swift # Session/Conversations/ConversationVC.swift # Session/Conversations/ConversationViewItem.h # Session/Conversations/ConversationViewItem.m # Session/Conversations/Message Cells/Content Views/LinkPreviewView.swift # Session/Conversations/Message Cells/MessageCell.swift # Session/Conversations/Message Cells/VisibleMessageCell.swift # Session/Conversations/Views & Modals/BodyTextView.swift # Session/Meta/Translations/en.lproj/Localizable.strings # Session/Shared/UserCell.swift # SessionMessagingKit/Jobs/MessageSendJob.swift # SessionMessagingKit/Messages/Signal/TSMessage.h # SessionMessagingKit/Messages/Signal/TSMessage.m # SessionMessagingKit/Messages/Visible Messages/VisibleMessage.swift # SessionMessagingKit/Open Groups/OpenGroupAPIV2.swift # SessionMessagingKit/Sending & Receiving/MessageReceiver+Handling.swift # SessionMessagingKit/Sending & Receiving/Notifications/NotificationsProtocol.h # SessionMessagingKit/Sending & Receiving/Pollers/OpenGroupPollerV2.swift # SessionMessagingKit/Utilities/General.swift # SessionNotificationServiceExtension/NSENotificationPresenter.swift # SignalUtilitiesKit/Utilities/DisplayableText.swift # SignalUtilitiesKit/Utilities/NoopNotificationsManager.swift # SignalUtilitiesKit/Utilities/Notification+Loki.swift
2022-07-25 07:39:56 +02:00
override func update(
with cellViewModel: MessageViewModel,
mediaCache: NSCache<NSString, AnyObject>,
playbackInfo: ConversationViewModel.PlaybackInfo?,
showExpandedReactions: Bool,
lastSearchText: String?
) {
guard cellViewModel.cellType == .typingIndicator else { return }
self.viewModel = cellViewModel
2021-01-29 01:46:32 +01:00
// Bubble view
updateBubbleViewCorners()
2021-01-29 01:46:32 +01:00
// Typing indicator view
typingIndicatorView.startAnimation()
}
override func dynamicUpdate(with cellViewModel: MessageViewModel, playbackInfo: ConversationViewModel.PlaybackInfo?) {
}
2021-01-29 01:46:32 +01:00
override func layoutSubviews() {
super.layoutSubviews()
2021-01-29 01:46:32 +01:00
updateBubbleViewCorners()
}
private func updateBubbleViewCorners() {
let maskPath = UIBezierPath(
roundedRect: bubbleView.bounds,
byRoundingCorners: getCornersToRound(),
cornerRadii: CGSize(
width: VisibleMessageCell.largeCornerRadius,
height: VisibleMessageCell.largeCornerRadius)
)
2021-01-29 01:46:32 +01:00
bubbleViewMaskLayer.path = maskPath.cgPath
bubbleView.layer.mask = bubbleViewMaskLayer
}
override func prepareForReuse() {
super.prepareForReuse()
2021-01-29 01:46:32 +01:00
typingIndicatorView.stopAnimation()
}
// MARK: - Convenience
2021-01-29 01:46:32 +01:00
private func getCornersToRound() -> UIRectCorner {
guard viewModel?.isOnlyMessageInCluster == false else { return .allCorners }
switch viewModel?.positionInCluster {
case .top: return [ .topLeft, .topRight, .bottomRight ]
case .middle: return [ .topRight, .bottomRight ]
case .bottom: return [ .topRight, .bottomRight, .bottomLeft ]
case .none, .individual: return .allCorners
2021-01-29 01:46:32 +01:00
}
}
}