Skip to content

Typing Indicator Support#776

Closed
nathantannar4 wants to merge 13 commits into
developmentfrom
typingBubble
Closed

Typing Indicator Support#776
nathantannar4 wants to merge 13 commits into
developmentfrom
typingBubble

Conversation

@nathantannar4

Copy link
Copy Markdown
Member

This PR adds TypingIndicator support by reserving the last section of the MessageCollectionView as needed. MessageKit will support the iMessage style typing bubble out of the box but you can also implement your own typing indicator cells!

@nathantannar4 nathantannar4 self-assigned this Jul 23, 2018
@nathantannar4 nathantannar4 added this to the 2.0 milestone Jul 23, 2018
@nathantannar4 nathantannar4 requested a review from zhongwuzw July 23, 2018 06:06
@zhongwuzw

Copy link
Copy Markdown
Member

When the indicator is animating, the same time I post a message, indicator cell would scroll to the bottom, this scroll animation is what we want?

@nathantannar4

Copy link
Copy Markdown
Member Author

I think that's how other messaging apps handle it

Sent with GitHawk

@SD10

SD10 commented Jul 23, 2018

Copy link
Copy Markdown
Member

I'll have to check this animation you guys are talking about. This is a feature that MessageKit will support, but personally I will never use it

setTypingIndicatorHidden(!isTyping, animated: true, completion: { _ in
self.messagesCollectionView.scrollToBottom(animated: true)
})
// defer {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code is commented out, you planning on doing something with it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Once this gets merged I will be updating the entire example app with more detailed examples for the TypingIndicator and custom cells.

/// - updates: A block of code that will be executed during `performBatchUpdates`
/// when `animated` is `TRUE` or before the `completion` block executes
/// when `animated` is `FALSE`
/// - completion: A completion block to execute after the insertion/deletion

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice docs 💯 🥇

Comment thread CHANGELOG.md

### Added

- **Breaking Change** Added typing indicator support to MessageKit by adding an extra section to `MessagesCollectionView` when needed. This included adding the following views: `BubbleCircle`, `TypingBubble`, `TypingIndicator`, `TypingBubbleCell`. Determine if the section is reserved for the typing indicator with `isSectionReservedForTypingIndicator(_ section: Int) -> Bool`, and set the typing indicators visiability with `setTypingIndicatorHidden(_ isHidden: Bool, animated: Bool, whilePerforming updates: (() -> Void)? = nil, completion: ((Bool) -> Void)?=nil)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is more a reminder to myself to improve this CHANGELOG entry before merging

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know how we can tell the user that numberOfSections(in collectionView: UICollectionView) would not only return the data source the user provide.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this is a valid concern that I have as well. I like the general idea but I haven't gone deep into how this will affect MessageKit

@stasian23

Copy link
Copy Markdown

Hi guys, are you planning to merge it to dev, and release? We really need this feature in our project

@SD10

SD10 commented Aug 8, 2018

Copy link
Copy Markdown
Member

@stasian23 That's the plan but this is lower priority right now. I like the general idea but I haven't thoroughly reviewed the code to see what impact this PR would have

@nathantannar4

Copy link
Copy Markdown
Member Author

@stasian23 I just rebased thetypingBubble branch onto the development branch. You can specify in your pod file to pull from the typingBubble branch if you would like to use it in pre-release

/// when `animated` is `TRUE` or before the `completion` block executes
/// when `animated` is `FALSE`
/// - completion: A completion block to execute after the insertion/deletion
open func setTypingIndicatorHidden(_ isHidden: Bool, animated: Bool, whilePerforming updates: (() -> Void)? = nil, completion: ((Bool) -> Void)?=nil) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

completion: ((Bool) -> Void)?=nil,please keep indention between nil.

let section = messagesCollectionView.numberOfSections

isTypingIndicatorHidden = isHidden
if let messagesFlowLayout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe guard return would be better, if layout is not MessagesCollectionViewFlowLayout, nothing we can do.

Comment thread CHANGELOG.md

### Added

- **Breaking Change** Added typing indicator support to MessageKit by adding an extra section to `MessagesCollectionView` when needed. This included adding the following views: `BubbleCircle`, `TypingBubble`, `TypingIndicator`, `TypingBubbleCell`. Determine if the section is reserved for the typing indicator with `isSectionReservedForTypingIndicator(_ section: Int) -> Bool`, and set the typing indicators visiability with `setTypingIndicatorHidden(_ isHidden: Bool, animated: Bool, whilePerforming updates: (() -> Void)? = nil, completion: ((Bool) -> Void)?=nil)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know how we can tell the user that numberOfSections(in collectionView: UICollectionView) would not only return the data source the user provide.

cell.typingBubble.typingIndicator.dotColor = typingBubbleDotColor
cell.typingBubble.startAnimating()
return cell
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a suggestion, can we move these things to a separate function? collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) becomes the big function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, it should be a function on the cell

}

open func setupSubviews() {
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thats how other MessageContentCell are set up so I added this for consistency

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't copy my code if it's bad (it usually is) 😆

super.prepareForReuse()
if typingBubble.isAnimating {
typingBubble.stopAnimating()
typingBubble.startAnimating()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

startAnimating() is not necessary IMO.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The animations stop when they move off screen, so they need to be restarted when they are about to appear again

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@nathantannar4 May I miss something? you already start it in cellForItemAt. 🤔

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Its required for the cell reusability. If its not initially started in cellForItem then isAnimating will be false

@nathantannar4

Copy link
Copy Markdown
Member Author

Recommendations added

@gorbat-o

Copy link
Copy Markdown

Hey,

Is there any progress on this PR ?

I hope it can be merged soon :D

@nathantannar4

Copy link
Copy Markdown
Member Author

2.0 release 😄

Sent with GitHawk

@gorbat-o

gorbat-o commented Sep 25, 2018

Copy link
Copy Markdown

😱😱😱😱😱
When ??

@nathantannar4

Copy link
Copy Markdown
Member Author

@SD10 and I have had some offline discussion about this and how this method reserves the last section of the MessagesCollectionView.

@SD10 I know you mentioned reserving the last section would be an issue for RxSwift users, but is there anything else?

@nathantannar4 nathantannar4 removed this from the 2.1 milestone Oct 13, 2018
@nathantannar4

Copy link
Copy Markdown
Member Author

Re-evaluating this PR so that is does not reserve a section

@nathantannar4

Copy link
Copy Markdown
Member Author

@SD10 @zhongwuzw I am revisiting this so we can get it merged. Are there still hesitations to adding an additional section? I tried using supplementary views but it becomes much more challenging to manage since the indicator ends up needing to be tied to a specific section. There are just many more edge cases that route.

@SD10

SD10 commented Dec 27, 2018

Copy link
Copy Markdown
Member

Are there still hesitations to adding an additional section?

It's been so long I'll have to re-evaluate reserving the last section for the typing indicator but I do think the highly dynamic nature of a typing indicator would cause a lot of IndexPath inconsistencies with apps in a production environment.

Probably not a good candidate for 3.0

@zhongwuzw

Copy link
Copy Markdown
Member

I agree with @SD10 , can we put the indicator view as a subview of UICollectionView? not treat it as a cell.

@nathantannar4 nathantannar4 deleted the typingBubble branch April 25, 2019 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants