Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit 0e11048

Browse files
committed
Add announcement banner to messages view
1 parent a4911cb commit 0e11048

3 files changed

Lines changed: 102 additions & 1 deletion

File tree

Rocket.Chat.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@
895895
D32E28251DFD86C300D6019C /* LauncherProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E28221DFD86C300D6019C /* LauncherProtocol.swift */; };
896896
D32E28261DFD86C300D6019C /* PersistencyCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D32E28231DFD86C300D6019C /* PersistencyCoordinator.swift */; };
897897
D3CFAFBD1E907D8900BADC0A /* ChatMessageTextViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3CFAFBC1E907D8900BADC0A /* ChatMessageTextViewModel.swift */; };
898+
DB926AFD21FA0AEE0046F53F /* ChatAnnouncementView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */; };
898899
/* End PBXBuildFile section */
899900

900901
/* Begin PBXContainerItemProxy section */
@@ -1848,6 +1849,7 @@
18481849
D32E28221DFD86C300D6019C /* LauncherProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LauncherProtocol.swift; sourceTree = "<group>"; };
18491850
D32E28231DFD86C300D6019C /* PersistencyCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersistencyCoordinator.swift; sourceTree = "<group>"; };
18501851
D3CFAFBC1E907D8900BADC0A /* ChatMessageTextViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatMessageTextViewModel.swift; sourceTree = "<group>"; };
1852+
DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatAnnouncementView.swift; sourceTree = "<group>"; };
18511853
E05A718A50D61E3E547007AF /* Pods-Rocket.Chat.test.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.Chat.test.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.Chat/Pods-Rocket.Chat.test.xcconfig"; sourceTree = "<group>"; };
18521854
F87E8221BEB77AF190F06201 /* Pods-Rocket.Chat.ShareExtension.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.Chat.ShareExtension.beta.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.Chat.ShareExtension/Pods-Rocket.Chat.ShareExtension.beta.xcconfig"; sourceTree = "<group>"; };
18531855
FEDACA44BBB1C0633DEA6F3D /* Pods-Rocket.ChatTests.beta.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Rocket.ChatTests.beta.xcconfig"; path = "Pods/Target Support Files/Pods-Rocket.ChatTests/Pods-Rocket.ChatTests.beta.xcconfig"; sourceTree = "<group>"; };
@@ -3028,6 +3030,7 @@
30283030
411498E21FC7A99C00D66542 /* ChatTitleViewModel.swift */,
30293031
339B6929205042D300F97392 /* KeyboardFrameView.swift */,
30303032
1435BFA21F9B601600FB2768 /* RCTextView.swift */,
3033+
DB926AFC21FA0AEE0046F53F /* ChatAnnouncementView.swift */,
30313034
);
30323035
path = Chat;
30333036
sourceTree = "<group>";
@@ -4827,6 +4830,7 @@
48274830
4190694321D0E82F00FE2573 /* MessageVideoCallCell.swift in Sources */,
48284831
9987B5992093E526007D277C /* FileTableViewCell.swift in Sources */,
48294832
99BE4D8A2153162A001A43E2 /* UnmanagedMessage.swift in Sources */,
4833+
DB926AFD21FA0AEE0046F53F /* ChatAnnouncementView.swift in Sources */,
48304834
41FC9E0C209B3BAA00FED485 /* UploadMessageRequest.swift in Sources */,
48314835
800FCD501F728EC800D9A692 /* MemberCell.swift in Sources */,
48324836
997FE19C210BA5B8000F6836 /* SubscriptionHideRequest.swift in Sources */,

Rocket.Chat/Controllers/Chat/MessagesViewController.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ final class MessagesViewController: RocketChatViewController {
7979
}
8080
}
8181

