GithubHelp home page GithubHelp logo

nvdnkpr / ticollectionview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ricardoalcocer/ticollectionview

0.0 2.0 0.0 7.67 MB

UICollectionView / GridView for Appcelerator Titanium

License: Other

JavaScript 4.63% Java 33.47% Objective-C 58.83% Python 3.08%

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

Context menu

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

iOS specific configuration (Creation Only!)

  • showContextMenu Boolean - Should we show a contextual menu on longpress? Default: NO
  • contextMenuStrokeColor Color - The stroke color of the context Menu indicator
  • contextMenuItems Array - An array of context menu items each item is an object with the following attributes
    • tintColor Color - The color used to tint the icon
    • selected Image - The image for the selected state
    • unselected Image - The image for the unselected state

Events

  • contextMenuClick - Fired when a context menu item gets selected
    • index Number - The selected menu item index
    • itemIndex Number - The selected collection view item index
    • sectionIndex Number - The selected collection view section index

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',
    
    // Context menu options
    showContextMenu : true,
	contextMenuStrokeColor : "red",
	contextMenuItems : [
		{
			tintColor: "red",
			selected: "/images/UploadIconSelected.png",
			unselected:"/images/UploadIcon.png",
		},
		{
			tintColor: "red",
			selected: "/images/TrashIconSelected.png",
			unselected:"/images/TrashIcon.png",
		}
	],
    
    // 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.2.0
    • iOS only Added support for longtouch context menus
  • 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

License

Copyright 2014-2015 Marcel Pociot

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contextmenu License

Copyright 2014 Brandon McQuilkin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ticollectionview's People

Contributors

adesugbaa avatar mpociot avatar ricardoalcocer avatar

Watchers

 avatar  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.