Code Monkey home page Code Monkey logo

thesmiths-widgets.ts.chat's Introduction

Chat Widget

Appcelerator Titanium Appcelerator Alloy License

This widget is an example of chat widget where the content is separated from the widget in such a way that any kind of model could be used with this widget. The widget uses builders to generate views corresponding to a message; This builders act as delegates so that the widget can focus its concern on displaying correctly those messages together.

Therefore, it handles the succession of messages in a TableView and gives easy ways to :

  • load older messages
  • add new message to the list
  • handle user inputs in a 'responsive' textArea

As a matter of fact, the widget is also a playground for new testing methods and tools. Then, It follows a continuous integration process where builds and tests are made in the cloud with travis.

A detailed documentation may be found here : documentation

Previews

Screenshots taken on an iPhone 4s Simulator using the messenger-like builder. screenshots

How to install it

Comming on GitTio.

How to use it

Initialization

First of all, the widget might be initialized once the windows is opened. This could be performed in the following way :

    $.index.addEventListener('open', function (e) {
        $.chat.init({
            messageBuilder: messengerLike,
        });
    });

    // ... Do some awesome stuff

    $.index.open();

Others parameters might be supplied during the initialisation such as an initial set of messages. Please, have a look to the following documentation page for more info.

Listen to events

The widget may trigger two kind of events : load and newmessage. Both event are documented here.

The first one is fired each time the user is asking for older messages (i.e.: scrolling up); the event contains some useful pieces of information such as the last message currently displayed as well as callbacks to response to the widget.

    $.chat.on('load', function (loadEvent) {
        // Do some stuff do handle the request ...
        loadEvent.success(/* someOlderMessages */);
    });

The second one is fired when the user has pressed the send button. The event holds data such as the content of the message and the date at which it has been send. Also, like the previous one, it offers two callbacks to handle success and error response. As the widget does not know how to create a message from a text content, the parent controller is supposed to supply an instance of the new message as an argument of the success callback.

    $.chat.on('newmessage', function (newMessageEvent) {
        // Do some stuff to handle the new message
        newMessageEvent.success(/* message */);
    });

Add new messages to the widget

It is also possible to manually add new messages to the chat widget (for instance, when a new message is sent from an app, it may trigger a specific event to the app of the opposite user...). To do such a thing, just use the receive function which handle either a message or an array of messages.

    $.chat.receive(/* Tons of messages */);

Dependencies

Pull To Refresh

The widget uses the pullToRefresh widget by Fokke Zandbergen

Message Builder

It also requires you to supply a message builder in order to render views. More info about message builders right here.

TODO

  • Give ways to change the style (colors, size, etc. ) from the outside.
  • Add a clean function

wearesmiths

thesmiths-widgets.ts.chat's People

Contributors

ktorz avatar xavierlacot avatar

Watchers

James Cloos avatar Brenton House avatar

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.