Change cells, add separator, fix room display name, fix content height, introduce AutoSizedTableView

This commit is contained in:
ismailgulek
2020-09-15 11:58:14 +03:00
parent 726654400d
commit 7b6668e243
6 changed files with 90 additions and 46 deletions
@@ -45,34 +45,44 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="goJ-ND-Jsk">
<rect key="frame" x="64" y="20" width="298" height="24"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<rect key="frame" x="72" y="20" width="290" height="23"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="19"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="f1E-jK-fMa">
<rect key="frame" x="64" y="44" width="298" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<rect key="frame" x="72" y="43" width="290" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="KNr-eh-RCO">
<rect key="frame" x="0.0" y="79" width="414" height="1"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="ALs-MS-Ho5"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="eyI-bY-amr" firstAttribute="top" secondItem="M84-br-bHM" secondAttribute="top" constant="16" id="10e-aB-X62"/>
<constraint firstItem="KNr-eh-RCO" firstAttribute="leading" secondItem="M84-br-bHM" secondAttribute="leading" id="EVn-qm-pHi"/>
<constraint firstAttribute="trailing" secondItem="f1E-jK-fMa" secondAttribute="trailing" constant="52" id="UX4-gD-R3P"/>
<constraint firstAttribute="bottom" secondItem="KNr-eh-RCO" secondAttribute="bottom" id="Wia-ai-pZe"/>
<constraint firstAttribute="trailing" secondItem="eyI-bY-amr" secondAttribute="trailing" constant="16" id="YbD-Uq-CyY"/>
<constraint firstItem="YaZ-Pv-7g9" firstAttribute="top" secondItem="M84-br-bHM" secondAttribute="top" constant="20" id="d1C-qB-Yx7"/>
<constraint firstItem="goJ-ND-Jsk" firstAttribute="leading" secondItem="YaZ-Pv-7g9" secondAttribute="trailing" constant="8" id="dPI-An-X2O"/>
<constraint firstItem="goJ-ND-Jsk" firstAttribute="leading" secondItem="YaZ-Pv-7g9" secondAttribute="trailing" constant="16" id="dPI-An-X2O"/>
<constraint firstAttribute="trailing" secondItem="KNr-eh-RCO" secondAttribute="trailing" id="kIO-FP-khg"/>
<constraint firstAttribute="height" constant="80" id="kTG-4C-HCx"/>
<constraint firstItem="f1E-jK-fMa" firstAttribute="leading" secondItem="YaZ-Pv-7g9" secondAttribute="trailing" constant="8" id="ohi-MX-TVT"/>
<constraint firstItem="f1E-jK-fMa" firstAttribute="leading" secondItem="YaZ-Pv-7g9" secondAttribute="trailing" constant="16" id="ohi-MX-TVT"/>
<constraint firstItem="f1E-jK-fMa" firstAttribute="top" secondItem="goJ-ND-Jsk" secondAttribute="bottom" id="pB3-Q4-RbB"/>
<constraint firstItem="YaZ-Pv-7g9" firstAttribute="leading" secondItem="M84-br-bHM" secondAttribute="leading" constant="16" id="w2d-dk-54I"/>
<constraint firstItem="eyI-bY-amr" firstAttribute="leading" secondItem="goJ-ND-Jsk" secondAttribute="trailing" constant="8" id="wUn-ed-WuH"/>
<constraint firstItem="goJ-ND-Jsk" firstAttribute="top" secondItem="M84-br-bHM" secondAttribute="top" constant="20" id="ykL-gN-QoL"/>
</constraints>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="co7-sG-zRv">
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="co7-sG-zRv" customClass="AutosizedTableView" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="80" width="414" height="762"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<connections>
@@ -100,6 +110,7 @@
<outlet property="roomAvatarImageView" destination="YaZ-Pv-7g9" id="Gu2-as-fNL"/>
<outlet property="roomInfoLabel" destination="f1E-jK-fMa" id="0CH-Q8-8aD"/>
<outlet property="roomNameLabel" destination="goJ-ND-Jsk" id="wuf-gz-aK0"/>
<outlet property="separatorView" destination="KNr-eh-RCO" id="47O-qE-sDg"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="zK0-v6-7Wt" userLabel="First Responder" sceneMemberID="firstResponder"/>
@@ -22,10 +22,6 @@ final class RoomCreationEventsModalViewController: UIViewController {
// MARK: - Constants
private enum Constants {
static let defaultStyleCellReuseIdentifier = "default"
}
// MARK: - Properties
// MARK: Outlets
@@ -39,13 +35,13 @@ final class RoomCreationEventsModalViewController: UIViewController {
@IBOutlet private weak var roomNameLabel: UILabel!
@IBOutlet private weak var roomInfoLabel: UILabel!
@IBOutlet private weak var closeButton: UIButton!
@IBOutlet private weak var separatorView: UIView!
// MARK: Private
private var viewModel: RoomCreationEventsModalViewModelType!
private var theme: Theme!
private var errorPresenter: MXKErrorPresentation!
private var activityPresenter: ActivityIndicatorPresenter!
// MARK: - Setup
@@ -53,6 +49,7 @@ final class RoomCreationEventsModalViewController: UIViewController {
let viewController = StoryboardScene.RoomCreationEventsModalViewController.initialScene.instantiate()
viewController.viewModel = viewModel
viewController.theme = ThemeService.shared().theme
_ = viewController.view
return viewController
}
@@ -64,7 +61,6 @@ final class RoomCreationEventsModalViewController: UIViewController {
// Do any additional setup after loading the view.
self.setupViews()
self.activityPresenter = ActivityIndicatorPresenter()
self.errorPresenter = MXKErrorAlertPresentation()
self.registerThemeServiceDidChangeThemeNotification()
@@ -95,11 +91,12 @@ final class RoomCreationEventsModalViewController: UIViewController {
theme.applyStyle(onNavigationBar: navigationBar)
}
// TODO: Set view colors here
theme.applyStyle(onButton: self.closeButton)
roomNameLabel.textColor = theme.textPrimaryColor
roomInfoLabel.textColor = theme.textSecondaryColor
closeButton.backgroundColor = theme.headerBorderColor
closeButton.tintColor = theme.textSecondaryColor
closeButton.setImage(closeButton.image(for: .normal)?.vc_tintedImage(usingColor: theme.textSecondaryColor), for: .normal)
separatorView.backgroundColor = theme.lineBreakColor
self.mainTableView.reloadData()
}
@@ -113,14 +110,14 @@ final class RoomCreationEventsModalViewController: UIViewController {
}
private func setupViews() {
self.mainTableView.separatorStyle = .none
self.mainTableView.tableFooterView = UIView()
mainTableView.separatorStyle = .none
mainTableView.tableFooterView = UIView()
mainTableView.contentInset = UIEdgeInsets(top: 10, left: 0, bottom: 20, right: 0)
mainTableView.register(cellType: TextViewTableViewCell.self)
}
private func render(viewState: RoomCreationEventsModalViewState) {
switch viewState {
case .loading:
self.renderLoading()
case .loaded:
self.renderLoaded()
case .error(let error):
@@ -128,17 +125,11 @@ final class RoomCreationEventsModalViewController: UIViewController {
}
}
private func renderLoading() {
// self.activityPresenter.presentActivityIndicator(on: self.view, animated: true)
}
private func renderLoaded() {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
mainTableView.reloadData()
}
private func render(error: Error) {
self.activityPresenter.removeCurrentActivityIndicator(animated: true)
self.errorPresenter.presentError(from: self, forError: error, animated: true, handler: nil)
}
@@ -169,9 +160,10 @@ extension RoomCreationEventsModalViewController: SlidingModalPresentable {
}
func layoutHeightFittingWidth(_ width: CGFloat) -> CGFloat {
return mainTableView.contentSize.height + 80
// TODO: Fix hard-coded
// return 500
return mainTableView.contentSize.height
+ mainTableView.contentInset.top
+ mainTableView.contentInset.bottom
+ 80 // height of the above view
}
}
@@ -180,10 +172,6 @@ extension RoomCreationEventsModalViewController: SlidingModalPresentable {
extension RoomCreationEventsModalViewController: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.numberOfRows
}
@@ -193,22 +181,23 @@ extension RoomCreationEventsModalViewController: UITableViewDataSource {
return UITableViewCell(style: .default, reuseIdentifier: nil)
}
var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: Constants.defaultStyleCellReuseIdentifier)
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: Constants.defaultStyleCellReuseIdentifier)
}
let cell: TextViewTableViewCell = tableView.dequeueReusableCell(for: indexPath)
if let title = viewModel.title {
let mutableTitle = NSMutableAttributedString(attributedString: title)
mutableTitle.setAttributes([
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
NSAttributedString.Key.foregroundColor: theme.textSecondaryColor
], range: NSRange(location: 0, length: mutableTitle.length))
cell.textLabel?.attributedText = mutableTitle
cell.textView.attributedText = mutableTitle
} else {
cell.textLabel?.attributedText = nil
cell.textView.attributedText = nil
}
cell.textLabel?.numberOfLines = 0
cell.textView.textContainerInset = UIEdgeInsets(top: 10, left: 16, bottom: 10, right: 16)
cell.textView.isScrollEnabled = false
cell.textView.isEditable = false
cell.textView.isSelectable = false
cell.backgroundColor = theme.backgroundColor
cell.contentView.backgroundColor = .clear
cell.tintColor = theme.tintColor
@@ -53,6 +53,9 @@ final class RoomCreationEventsModalViewModel: RoomCreationEventsModalViewModelTy
if let aliases = roomState.aliases, aliases.count > 0 {
return aliases.first
}
if let summary = session.roomSummary(withRoomId: roomState.roomId) {
return summary.displayname
}
return nil
}
var roomInfo: String? {
@@ -119,9 +122,7 @@ final class RoomCreationEventsModalViewModel: RoomCreationEventsModalViewModelTy
// MARK: - Private
private func loadData() {
self.update(viewState: .loading)
self.update(viewState: .loaded)
}
private func update(viewState: RoomCreationEventsModalViewState) {
@@ -20,7 +20,6 @@ import Foundation
/// RoomCreationEventsModalViewController view state
enum RoomCreationEventsModalViewState {
case loading
case loaded(_ displayName: String)
case loaded
case error(Error)
}