scrollable subtitle for conversation screen

pull/941/head
Ryan Zhao 2 years ago
parent 56e377824a
commit ee3a03f7cb

@ -31,7 +31,7 @@ final class ConversationTitleView: UIView {
private lazy var pagedScrollView: PagedScrollView = {
let result = PagedScrollView()
result.set(.width, to: 320)
return result
}()
@ -44,6 +44,24 @@ final class ConversationTitleView: UIView {
return result
}()
private lazy var userCountLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: 13)
result.themeTextColor = .textPrimary
result.lineBreakMode = .byTruncatingTail
return result
}()
private lazy var notificationSettingsLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: 13)
result.themeTextColor = .textPrimary
result.lineBreakMode = .byTruncatingTail
return result
}()
private lazy var disappearingMessageSettingLabel: UILabel = {
let result: UILabel = UILabel()
result.font = .systemFont(ofSize: 13)
@ -67,12 +85,14 @@ final class ConversationTitleView: UIView {
}()
private lazy var stackView: UIStackView = {
let result = UIStackView(arrangedSubviews: [ titleLabel, subtitleLabel, disappearingMessageSettingsStackView ])
let result = UIStackView(arrangedSubviews: [ titleLabel, pagedScrollView ])
result.axis = .vertical
result.alignment = .center
return result
}()
private var slides: [UIView] = []
// MARK: - Initialization
@ -111,6 +131,8 @@ final class ConversationTitleView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
self.pagedScrollView.update(with: slides, slideSize: CGSize(width: bounds.size.width, height: 20), shouldAutoScroll: false)
// There is an annoying issue where pushing seems to update the width of this
// view resulting in the content shifting to the right during
guard self.oldSize != .zero, self.oldSize != bounds.size else {
@ -159,11 +181,13 @@ final class ConversationTitleView: UIView {
)
)
ThemeManager.onThemeChange(observer: self.subtitleLabel) { [weak subtitleLabel] theme, _ in
ThemeManager.onThemeChange(observer: self.subtitleLabel) { [weak self] theme, _ in
guard let textPrimary: UIColor = theme.color(for: .textPrimary) else { return }
guard Date().timeIntervalSince1970 > (mutedUntilTimestamp ?? 0) else {
subtitleLabel?.attributedText = NSAttributedString(
var slides: [UIView?] = []
if Date().timeIntervalSince1970 <= (mutedUntilTimestamp ?? 0) {
self?.notificationSettingsLabel.attributedText = NSAttributedString(
string: "\u{e067} ",
attributes: [
.font: UIFont.ows_elegantIconsFont(10),
@ -171,9 +195,9 @@ final class ConversationTitleView: UIView {
]
)
.appending(string: "Muted")
return
}
guard !onlyNotifyForMentions else {
self?.notificationSettingsLabel.isHidden = false
slides.append(self?.notificationSettingsLabel)
} else if onlyNotifyForMentions{
let imageAttachment = NSTextAttachment()
imageAttachment.image = UIImage(named: "NotifyMentions.png")?.withTint(textPrimary)
imageAttachment.bounds = CGRect(
@ -183,26 +207,32 @@ final class ConversationTitleView: UIView {
height: Values.smallFontSize
)
subtitleLabel?.attributedText = NSAttributedString(attachment: imageAttachment)
self?.notificationSettingsLabel.attributedText = NSAttributedString(attachment: imageAttachment)
.appending(string: " ")
.appending(string: "view_conversation_title_notify_for_mentions_only".localized())
return
self?.notificationSettingsLabel.isHidden = false
slides.append(self?.notificationSettingsLabel)
}
guard let userCount: Int = userCount else { return }
switch threadVariant {
case .contact: break
case .closedGroup:
subtitleLabel?.attributedText = NSAttributedString(
string: "\(userCount) member\(userCount == 1 ? "" : "s")"
)
case .openGroup:
subtitleLabel?.attributedText = NSAttributedString(
string: "\(userCount) active member\(userCount == 1 ? "" : "s")"
)
if let userCount: Int = userCount {
switch threadVariant {
case .contact: break
case .closedGroup:
self?.userCountLabel.attributedText = NSAttributedString(
string: "\(userCount) member\(userCount == 1 ? "" : "s")"
)
case .openGroup:
self?.userCountLabel.attributedText = NSAttributedString(
string: "\(userCount) active member\(userCount == 1 ? "" : "s")"
)
}
slides.append(self?.userCountLabel)
}
// TODO: Disappearing message settings
self?.slides = slides.compactMap{ $0 }
}
// Contact threads also have the call button to compensate for

@ -4,12 +4,15 @@ import UIKit
import SessionUIKit
final class PagedScrollView: UIView {
private static let autoScrollingTimeInterval: TimeInterval = 3
private static let autoScrollingTimeInterval: TimeInterval = 10
private var slides: [UIView] = []
private var slideSize: CGSize = .zero
private var shouldAutoScroll: Bool = false
private var timer: Timer?
private lazy var contentWidth = stackView.set(.width, to: 0)
private lazy var contentHeight = stackView.set(.height, to: 0)
// MARK: - UI Components
private lazy var scrollView: UIScrollView = {
@ -30,7 +33,11 @@ final class PagedScrollView: UIView {
private lazy var pageControl: UIPageControl = {
let result = UIPageControl(frame: .zero)
result.currentPageIndicatorTintColor = .black
result.pageIndicatorTintColor = .gray
result.themeTintColor = .textPrimary
result.set(.height, to: 5)
result.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
return result
}()
@ -57,6 +64,11 @@ final class PagedScrollView: UIView {
pageControl.currentPage = 0
pageControl.isHidden = (slides.count == 1)
let contentSize = CGSize(width: slideSize.width * CGFloat(slides.count), height: slideSize.height)
scrollView.contentSize = contentSize
contentWidth.constant = contentSize.width
contentHeight.constant = contentSize.height
stackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
self.slides.forEach {
@ -79,15 +91,15 @@ final class PagedScrollView: UIView {
addSubview(pageControl)
pageControl.center(.horizontal, in: self)
pageControl.pin(.bottom, to: .bottom, of: self)
pageControl.pin(.bottom, to: .bottom, of: self, withInset: -1)
scrollView.addSubview(stackView)
stackView.pin([ UIView.HorizontalEdge.leading, UIView.VerticalEdge.top ], to: scrollView)
}
private func startScrolling() {
timer?.invalidate()
timer = Timer.scheduledTimerOnMainThread(withTimeInterval: Self.autoScrollingTimeInterval, repeats: true) { _ in
guard self.slides.count != 0 else { return }
let targetPage = (self.pageControl.currentPage + 1) % self.slides.count
self.scrollView.scrollRectToVisible(
CGRect(

Loading…
Cancel
Save