Giter VIP home page Giter VIP logo

asyncmessagesviewcontroller's Introduction

AsyncMessagesViewController

A smooth, responsive and flexible messages UI library for iOS apps. Built on top of the awesome Texture (formerly AsyncDisplayKit) framework, it takes full advantage of asynchronous layout and rendering to deliver a "butter smooth" scrolling experience.

Screenshot1    Screenshot2

Dependencies

Requirements

  • iOS 9 and later.
  • Swift 4.
  • ARC.

Installation

From CocoaPods:

pod 'AsyncMessagesViewController'  

Without CocoaPods

Copy the Source\ directory to your project and install all dependencies.

How to use

  • Example project
    • Run pod install.
    • Open AsyncMessagesViewController.xcworkspace.
    • Enjoy the simple ViewController.swift class.
  • Model
    • Your message model object should conform to MessageData protocol.
  • View
    • MessageCellNode is your friend. Most of the time you don't want to subclass it.
    • There are 2 basic built-in bubble nodes implemented for you: MessageTextBubbleNode for text based messages and MessageNetworkImageBubbleNode for remote image based messages.
    • Need a custom bubble node? Here you go.
  • Controller
    • Your view controller should subclass AsyncMessagesViewController. As you may see, it's a very simple view controller (and should be). Most of the magic is in the data source.
    • What data source, you may ask. Any data source that conform to AsyncMessagesCollectionViewDataSource protocol.
    • There is a default implemention: DefaultAsyncMessagesCollectionViewDataSource. This class keeps a sorted list of messages, but doesn't allow you to change them directly. Instead, you must alter messages using given methods in its protocol and let it handle the heavy work. It can (supposedly) smartly determine which cells need to be inserted, deleted and reloaded. Why? because:
      • Calling reloadData is very expensive on ASCollectionView (and ASTableView).
      • Most of the time, inserting/deleting a cell causing UI changes in other cells as well. DefaultAsyncMessagesCollectionViewDataSource can detect those changes automatically.
    • MessageCellNodeMetadata provides runtime-computed information about a message and how its data should be presented in a MessageCellNode. Metadata of a message is often computed based on the relationship with other messages. For example, message's sender name should be displayed if it is an incoming message and is the first one in a set of consecutive messages sent by a same user. Or message's date should be shown if it is the first message sent within a 15 minutes window. This kind of UI logic is encapsulated in MessageCellNodeMetadataFactory and computed at runtime. Of course you can implement your own logic.

Customizations

  • Custom bubble node:
    • Please read this guide on subclassing ASDisplayNode.
    • Implement a factory that conforms to MessageBubbleNodeFactory protocol.
    • Inject your factory to DefaultAsyncMessagesCollectionViewDataSource via its initializer.
    • Inject the data source to AsyncMessagesViewController (also via its initializer).
  • Custom bubble image's colors:
    • Initiate a MessageBubbleImageProvider with whatever colors you want.
    • Inject it to your data source.
    • Inject the data source to your view controller.
  • Custom bubble images:
    • Implementing your own MessageBubbleImageProvider.
    • Inject it to your data source.
    • Inject the data source to your view controller.
  • Custom logic for computing cell metadata:
    • Subclass MessageCellNodeMetadataFactory and override any neccessary method.
    • Inject it to your data source.
    • Inject the data source to your view controller.
  • Custom format for message date:
    • Subclass MessageTimestampFormatter and override attributedTimestamp(NSDate).
    • Inject it to your data source.
    • Inject the data source to your view controller.
  • Any customization related to the input toolbar:
  • Other customizations:
    • File an issue and I will be more than happy to help :)

Contributing

All feedbacks, questions and pull requests are very welcome. See here for details.

Credits

Created by Huy Nguyen, an Android developer :)

License

AsyncMessagesViewController is released under an MIT License. See here for details.

Copyright © 2015 Huy Nguyen.

asyncmessagesviewcontroller's People

Contributors

fredericjacobs avatar nguyenhuy avatar qtdzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asyncmessagesviewcontroller's Issues

Automatic scroll when TextView edit begins

I just noticed that when the chat view is at the bottom and I tap the input view, the chat view doesn't scroll up, and the last bubbles of chat get hidden by the keyboard view. When I tap outside the keyboard, the keyboard get dismissed but the chat scrolls back down with it, as if it had been scrolled up before and now "wants to get back" to its initial position. Though, when the chat view is not at the bottom, if I tap the input view, the chat does scroll up in a normal way, and when I tap outside the keyboard it scrolls back to its initial position. How can I fix the scroll behavior when the chat view is at the very bottom? Thank you.

Unable to subclass AsyncMessagesViewController

After installing the pod in XCode 9, I am unable subclass or otherwise use AsyncMessagesViewController. All other dependencies (SLKTextViewController, etc.) are accessible. I have deintegrated and reinstalled my pods. All other pods work.

How about add CocoaPods's support

⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️

Update
Oh, forget this. It can not be add to CocoaPods...

Roadmap

Hey @nguyenhuy!

Terrific project. I'm excited. I've been thinking for some time now to build something similar but never managed to find time to actually write it, so congrats to you.

Do you have a public roadmap or contributor guidelines?

Assertion failure in -[_ASCollectionViewProxy forwardingTargetForSelector:]

Hi! Here is the scenario: my first view controller has an ASTableView containing some dummy cells for testing. Clicking either cell will push a new view controller named ChatViewController (which is exactly the ViewController from your example), with the exception that the collectionView scrolls to bottom after all the messages are inserted with success.

dataSource.collectionView(collectionView, insertMessages: messages) { (success) -> () in
            if (success) {
                self.scrollCollectionViewToBottom()
            }
        }

After I click the back button, my app crashes giving this log:
screen shot 2015-11-27 at 17 58 21

If I scroll back to top in the ChatViewController and click the back button, the app will not crash. Is there any solution? Thank you!

Avatar image tap event

Would you create an avatar image event delegate or callback? Or is there any easy way you suggest to add a listener to avatar images?

avatar image

Is is posiible to have avatar image under the message bubble. Thanks

dude the example is not building

@nguyenhuy
The example is SO outdated....
Clearly showing that this library is useless..
OMG I waisted time to fix errors, and in the end got error with .some lPods not found...

You are worst programmer ever!!!

Custom bubbles from UIView

Hey,

First of all: Congrats for this awesome work! The first time I see AsyncDisplayKit I thought it would be awesome to have a chat library built on top of it.

I don't have played enough with AsyncDisplayKit to being comfortable to adopt its sizing and designing techniques (i.e. without UIKit and Autolayout), and I'm have a deploy to do in the next days.

I have a .xib within a UIView designed chat bubble I would like to port to AsyncMessagesViewController. Can I use the following method to inject my custom view into an ASDisplayNode and make it works with your library?

let node = ASDisplayNode(viewBlock: { () -> UIView! in
    let view = SomeView();
    return view
})

(I've tried it, but I don't know if I'm doing something wrong or if it is not possible)

Thank you in advance!

Ability to have sections

I have yet to find a message Library that will allow me to expand and collapse sections. I want to be able to pull in a "chat history" by date and somehow section it off by date. Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.