Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore typing notifications inspired by web #4147

Merged
merged 31 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
00a524a
Explore typing notifications inspired by web
gileluard Mar 22, 2021
847afcb
Merge branch 'element_4133' into element_4134
gileluard Mar 23, 2021
b40aeb4
Merge branch 'element_4133' into element_4134
gileluard Mar 24, 2021
6f499cb
Explore typing notifications inspired by web
gileluard Mar 24, 2021
b103bc3
Merge branch 'element_4133' into element_4134
gileluard Mar 25, 2021
4a4025f
Explore typing notifications inspired by web
gileluard Mar 25, 2021
dce73e4
Explore typing notifications inspired by web
gileluard Mar 25, 2021
a6ee83b
Merge branch 'element_4087' into element_4134
gileluard Mar 25, 2021
111e3a0
Merge branch 'element_4087' into element_4134
gileluard Mar 26, 2021
9f7e0b7
Merge branch 'element_4087' into element_4134
gileluard Mar 27, 2021
0322f3c
Explore typing notifications inspired by web
gileluard Mar 29, 2021
d24d20d
Merge branch 'element_4087' into element_4134
gileluard Apr 1, 2021
632adec
Merge branch 'element_4087' into element_4134
gileluard Apr 2, 2021
283b6f3
Limit typing notifications timeline jumps
gileluard Apr 6, 2021
57101f3
Consider displaying names in typing notifications
gileluard Apr 6, 2021
d4b736c
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
e4a853e
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
120dbac
Crash in [RoomViewController refreshTypingNotification]
gileluard Apr 7, 2021
9fbdd74
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
decc075
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
46561f7
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
3722bd7
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
43059ee
Updated CHANGES.rst
gileluard Apr 7, 2021
4d280bd
Merge branch 'element_4087' into element_4134
gileluard Apr 7, 2021
1659e20
Merge branch 'element_4087' into element_4134
gileluard Apr 8, 2021
52f5ffa
Update CHANGES.rst
gileluard Apr 8, 2021
b42bb37
Update Riot/Modules/Room/Views/BubbleCells/RoomTypingBubbleCell.swift
gileluard Apr 8, 2021
5070f36
Update Riot/Modules/DotsView/DotsView.swift
gileluard Apr 8, 2021
b41ab9f
Update after review
gileluard Apr 8, 2021
f27363d
Update after review
gileluard Apr 8, 2021
84e1b98
Update Riot/Modules/Room/Views/BubbleCells/RoomTypingBubbleCell.swift
gileluard Apr 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Riot/Modules/DotsView/DotsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ import UIKit
class DotsView: UIView {
// MARK: - Public properties

@IBInspectable var highlightedDotColor: UIColor = .darkGray {
didSet {
}
}
@IBInspectable var highlightedDotColor: UIColor = .darkGray

@IBInspectable var dotColor: UIColor = .lightGray {
didSet {
}
}
@IBInspectable var dotColor: UIColor = .lightGray

@IBInspectable var dotMaxWidth: CGFloat = 10 {
didSet {
Expand Down
4 changes: 3 additions & 1 deletion Riot/Modules/Room/DataSources/RoomDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#import "MXRoomSummary+Riot.h"

#import "TypingUserInfo.h"

@protocol RoomDataSourceDelegate;

/**
Expand Down Expand Up @@ -51,7 +53,7 @@
/**
List of members who are typing in the room.
*/
@property(nonatomic, nullable) NSArray *currentTypingUsers;
@property(nonatomic, nullable) NSArray<TypingUserInfo *> *currentTypingUsers;

/**
Check if there is an active jitsi widget in the room and return it.
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Room/DataSources/RoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#import "MXRoom+Riot.h"

const CGFloat kTypingCellHeight = 24;

@interface RoomDataSource() <BubbleReactionsViewModelDelegate>
{
Expand Down Expand Up @@ -191,7 +192,7 @@ - (CGFloat)cellHeightAtIndex:(NSInteger)index withMaximumWidth:(CGFloat)maxWidth
{
if (index == self.typingCellIndex)
{
return 24;
return kTypingCellHeight;
}

return [super cellHeightAtIndex:index withMaximumWidth:maxWidth];
Expand Down
8 changes: 4 additions & 4 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1354,8 +1354,8 @@ - (void)setScrollToBottomHidden:(BOOL)scrollToBottomHidden
if (roomDataSource.currentTypingUsers && !roomDataSource.currentTypingUsers.count)
{
[roomDataSource resetTypingNotification];
NSInteger count = [roomDataSource tableView:self.bubblesTableView numberOfRowsInSection:0];
[self.bubblesTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:count inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
NSInteger count = [self.bubblesTableView numberOfRowsInSection:0];
[self.bubblesTableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:count - 1 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
}
}

Expand Down Expand Up @@ -4159,7 +4159,7 @@ - (void)refreshTypingNotification
}
else
{
NSInteger count = [self.roomDataSource tableView:self.bubblesTableView numberOfRowsInSection:0];
NSInteger count = [self.bubblesTableView numberOfRowsInSection:0];
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:count - 1 inSection:0];
[self.bubblesTableView reloadRowsAtIndexPaths:@[lastIndexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Expand All @@ -4168,7 +4168,7 @@ - (void)refreshTypingNotification
&& !self.bubblesTableView.isDragging
&& !self.bubblesTableView.isDecelerating)
{
NSInteger count = [self.roomDataSource tableView:self.bubblesTableView numberOfRowsInSection:0];
NSInteger count = [self.bubblesTableView numberOfRowsInSection:0];
if (count)
{
[self scrollBubblesTableViewToBottomAnimated:YES];
Expand Down
57 changes: 33 additions & 24 deletions Riot/Modules/Room/Views/BubbleCells/RoomTypingBubbleCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
import UIKit

@objcMembers
class RoomTypingBubbleCell: UITableViewCell {
class RoomTypingBubbleCell: UITableViewCell, Themable {
// MARK: - Constants

static let cellIdentifier = "RoomTypingBubbleCell"

private static let maxPictureCount = 4
gileluard marked this conversation as resolved.
Show resolved Hide resolved
private static let pictureSize: CGFloat = 24
private static let pictureMaxMargin: CGFloat = 16
private static let pictureMinMargin: CGFloat = 8

// MARK: - Outlets

@IBOutlet weak var additionalUsersLabel: UILabel?
@IBOutlet weak var additionalUsersLabelLeadingConstraint: NSLayoutConstraint?
@IBOutlet weak var dotsView: DotsView?
@IBOutlet weak var dotsViewLeadingConstraint: NSLayoutConstraint?
@IBOutlet private weak var additionalUsersLabel: UILabel!
@IBOutlet private weak var additionalUsersLabelLeadingConstraint: NSLayoutConstraint!
@IBOutlet private weak var dotsView: DotsView!
@IBOutlet private weak var dotsViewLeadingConstraint: NSLayoutConstraint!

// MARK: - members

Expand All @@ -38,9 +42,7 @@ class RoomTypingBubbleCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()

additionalUsersLabel?.textColor = ThemeService.shared().theme.textSecondaryColor
dotsView?.highlightedDotColor = ThemeService.shared().theme.textTertiaryColor
dotsView?.dotColor = ThemeService.shared().theme.textSecondaryColor
update(theme: ThemeService.shared().theme)
gileluard marked this conversation as resolved.
Show resolved Hide resolved
}

override func prepareForReuse() {
Expand All @@ -50,15 +52,13 @@ class RoomTypingBubbleCell: UITableViewCell {
pictureView.removeFromSuperview()
}

additionalUsersLabel?.textColor = ThemeService.shared().theme.textSecondaryColor
dotsView?.highlightedDotColor = ThemeService.shared().theme.textTertiaryColor
dotsView?.dotColor = ThemeService.shared().theme.textSecondaryColor
update(theme: ThemeService.shared().theme)
}

override func layoutSubviews() {
super.layoutSubviews()

self.dotsView?.isHidden = userPictureViews.count == 0
dotsView.isHidden = userPictureViews.count == 0

guard userPictureViews.count > 0 else {
return
Expand All @@ -69,31 +69,40 @@ class RoomTypingBubbleCell: UITableViewCell {
var pictureViewsMaxX: CGFloat = 0
var xOffset: CGFloat = 0
for pictureView in userPictureViews {
pictureView.center = CGPoint(x: 16 + xOffset + pictureView.bounds.midX, y: self.bounds.midY)
pictureView.center = CGPoint(x: RoomTypingBubbleCell.pictureMaxMargin + xOffset + pictureView.bounds.midX, y: self.bounds.midY)
xOffset += round(pictureView.bounds.maxX * 2 / 3)
pictureViewsMaxX = pictureView.frame.maxX
}

let leftMagin: CGFloat = pictureViewsMaxX + (userPictureViews.count == 1 ? 16 : 8)
additionalUsersLabelLeadingConstraint?.constant = leftMagin
let leftMagin: CGFloat = pictureViewsMaxX + (userPictureViews.count == 1 ? RoomTypingBubbleCell.pictureMaxMargin : RoomTypingBubbleCell.pictureMinMargin)
additionalUsersLabelLeadingConstraint.constant = leftMagin

dotsViewLeadingConstraint?.constant = additionalUsersLabel?.text.isEmptyOrNil == true ? leftMagin : leftMagin + 8 + (additionalUsersLabel?.frame.width ?? 0)
dotsViewLeadingConstraint?.constant = additionalUsersLabel.text.isEmptyOrNil == true ? leftMagin : leftMagin + 8 + additionalUsersLabel.frame.width
}

// MARK: - Themable

func update(theme: Theme) {
additionalUsersLabel.textColor = theme.textSecondaryColor
dotsView.highlightedDotColor = theme.textTertiaryColor
dotsView.dotColor = theme.textSecondaryColor
}


// MARK: - Business methods

func updateTypingUsers(_ typingUsers: Array<TypingUserInfo>, mediaManager: MXMediaManager) {
func updateTypingUsers(_ typingUsers: [TypingUserInfo], mediaManager: MXMediaManager) {
for pictureView in userPictureViews {
pictureView.removeFromSuperview()
}
userPictureViews = Array()
userPictureViews = []

for user in typingUsers {
if userPictureViews.count >= 4 {
if userPictureViews.count >= RoomTypingBubbleCell.maxPictureCount {
break
}

let pictureView = MXKImageView(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
let pictureView = MXKImageView(frame: CGRect(x: 0, y: 0, width: RoomTypingBubbleCell.pictureSize, height: RoomTypingBubbleCell.pictureSize))
pictureView.layer.masksToBounds = true
pictureView.layer.cornerRadius = pictureView.bounds.midX

Expand All @@ -106,11 +115,11 @@ class RoomTypingBubbleCell: UITableViewCell {

switch typingUsers.count {
case 0:
additionalUsersLabel?.text = nil
additionalUsersLabel.text = nil
case 1:
additionalUsersLabel?.text = firstUserNameFor(typingUsers)
additionalUsersLabel.text = firstUserNameFor(typingUsers)
default:
additionalUsersLabel?.text = VectorL10n.roomMultipleTypingNotification(firstUserNameFor(typingUsers) ?? "")
additionalUsersLabel.text = VectorL10n.roomMultipleTypingNotification(firstUserNameFor(typingUsers) ?? "")
}
self.setNeedsLayout()
}
Expand Down