Code Monkey home page Code Monkey logo

ticollectionview's Introduction

#TiCollectionView gittio License issues

Overview

This module allows you to use a collection / grid view with the Appcelerator Titanium SDK.

It uses the Titanium ItemTemplate objects for the best performance.

Grid layout

example

Waterfall layout

example

Installation

Get it gitTio

Download the latest distribution ZIP-file and consult the Titanium Documentation on how install it, or simply use the gitTio CLI:

$ gittio install de.marcelpociot.collectionview

Important notes for Android

In order to make this module work for Android, you need to use the provided "CollectionView.js" CommonJS library.

API

This module uses the Ti.UI.ListView API.

Additional parameters

The ListView API gets extended by these custom parameters:

  • layout (LAYOUT_WATERFALL | LAYOUT_GRID) - sets the layout to use for the collection view. You can select between the waterfall layout (like Pinterest) or the standard grid layout which is the default value.

Waterfall layout specific configuration

  • columnCount (Number) The number of columns to use. Default: 3
  • minimumColumnSpacing (Number) The minimum spacing between each columns
  • minimumInteritemSpacing (Number) The minimum spacing between each items (vertically)
  • renderDirection (DIRECTION_LEFT_TO_RIGHT | DIRECTION_RIGHT_TO_LEFT | DIRECTION_SHORTEST_FIRST) The render direction to use. Default: DIRECTION_LEFT_TO_RIGHT

Android specific configuration

  • columnWidth (Number) - Defines the width of each column. The Android module will fit as many columns in a row as possible
  • verticalSpacing (Number) - Defines the vertical column spacing
  • horizontalSpacing (Number) - Defines the horizontal column spacing

Usage

Alloy:

    <ListView id="listView" backgroundColor="white" defaultItemTemplate="template" module="CollectionView" method="createCollectionView">

    <Templates>
        <ItemTemplate name="template">
            <View id="container">
                <Label bindId="info" id="title" />
                <Label bindId="es_info" id="subtitle" />
            </View>
        </ItemTemplate>

    </Templates>

    <ListSection module="de.marcelpociot.collectionview" method="createCollectionSection">

        <ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" width="150" height="200" info:text="Apple" es_info:text="Manzana" />
        <ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" width="150" height="200" info:text="Banana" es_info:text="Banana" />
        <ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" width="150" height="200" info:text="Apple" es_info:text="Manzana" />
        <ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" width="150" height="200" info:text="Banana" es_info:text="Banana" />
    </ListSection>
</ListView>

Vanilla JS:

var collectionView = require("de.marcelpociot.collectionview");

var win = Ti.UI.createWindow({backgroundColor: 'white'});

// Create a custom template that displays an image on the left, 
// then a title next to it with a subtitle below it.
var myTemplate = {
	childTemplates: [
    	{                            // Title 
        	type: 'Ti.UI.Label',     // Use a label for the title 
	        bindId: 'info',          // Maps to a custom info property of the item data
            properties: {            // Sets the label properties
    	        color: 'black',
        	    font: { fontFamily:'Arial', fontSize: '20dp', fontWeight:'bold' },
            	left: '60dp', top: 0,
        	}
        },
	    {                            // Subtitle
    	    type: 'Ti.UI.Label',     // Use a label for the subtitle
        	bindId: 'es_info',       // Maps to a custom es_info property of the item data
            properties: {            // Sets the label properties
	            color: 'gray',
    	        font: { fontFamily:'Arial', fontSize: '14dp' },
        	    left: '60dp', top: '25dp',
            }
	    }
    ]
};

var listView = require("CollectionView")".createCollectionView({
	backgroundColor: "white",
	top: 0,
	left: 0,
	width: Ti.UI.FILL,
	height: Ti.UI.FILL,
    // Maps myTemplate dictionary to 'template' string
    templates: { 'template': myTemplate },
    // Use 'template', that is, the myTemplate dict created earlier
    // for all items as long as the template property is not defined for an item.
    defaultItemTemplate: 'template',
    // ANDROID ONLY
    columnWidth: 150,
    verticalSpacing: 10,
    horizontalSpacing: 10
});
var sections = [];

var fruitSection = collectionView.createCollectionSection({ headerTitle: 'Fruits / Frutas'});
var fruitDataSet = [
	// the text property of info maps to the text property of the title label
    // the text property of es_info maps to text property of the subtitle label
    // the image property of pic maps to the image property of the image view
    { info: {text: 'Apple'}, es_info: {text: 'Manzana'}, properties: {height:150,width:150}},
    { info: {text: 'Apple'}, es_info: {text: 'Manzana'}, properties: {height:150,width:150}},
];
fruitSection.setItems(fruitDataSet);
sections.push(fruitSection);

listView.setSections(sections);
win.add(listView);
win.open();

Changelog

  • v1.1.1
    • Added support for Pull To Refresh
  • v1.1.0
    • Added waterfall layout for iOS
  • v1.0.0
    • Initial release with Android support added

ticollectionview's People

Contributors

mpociot avatar adesugbaa avatar

Watchers

Kosso avatar James Cloos 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.