82+
lazy var announcementBannerView: UIView = {
83+
let announcementBannerView = ChatAnnouncementView()
84+
announcementBannerView.subscription = subscription?.unmanaged
85+
return announcementBannerView
86+
}()
87+
8288
private let buttonScrollToBottomSize = CGFloat(70)
8389
var keyboardHeight: CGFloat = 0
8490
var buttonScrollToBottomConstraint: NSLayoutConstraint!
@@ -131,7 +137,7 @@ final class MessagesViewController: RocketChatViewController {
131137

132138
registerCells()
133139
setupScrollToBottom()
134-
140+
setupAnnouncementBanner()
135141
NotificationCenter.default.addObserver(
136142
self,
137143
selector: #selector(keyboardWillShow(_:)),
@@ -197,6 +203,7 @@ final class MessagesViewController: RocketChatViewController {
197203
super.viewDidAppear(animated)
198204
markAsRead()
199205
becomeFirstResponder()
206+
updateAnnouncementBanner()
200207
}
201208

202209
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
@@ -274,6 +281,35 @@ final class MessagesViewController: RocketChatViewController {
274281
}
275282
}
276283

284+
// MARK: Announcement
285+
286+
func setupAnnouncementBanner() {
287+
// Start as invisible first, alpha will be set to 1 if a valid announcement is fetched
288+
announcementBannerView.alpha = 0
289+
290+
view.addSubview(announcementBannerView)
291+
view.bringSubviewToFront(announcementBannerView)
292+
NSLayoutConstraint.activate([
293+
announcementBannerView.topAnchor.constraint(equalTo: view.topAnchor),
294+
announcementBannerView.leftAnchor.constraint(equalTo: view.leftAnchor),
295+
announcementBannerView.rightAnchor.constraint(equalTo: view.rightAnchor),
296+
announcementBannerView.heightAnchor.constraint(equalToConstant: 50)
297+
])
298+
299+
announcementBannerView.applyTheme()
300+
}
301+
302+
func updateAnnouncementBanner() {
303+
guard let announcement = subscription?.unmanaged?.roomAnnouncement else { return }
304+
let hasAnnouncement = announcement == "" ? false : true
305+
306+
if hasAnnouncement {
307+
announcementBannerView.alpha = 1
308+
} else {
309+
announcementBannerView.alpha = 0
310+
}
311+
}
312+
277313
// MARK: Scroll to Bottom
278314

279315
func setupScrollToBottom() {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// ChatAnnouncementView.swift
3+
// Rocket.Chat
4+
//
5+
// Created by Bryan Lew on 24/1/19.
6+
// Copyright © 2019 Rocket.Chat. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
final class ChatAnnouncementView: UIView {
12+
13+
override init(frame: CGRect) {
14+
super.init(frame: frame)
15+
setupUI()
16+
}
17+
18+
required init?(coder aDecoder: NSCoder) {
19+
fatalError("init(coder:) has not been implemented")
20+
}
21+
22+
var subscription: UnmanagedSubscription? {
23+
didSet {
24+
guard let subscription = subscription else { return }
25+
guard let announcement = subscription.roomAnnouncement else { return }
26+
let attributedString = NSAttributedString(string: announcement)
27+
announcementLabel.attributedText = MarkdownManager.shared.transformAttributedString(attributedString)
28+
}
29+
}
30+
31+
let announcementLabel: UILabel = {
32+
let label = UILabel()
33+
label.textAlignment = .center
34+
label.translatesAutoresizingMaskIntoConstraints = false
35+
return label
36+
}()
37+
38+
fileprivate func setupUI() {
39+
translatesAutoresizingMaskIntoConstraints = false
40+
41+
addSubview(announcementLabel)
42+
NSLayoutConstraint.activate([
43+
announcementLabel.topAnchor.constraint(equalTo: topAnchor),
44+
announcementLabel.bottomAnchor.constraint(equalTo: bottomAnchor),
45+
announcementLabel.leftAnchor.constraint(equalTo: leftAnchor, constant: 12),
46+
announcementLabel.rightAnchor.constraint(equalTo: rightAnchor, constant: -12)
47+
])
48+
}
49+
}
50+
51+
// MARK: Themeable
52+
53+
extension ChatAnnouncementView {
54+
55+
override func applyTheme() {
56+
super.applyTheme()
57+
backgroundColor = theme?.bannerBackground
58+
announcementLabel.textColor = theme?.auxiliaryText
59+
}
60+
61+
}

0 commit comments

Comments
 (0)