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

Message bubbles: Text message layout #5383

Merged
merged 66 commits into from
Jan 21, 2022
Merged

Conversation

SBiOSoftWhare
Copy link
Contributor

@SBiOSoftWhare SBiOSoftWhare commented Jan 14, 2022

Handles #5208, #5214, #5212, #5216

Two things to make in another PR:

  • Improve bubble height calculation (needs extra properties on RoomBubbleCellData to get only text position)
  • Use layout constants instead of copy pasted magic numbers
Simulator Screen Shot - iPhone 13 - 2022-01-18 at 16 10 41 Simulator Screen Shot - iPhone 13 - 2022-01-19 at 11 59 40

@github-actions
Copy link

github-actions bot commented Jan 14, 2022

📱 Scan the QR code below to install the build for this PR.
🔒 This build is for internal testing purpose. Only devices listed in the ad-hoc provisioning profile can install Element Alpha.

QR code

If you can't scan the QR code you can install the build via this link: https://i.diawi.com/qx5TjS

@stefanceriu stefanceriu self-requested a review January 19, 2022 14:21
Copy link
Member

@stefanceriu stefanceriu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great so far 👏 Left some comments inline.


} else if let messageTextViewHeight = cell.messageTextView?.frame.height {

finalBubbleHeight = messageTextViewHeight + extraMargin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will not build on Xcode 12 because "Cannot convert value of type 'Double' to expected argument type 'CGFloat'" (probably why the CI checks fail)


@return Last visible component or nil.
*/
- (MXKRoomBubbleComponent*)getLastBubbleComponentWithDisplay;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably start annotating nullability in ObjC, no matter how many warnings it generates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your POV but we have 25k warnings to address on Xcode 13, not sure we will see them :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more thinking about the Swift point of view, expose a nice interface to it without caring about ObjC warnings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see. Yes we should do that for sure but we have to carefully inspect each ObjC properties and method to be sure we are using the right nullability flag.

for (NSInteger index = 0; index < bubbleComponents.count; index++)
{
MXKRoomBubbleComponent *component = bubbleComponents[index];
if (component.attributedTextMessage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a foreach in reverseObjectEnumerator would be cleaner in this case. Same applies for the getFirstBubbleComponentWithDisplay method.. not reversed of course 😄

for(MXKRoomBubbleComponent *component in bubbleComponents.reverseObjectEnumerator) {
    if (component.attributedTextMessage)
    {
        return component;
    }
}

NS_ASSUME_NONNULL_BEGIN

/// Enables to register and provide room timeline cells
@protocol RoomTimelineCellProviderProtocol <NSObject>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice! 👌

// Hide sender info and avatar for bubble outgoing messages
return @{
// Clear
@(RoomTimelineCellIdentifierOutgoingTextMessage) : RoomOutgoingTextMsgWithoutSenderInfoBubbleCell.class,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly typo here, should it be RoomOutgoingTextMsgBubbleCell?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact for outgoing text messages we are hiding sender infos every time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it 👍

let leadingAnchor = messageTextView.leadingAnchor
let trailingAnchor = messageTextView.trailingAnchor

bubbleBackgroundView.updateHeight(messageTextView.frame.height)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we pin this to the cells content somehow so we don't have to manually manage its height?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the bubble background should wrap the visible text. And currently the textView is not exactly wrapping the text, especially if you add decorations such as previews and reactions.

import UIKit

/// BubbleReactionsView items alignement
enum BubbleReactionsViewAlignement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, should be Alignment

import UIKit

/// UICollectionViewFlowLayout with right align behavior
class CollectionViewRightAlignFlowLayout: UICollectionViewFlowLayout {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we should have one single parameterizable layout instead of two. Layout logic difference between left and right should be small.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sure but the implementation is not the same atm for the two different layout.

@@ -325,4 +325,7 @@ extern NSString *const kMXKRoomBubbleCellUrlItemInteraction;
*/
- (void)setupViews;

/// Add temporary subview to `tmpSubviews` property.
- (void)addTmpSubview:(UIView*)subview;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding subviews on cells and handling their frames externally is probably going to create more problems than it fixes. Ideally these should go in some sort of base cell container. I believe this code already existed and was just moved around but what's the long term goal?
Either way, we shouldn't use abbreviations in method names -> addTemporarySubview

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the decoration view and reuse handling can be better managed. It was already existing before as you said.

#import "RoomOutgoingAttachmentWithoutSenderInfoBubbleCell.h"
#import "RoomOutgoingAttachmentWithPaginationTitleBubbleCell.h"

@implementation BubbleRoomTimelineCellProvider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the plan here to provide different cells classes for bubbles or to continue manually decorating/modifying them based on the layout? I imagine that ideally we would have different views with no manual customization on top but I might be missing something 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should not have the RoomCellLayoutUpdaterProtocol that updates existing cell layout. And provide appropriated cells with RoomTimelineCellProvider for each room timeline styles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, that's what I though 👍

@thibaultamartin
Copy link
Contributor

This might be an opportunity to close #4150 as well?

@stefanceriu stefanceriu self-requested a review January 20, 2022 15:51
@SBiOSoftWhare SBiOSoftWhare merged commit 95ee3cf into develop Jan 21, 2022
@SBiOSoftWhare SBiOSoftWhare deleted the steve/5208_text_msg_layout branch January 21, 2022 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants