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

[BUG][RCVC] Left and right edges on iPad need to increase to match the other elements in the controller #2295

Merged
merged 10 commits into from
Nov 9, 2018
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ CHECKOUT OPTIONS:
:commit: c34d9ccef689c55b9eae69f3c65283da8d8b0c6c
:git: https://github.com/RocketChat/RCMarkdownParser.git
RocketChatViewController:
:commit: 5d98d7c149fa0f43f7a53fba37b3af444a4f0402
:commit: 65681ffd775907ea6d29e75269eb605a933ea25c
:git: https://github.com/RocketChat/RocketChatViewController
SimpleImageViewer:
:commit: 8222c338de0f285ca0c2d556c5d8dedd4a365b52
Expand Down
2 changes: 1 addition & 1 deletion Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ final class MessageSection: ChatSection {
cell.delegate = self
}

let adjustedContentInsets = messagesController?.collectionView.adjustedContentInset ?? .zero
let adjustedHoritonzalInsets = adjustedContentInsets.left + adjustedContentInsets.right
cell.adjustedHorizontalInsets = adjustedHoritonzalInsets
cell.messageWidth = messagesController?.messageWidth() ?? 0
cell.viewModel = viewModel
cell.configure()
return cell
Expand Down
33 changes: 20 additions & 13 deletions Rocket.Chat/Controllers/Chat/MessagesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import DifferenceKit

protocol SizingCell: class {
static var sizingCell: UICollectionViewCell & ChatCell { get }
static func size(for viewModel: AnyChatItem, with horizontalMargins: CGFloat) -> CGSize
static func size(for viewModel: AnyChatItem, with cellWidth: CGFloat) -> CGSize
}

