Add didTapAccessoryView Delegate method and adjust layout#834
Add didTapAccessoryView Delegate method and adjust layout#834nathantannar4 merged 8 commits intodevelopmentfrom
Conversation
|
Solves #770 |
| func configureAccessoryView(_ accessoryView: UIView, for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) { | ||
| let button = UIButton(type: .infoLight) | ||
| button.tintColor = .primaryColor | ||
| accessoryView.addSubview(button) |
There was a problem hiding this comment.
This subview will have to be removed somewhere because cells are reused?
There was a problem hiding this comment.
Added with a comment to remind devs of this
|
|
||
| // Accessory view aligned to the middle of the messageContainerView | ||
| var y = (messageContainerView.bounds.height - attributes.accessoryViewSize.height) / 2 | ||
| y += messageContainerView.frame.origin.y |
There was a problem hiding this comment.
Pretty sure the cellContentHeight method will be incorrect due to this new alignment
There was a problem hiding this comment.
Maybe not actually 🤔 Need to review in more depth
There was a problem hiding this comment.
@nathantannar4 I think your logic for this is:
var y = messageContainerView.frame.midY - (attributes.accessoryViewSize.height/2)This is a tough area of the codebase I know
SD10
left a comment
There was a problem hiding this comment.
@nathantannar4 Really appreciate you stepping up and taking this on 🥇 💯 💪 Just a few things
|
@SD10 💪 |
| let accessoryViewVerticalPadding = accessoryViewPadding(for: message).vertical | ||
| let accessoryViewTotalHeight = accessoryViewHeight + accessoryViewVerticalPadding | ||
| let accessoryViewYOriginInset = cellTopLabelHeight + messageTopLabelHeight + messageVerticalPadding + messageContainerPadding(for: message).top | ||
| let accessoryViewTotalHeight = accessoryViewHeight + accessoryViewVerticalPadding + accessoryViewYOriginInset |
There was a problem hiding this comment.
Care to explain what you're doing here? I'll review later but the logic was already super confusing before this 🤔
There was a problem hiding this comment.
Adding the extra distance that the accessoryView's origin starts at
There was a problem hiding this comment.
messageVerticalPadding already includes messageContainerPadding(for: message).top. Not sure if I really understand this approach? Shouldn't the logic be the same for resolving the height against the AvatarView when it is positioned .messageCenter?
If you think you have a better way of calculating it -- I'm open to suggestions -- but I can't understand what trick you're using so I'm skeptical 🤔
There was a problem hiding this comment.
Idk if this is a better way. I was just trying to come to a solution. I can adjust
| let accessoryViewVerticalPadding = accessoryViewPadding(for: message).vertical | ||
| let accessoryViewTotalHeight = accessoryViewHeight + accessoryViewVerticalPadding | ||
| let accessoryViewYOriginInset = cellTopLabelHeight + messageTopLabelHeight + messageContainerPadding(for: message).top | ||
| let accessoryViewTotalHeight = accessoryViewHeight + accessoryViewVerticalPadding + accessoryViewYOriginInset |
There was a problem hiding this comment.
This should just be:
let accessoryViewTotalHeight = accessoryViewHeight + accessoryViewVerticalPaddingNo need for accessoryViewYOriginInset, see the reason why below
There was a problem hiding this comment.
The reason is because the cellContentHeight logic was already fine as is 😆. Do you mind cleaning up the git history by squashing these commits? Since we flip flopped back and forth
EDIT: I think I may have to make a slight change actually... jeez
0f93660 to
041a239
Compare
|
Alright, fixing this now 😓 |
|
@SD10 I think this is fairly solid in its current state. Layout gets messed up when absurdly large accessory view sizes are set, but that could be listed as a known bug so we can push the 1.1 release which will fix the bottom inset issues. Then we could update to Swift 4.2 for a 1.2 update |
|
@nathantannar4 Thanks for taking lead here 👍 The problem here is we shouldn't ship an API where the accessory view has a |
| // Accessory view aligned to the middle of the messageContainerView | ||
| var y = (messageContainerView.bounds.height - attributes.accessoryViewSize.height) / 2 | ||
| y += messageContainerView.frame.origin.y | ||
| var y = messageContainerView.frame.midY - (attributes.accessoryViewSize.height/2) |
| var y = (messageContainerView.bounds.height - attributes.accessoryViewSize.height) / 2 | ||
| y += messageContainerView.frame.origin.y | ||
| var y = messageContainerView.frame.midY - (attributes.accessoryViewSize.height/2) | ||
| y -= attributes.accessoryViewPadding.vertical + attributes.accessoryViewPadding.top |
There was a problem hiding this comment.
This code isn't doing anything except ruining the calculation above. This is what I mean by no vertical padding
| layout?.setMessageIncomingMessagePadding(UIEdgeInsets(top: -outgoingAvatarOverlap, left: -18, bottom: outgoingAvatarOverlap, right: 18)) | ||
|
|
||
| layout?.setMessageIncomingAccessoryViewSize(CGSize(width: 30, height: 30)) | ||
| layout?.setMessageIncomingAccessoryViewPadding(UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)) |
There was a problem hiding this comment.
An unfortunate API at this point:
incomingAccessoryViewLeftPadding
incomingAccessoryViewRightPadding
outgoingAccessoryViewLeftPadding
outgoingAccessoryViewRightPadding
Accessoryview updates try to fix
| + messageContainerHeight + messageVerticalPadding + messageBottomLabelHeight | ||
| let cellHeight = max(avatarHeight, totalLabelHeight) | ||
| return max(accessoryViewTotalHeight, cellHeight) | ||
| return cellHeight |
There was a problem hiding this comment.
Are we sure this was the correct change? 🤔 Seems like it was correct before
There was a problem hiding this comment.
Ok, I thought this was one of the things you wanted reverted and if it messed up the height it was a developer error, back to how I originally had it :D
| let accessoryWidth = accessoryViewSize(for: message).width | ||
| let accessoryPadding = accessoryViewPadding(for: message) | ||
| return messagesLayout.itemWidth - avatarWidth - messagePadding.horizontal - accessoryWidth - accessoryPadding.horizontal | ||
| return messagesLayout.itemWidth - avatarWidth - messagePadding.horizontal + accessoryWidth + accessoryPadding.horizontal |
There was a problem hiding this comment.
These should be subtracted, not added?
There was a problem hiding this comment.
Reverted, I goofed


No description provided.