mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-23 18:12:44 +02:00
Use ReadMoreTextView for room tpic
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import UIKit
|
||||
import Reusable
|
||||
import ReadMoreTextView
|
||||
|
||||
class RoomInfoBasicView: UIView {
|
||||
|
||||
@@ -39,14 +40,35 @@ class RoomInfoBasicView: UIView {
|
||||
@IBOutlet private weak var badgeImageView: UIImageView!
|
||||
@IBOutlet private weak var roomNameLabel: UILabel!
|
||||
@IBOutlet private weak var roomAddressLabel: UILabel!
|
||||
@IBOutlet private weak var roomTopicTextView: UITextView! {
|
||||
@IBOutlet private weak var roomTopicTextView: ReadMoreTextView! {
|
||||
didSet {
|
||||
roomTopicTextView.contentInset = .zero
|
||||
roomTopicTextView.textContainerInset = .zero
|
||||
roomTopicTextView.textContainer.lineFragmentPadding = 0
|
||||
roomTopicTextView.readMoreTextPadding = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
roomTopicTextView.readLessTextPadding = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
|
||||
roomTopicTextView.shouldTrim = true
|
||||
roomTopicTextView.maximumNumberOfLines = 4
|
||||
roomTopicTextView.onSizeChange = { _ in
|
||||
self.roomTopicTextView.textAlignment = .center
|
||||
self.onTopicSizeChange?(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Block to be invoked when topic text view changes its content size.
|
||||
var onTopicSizeChange: ((RoomInfoBasicView) -> Void)?
|
||||
|
||||
/// Force to update topic text view trimming.
|
||||
func updateTrimmingOnTopic() {
|
||||
roomTopicTextView.setNeedsUpdateTrim()
|
||||
roomTopicTextView.layoutIfNeeded()
|
||||
let currentValue = roomTopicTextView.shouldTrim
|
||||
roomTopicTextView.shouldTrim = !currentValue
|
||||
roomTopicTextView.shouldTrim = currentValue
|
||||
roomTopicTextView.textAlignment = .center
|
||||
}
|
||||
|
||||
func configure(withViewData viewData: RoomInfoBasicViewData) {
|
||||
let avatarImage = AvatarGenerator.generateAvatar(forMatrixItem: viewData.roomId, withDisplayName: viewData.roomDisplayName)
|
||||
|
||||
@@ -70,7 +92,7 @@ class RoomInfoBasicView: UIView {
|
||||
roomTopicTextView.text = viewData.roomTopic
|
||||
roomTopicTextView.isHidden = roomTopicTextView.text?.isEmpty ?? true
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension RoomInfoBasicView: NibLoadable {}
|
||||
@@ -86,6 +108,24 @@ extension RoomInfoBasicView: Themable {
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
|
||||
NSAttributedString.Key.foregroundColor: theme.tintColor
|
||||
]
|
||||
let mutableReadMore = NSMutableAttributedString(string: "... ", attributes: [
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
|
||||
NSAttributedString.Key.foregroundColor: theme.textSecondaryColor
|
||||
])
|
||||
let attributedMore = NSAttributedString(string: VectorL10n.more, attributes: [
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
|
||||
NSAttributedString.Key.foregroundColor: theme.tintColor
|
||||
])
|
||||
mutableReadMore.append(attributedMore)
|
||||
roomTopicTextView.attributedReadMoreText = mutableReadMore
|
||||
|
||||
let mutableReadLess = NSMutableAttributedString(string: " ")
|
||||
let attributedLess = NSAttributedString(string: VectorL10n.less, attributes: [
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
|
||||
NSAttributedString.Key.foregroundColor: theme.tintColor
|
||||
])
|
||||
mutableReadLess.append(attributedLess)
|
||||
roomTopicTextView.attributedReadLessText = mutableReadLess
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,28 +63,38 @@
|
||||
<constraint firstAttribute="trailing" secondItem="szu-r5-TIX" secondAttribute="trailing" id="xqQ-Ue-Ldl"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ekk-PI-fnh">
|
||||
<rect key="frame" x="156" y="97" width="50.5" height="24"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ekk-PI-fnh">
|
||||
<rect key="frame" x="156" y="97" width="50.5" height="29.5"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Yjw-ez-u4W">
|
||||
<rect key="frame" x="161.5" y="129" width="39.5" height="19.5"/>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Yjw-ez-u4W">
|
||||
<rect key="frame" x="161.5" y="134.5" width="39.5" height="19.5"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" verticalCompressionResistancePriority="751" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" text="Lorem ipsum" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DCx-MH-TSC">
|
||||
<rect key="frame" x="129.5" y="156.5" width="103.5" height="41.5"/>
|
||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" verticalHuggingPriority="252" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" editable="NO" text="Lorem ipsum" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="DCx-MH-TSC" customClass="ReadMoreTextView" customModule="ReadMoreTextView">
|
||||
<rect key="frame" x="0.0" y="162" width="362" height="36"/>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<color key="textColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="16"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
<dataDetectorType key="dataDetectorTypes" phoneNumber="YES" link="YES" address="YES" calendarEvent="YES" shipmentTrackingNumber="YES" flightNumber="YES"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
<userDefinedRuntimeAttribute type="number" keyPath="maximumNumberOfLines">
|
||||
<integer key="value" value="4"/>
|
||||
</userDefinedRuntimeAttribute>
|
||||
<userDefinedRuntimeAttribute type="boolean" keyPath="shouldTrim" value="YES"/>
|
||||
</userDefinedRuntimeAttributes>
|
||||
</textView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<constraints>
|
||||
<constraint firstItem="DCx-MH-TSC" firstAttribute="leading" secondItem="xmU-kN-zva" secondAttribute="leading" id="Sv1-Mq-Zt2"/>
|
||||
<constraint firstAttribute="trailing" secondItem="DCx-MH-TSC" secondAttribute="trailing" id="rpo-QH-rrI"/>
|
||||
</constraints>
|
||||
</stackView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
|
||||
Reference in New Issue
Block a user