extension SizingCell {
static func size(for viewModel: AnyChatItem, with horizontalMargins: CGFloat) -> CGSize {
static func size(for viewModel: AnyChatItem, with cellWidth: CGFloat) -> CGSize {
var mutableSizingCell = sizingCell
mutableSizingCell.prepareForReuse()
mutableSizingCell.adjustedHorizontalInsets = horizontalMargins
mutableSizingCell.messageWidth = cellWidth
mutableSizingCell.viewModel = viewModel
mutableSizingCell.configure()
mutableSizingCell.setNeedsLayout()
Expand Down Expand Up @@ -99,7 +99,7 @@ final class MessagesViewController: RocketChatViewController {

lazy var screenSize = view.frame.size
var isInLandscape: Bool {
return screenSize.width / screenSize.height > 1 ? true : false
return screenSize.width / screenSize.height > 1 && UIDevice.current.userInterfaceIdiom == .phone
}

deinit {
Expand Down Expand Up @@ -251,6 +251,19 @@ final class MessagesViewController: RocketChatViewController {
API.current()?.client(SubscriptionsClient.self).markAsRead(subscription: subscription)
}

// MARK: Sizing

func messageWidth() -> CGFloat {
var horizontalMargins: CGFloat
if isInLandscape {
horizontalMargins = collectionView.adjustedContentInset.top + collectionView.adjustedContentInset.bottom
} else {
horizontalMargins = 0
}

return screenSize.width - horizontalMargins
}

}

extension MessagesViewController {
Expand Down Expand Up @@ -283,15 +296,9 @@ extension MessagesViewController {
""")
}

var horizontalMargins: CGFloat
if isInLandscape {
horizontalMargins = collectionView.adjustedContentInset.top + collectionView.adjustedContentInset.bottom
} else {
horizontalMargins = 0
}

var size = type(of: sizingCell).size(for: item, with: horizontalMargins)
size = CGSize(width: screenSize.width - horizontalMargins, height: size.height)
let cellWidth = messageWidth()
var size = type(of: sizingCell).size(for: item, with: cellWidth)
size = CGSize(width: cellWidth, height: size.height)
viewSizingModel.set(size: size, for: item.differenceIdentifier)
return size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import RocketChatViewController

class BaseMessageCell: UICollectionViewCell, ChatCell {
var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?

lazy var avatarView: AvatarView = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ class BaseQuoteMessageCell: BaseMessageCell {
var readReceiptTrailingInitialConstant: CGFloat = 0
var textLabelWidth: CGFloat {
return
UIScreen.main.bounds.width -
messageWidth -
avatarLeadingInitialConstant -
avatarWidthInitialConstant -
containerLeadingInitialConstant -
textLeadingInitialConstant -
textTrailingInitialConstant -
containerTrailingInitialConstant -
readReceiptWidthInitialConstant -
readReceiptTrailingInitialConstant -
adjustedHorizontalInsets
readReceiptTrailingInitialConstant
}

var isCollapsible = false
Expand All @@ -39,8 +38,7 @@ class BaseQuoteMessageCell: BaseMessageCell {
@objc func didTapContainerView() {
guard
isCollapsible,
let viewModel = viewModel,
let quoteViewModel = viewModel.base as? QuoteChatItem
let viewModel = viewModel
else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BaseTextAttachmentMessageCell: BaseMessageCell {
var readReceiptTrailingInitialConstant: CGFloat = 0
var fieldLabelWidth: CGFloat {
return
UIScreen.main.bounds.width -
messageWidth -
avatarLeadingInitialConstant -
avatarWidthInitialConstant -
textContainerLeadingInitialConstant -
Expand All @@ -39,8 +39,7 @@ class BaseTextAttachmentMessageCell: BaseMessageCell {
fieldsStackViewTrailingInitialConstant -
textContainerTrailingInitialConstant -
readReceiptWidthInitialConstant -
readReceiptTrailingInitialConstant -
adjustedHorizontalInsets
readReceiptTrailingInitialConstant
}

func configure(stackView: UIStackView) -> CGFloat {
Expand Down
22 changes: 9 additions & 13 deletions Rocket.Chat/Views/Chat/New Chat/Cells/BasicMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ final class BasicMessageCell: BaseMessageCell, BaseMessageCellProtocol, SizingCe
@IBOutlet weak var readReceiptTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak var avatarWidthConstraint: NSLayoutConstraint!
@IBOutlet weak var avatarLeadingConstraint: NSLayoutConstraint!
var textHorizontalMargins: CGFloat {
var textWidth: CGFloat {
return
textLeadingConstraint.constant +
textTrailingConstraint.constant +
readReceiptWidthConstraint.constant +
readReceiptTrailingConstraint.constant +
avatarWidthConstraint.constant +
avatarLeadingConstraint.constant +
adjustedHorizontalInsets
messageWidth -
textLeadingConstraint.constant -
textTrailingConstraint.constant -
readReceiptWidthConstraint.constant -
readReceiptTrailingConstraint.constant -
avatarWidthConstraint.constant -
avatarLeadingConstraint.constant
}

weak var longPressGesture: UILongPressGestureRecognizer?
Expand Down Expand Up @@ -95,12 +95,8 @@ final class BasicMessageCell: BaseMessageCell, BaseMessageCellProtocol, SizingCe

text.message = message

// FA NOTE: Using UIScreen.main bounds is fine because we are not using
// section insets, but in the future we can create a mechanism that
// discounts the UICollectionView's section insets from the main screen's bounds
let screenWidth = UIScreen.main.bounds.width
let maxSize = CGSize(
width: screenWidth - textHorizontalMargins,
width: textWidth,
height: .greatestFiniteMagnitude
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class DateSeparatorCell: UICollectionViewCell, ChatCell, SizingCell {
@IBOutlet weak var date: UILabel!
@IBOutlet weak var rightLine: UIView!

var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?

func configure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MessageActionsCell: UICollectionViewCell, BaseMessageCellProtocol, ChatCel
}

weak var delegate: ChatMessageCellProtocol?
var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?

func configure() {}
Expand Down
7 changes: 3 additions & 4 deletions Rocket.Chat/Views/Chat/New Chat/Cells/MessageURLCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ final class MessageURLCell: UICollectionViewCell, BaseMessageCellProtocol, ChatC
@IBOutlet weak var containerTrailingConstraint: NSLayoutConstraint!
var containerWidth: CGFloat {
return
UIScreen.main.bounds.width -
messageWidth -
containerLeadingConstraint.constant -
containerTrailingConstraint.constant -
adjustedHorizontalInsets
containerTrailingConstraint.constant
}

weak var delegate: ChatMessageCellProtocol?

var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?
var thumbnailHeightInitialConstant: CGFloat = 0

Expand Down
4 changes: 2 additions & 2 deletions Rocket.Chat/Views/Chat/New Chat/Cells/MessageURLCell.xib
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion Rocket.Chat/Views/Chat/New Chat/Cells/ReactionsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ReactionsCell: UICollectionViewCell, ChatCell, SizingCell {
return cell
}()

var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?

@IBOutlet weak var reactionsList: ReactionListView! {
Expand Down
19 changes: 8 additions & 11 deletions Rocket.Chat/Views/Chat/New Chat/Cells/SequentialMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ final class SequentialMessageCell: BaseMessageCell, BaseMessageCellProtocol, Siz
@IBOutlet weak var textTrailingConstraint: NSLayoutConstraint!
@IBOutlet weak var readReceiptWidthConstraint: NSLayoutConstraint!
@IBOutlet weak var readReceiptTrailingConstraint: NSLayoutConstraint!
var textHorizontalMargins: CGFloat {
return textLeadingConstraint.constant +
textTrailingConstraint.constant +
readReceiptWidthConstraint.constant +
readReceiptTrailingConstraint.constant +
adjustedHorizontalInsets
var textWidth: CGFloat {
return
messageWidth -
textLeadingConstraint.constant -
textTrailingConstraint.constant -
readReceiptWidthConstraint.constant -
readReceiptTrailingConstraint.constant
}

weak var longPressGesture: UILongPressGestureRecognizer?
Expand Down Expand Up @@ -75,12 +76,8 @@ final class SequentialMessageCell: BaseMessageCell, BaseMessageCellProtocol, Siz

text.message = message

// FA NOTE: Using UIScreen.main bounds is fine because we are not using
// section insets, but in the future we can create a mechanism that
// discounts the UICollectionView's section insets from the main screen's bounds
let screenWidth = UIScreen.main.bounds.width
let maxSize = CGSize(
width: screenWidth - textHorizontalMargins,
width: textWidth,
height: .greatestFiniteMagnitude
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class UnreadMarkerCell: UICollectionViewCell, ChatCell, SizingCell {
@IBOutlet weak var separatorLeft: UIView!
@IBOutlet weak var separatorRight: UIView!

var adjustedHorizontalInsets: CGFloat = 0
var messageWidth: CGFloat = 0
var viewModel: AnyChatItem?

func configure() {
Expand Down