Merge pull request #5624 from vector-im/steve/5521_bubbles_readmarker

Message Bubbles: Fix read marker appearing part way thru a message
This commit is contained in:
SBiOSoftWhare
2022-02-18 15:14:30 +01:00
committed by GitHub
16 changed files with 291 additions and 81 deletions
@@ -124,6 +124,40 @@ class BaseRoomCell: MXKRoomBubbleTableViewCell, BaseRoomCellProtocol {
}
}
override var readMarkerViewLeadingConstraint: NSLayoutConstraint! {
get {
if self is RoomCellReadMarkerDisplayable {
return self.roomCellContentView?.readMarkerViewLeadingConstraint
} else {
return super.readMarkerViewLeadingConstraint
}
}
set {
if self is RoomCellReadMarkerDisplayable {
self.roomCellContentView?.readMarkerViewLeadingConstraint = newValue
} else {
super.readMarkerViewLeadingConstraint = newValue
}
}
}
override var readMarkerViewTrailingConstraint: NSLayoutConstraint! {
get {
if self is RoomCellReadMarkerDisplayable {
return self.roomCellContentView?.readMarkerViewTrailingConstraint
} else {
return super.readMarkerViewTrailingConstraint
}
}
set {
if self is RoomCellReadMarkerDisplayable {
self.roomCellContentView?.readMarkerViewTrailingConstraint = newValue
} else {
super.readMarkerViewTrailingConstraint = newValue
}
}
}
// MARK: - Setup
required override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
@@ -300,6 +334,19 @@ class BaseRoomCell: MXKRoomBubbleTableViewCell, BaseRoomCellProtocol {
self.roomCellContentView?.removeThreadSummaryView()
}
// MARK: - RoomCellReadMarkerDisplayable
func addReadMarkerView(_ readMarkerView: UIView) {
self.roomCellContentView?.addReadMarkerView(readMarkerView)
self.readMarkerView = readMarkerView
}
override func removeReadMarkerView() {
self.roomCellContentView?.removeReadMarkerView()
super.removeReadMarkerView()
}
// Encryption status
private func updateEncryptionStatusViewImage() {
@@ -56,6 +56,12 @@ final class RoomCellContentView: UIView, NibLoadable {
@IBOutlet weak var readReceiptsContainerView: UIView!
@IBOutlet weak var readReceiptsContentView: UIView!
@IBOutlet weak var readMarkerContainerView: UIView!
@IBOutlet weak var readMarkerContentView: UIView!
var readMarkerViewLeadingConstraint: NSLayoutConstraint?
var readMarkerViewTrailingConstraint: NSLayoutConstraint?
@IBOutlet weak var reactionsContainerView: UIView!
@IBOutlet weak var reactionsContentView: UIView!
@IBOutlet weak var reactionsContentViewLeadingConstraint: NSLayoutConstraint!
@@ -154,6 +160,15 @@ final class RoomCellContentView: UIView, NibLoadable {
}
}
var showReadMarker: Bool {
get {
return !self.readMarkerContainerView.isHidden
}
set {
self.readMarkerContainerView.isHidden = !newValue
}
}
var decorationViewsAlignment: RoomCellDecorationAlignment = .left
// MARK: - Setup
@@ -304,3 +319,46 @@ extension RoomCellContentView: RoomCellURLPreviewDisplayable {
self.urlPreviewContentView.vc_removeAllSubviews()
}
}
// MARK: - RoomCellReadMarkerDisplayable
extension RoomCellContentView: RoomCellReadMarkerDisplayable {
func addReadMarkerView(_ readMarkerView: UIView) {
guard let containerView = self.readMarkerContainerView else {
return
}
self.readMarkerContentView.vc_removeAllSubviews()
readMarkerView.translatesAutoresizingMaskIntoConstraints = false
self.readMarkerContentView.addSubview(readMarkerView)
// Force read marker constraints
let topConstraint = readMarkerView.topAnchor.constraint(equalTo: containerView.topAnchor)
let leadingConstraint = readMarkerView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor)
let trailingConstraint = readMarkerView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
let heightConstraint = readMarkerView.heightAnchor.constraint(equalToConstant: PlainRoomCellLayoutConstants.readMarkerViewHeight)
let bottomContraint = readMarkerView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
NSLayoutConstraint.activate([topConstraint,
leadingConstraint,
trailingConstraint,
heightConstraint,
bottomContraint])
self.readMarkerViewLeadingConstraint = leadingConstraint
self.readMarkerViewTrailingConstraint = trailingConstraint
self.showReadMarker = true
}
func removeReadMarkerView() {
self.showReadMarker = false
self.readMarkerContentView.vc_removeAllSubviews()
}
}
@@ -222,6 +222,25 @@
<constraint firstAttribute="trailing" secondItem="rQt-NH-Cb0" secondAttribute="trailing" constant="6" id="lq2-AY-Lus"/>
</constraints>
</view>
<view hidden="YES" clipsSubviews="YES" contentMode="scaleToFill" verticalHuggingPriority="253" translatesAutoresizingMaskIntoConstraints="NO" id="2i0-Un-VXa">
<rect key="frame" x="0.0" y="0.0" width="595" height="0.0"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3Cq-BI-po5">
<rect key="frame" x="0.0" y="0.0" width="595" height="0.0"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" priority="250" constant="2" id="3j7-Qe-vYL"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="3Cq-BI-po5" firstAttribute="top" secondItem="2i0-Un-VXa" secondAttribute="top" id="6YG-04-nSb"/>
<constraint firstItem="3Cq-BI-po5" firstAttribute="leading" secondItem="2i0-Un-VXa" secondAttribute="leading" id="CrN-xe-M6m"/>
<constraint firstAttribute="trailing" secondItem="3Cq-BI-po5" secondAttribute="trailing" id="SBL-F4-EJ8"/>
<constraint firstAttribute="bottom" secondItem="3Cq-BI-po5" secondAttribute="bottom" id="r3l-ZY-0kc"/>
</constraints>
</view>
<view hidden="YES" clipsSubviews="YES" contentMode="scaleAspectFit" translatesAutoresizingMaskIntoConstraints="NO" id="2eB-kB-m20">
<rect key="frame" x="0.0" y="0.0" width="595" height="0.0"/>
<subviews>
@@ -289,6 +308,8 @@
<outlet property="reactionsContentView" destination="SNw-aM-ILI" id="wMe-f0-qhq"/>
<outlet property="reactionsContentViewLeadingConstraint" destination="x1n-oT-dez" id="LUh-3Q-SVr"/>
<outlet property="reactionsContentViewTrailingConstraint" destination="ynR-d4-6cf" id="Sy0-o9-vAC"/>
<outlet property="readMarkerContainerView" destination="2i0-Un-VXa" id="O4q-3S-R5o"/>
<outlet property="readMarkerContentView" destination="3Cq-BI-po5" id="Bwr-Sg-sOt"/>
<outlet property="readReceiptsContainerView" destination="4zo-V8-CNe" id="7ek-u4-CX8"/>
<outlet property="readReceiptsContentView" destination="rQt-NH-Cb0" id="tqw-je-kp9"/>
<outlet property="threadSummaryContainerView" destination="2eB-kB-m20" id="0Y4-4E-I9K"/>
@@ -0,0 +1,23 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import UIKit
/// `RoomCellReadMarkerDisplayable` is a protocol indicating that a cell support displaying read marker.
@objc protocol RoomCellReadMarkerDisplayable {
func addReadMarkerView(_ readMarkerView: UIView)
func removeReadMarkerView()
}