Skip to content

Instantly share code, notes, and snippets.

@viezel
Created March 23, 2015 09:25
Show Gist options
  • Save viezel/3b681f6d4ff2046bfdc9 to your computer and use it in GitHub Desktop.
Save viezel/3b681f6d4ff2046bfdc9 to your computer and use it in GitHub Desktop.
Example of how to use TiCollectionView
$.listView.addEventListener("contextMenuClick", function(e){
alert( "You clicked on menu item " + e.index + " - CollectionView item " + e.itemIndex );
});
$.listView.addEventListener("pull", function(e){
Ti.API.info(e);
});
$.listView.addEventListener("pullend", function(e){
Ti.API.info(e);
});
function myRefresher(e) {
Ti.API.info("myRefresher");
// fake a remote fetch
setTimeout(function(){
Ti.API.info("myRefresher callback");
e.hide();
}, 3000);
}
// init the Pull To Refresh Widget
$.ptr.refresh();
// init the infinite scroll
$.is.init($.listView);
function myLoader(e) {
// fake fetch call
setTimeout(function(){
e.success();
}, 2000);
}
$.win.open();
".container": {
backgroundColor:"white"
}
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000"
}
"#label": {
font: {
fontSize: 12
}
}
"#listView[platform=ios]":{
showContextMenu: true,
contextMenuStrokeColor : "red",
// insets
topInset: "20dp",
leftInset: "10dp",
rightInset: "10dp",
bottomInset: "20dp",
contextMenuItems : [
{
tintColor: "red",
selected: "/images/UploadIconSelected.png",
unselected:"/images/UploadIcon.png",
},
{
tintColor: "black",
selected: "/images/TrashIconSelected.png",
unselected:"/images/TrashIcon.png",
},
{
tintColor: "blue",
selected: "/images/TrashIconSelected.png",
unselected:"/images/UploadIcon.png",
},
{
tintColor: "yellow",
selected: "/images/TrashIconSelected.png",
unselected:"/images/TrashIcon.png",
}
],
}
"ListSection":{
itemSpacing: 5,
lineSpacing: 5
}
<Alloy>
<Window id="win">
<Widget id="ptr" src="nl.fokkezb.pullToRefresh" onRelease="myRefresher">
<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" top="30dp" id="subtitle" />
</View>
</ItemTemplate>
</Templates>
<ListSection id="section1" module="de.marcelpociot.collectionview" method="createCollectionSection">
<HeaderView>
<View backgroundColor="#DDD" height="Ti.UI.SIZE">
<Label>GOOD SHIT</Label>
</View>
</HeaderView>
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="red" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="green" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="yellow" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="blue" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="red" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="green" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="yellow" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="blue" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="red" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="green" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="yellow" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="blue" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="red" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<FooterView>
<View backgroundColor="#EEE" height="Ti.UI.SIZE">
<Label>Hello Footer</Label>
</View>
</FooterView>
</ListSection>
<ListSection module="de.marcelpociot.collectionview" method="createCollectionSection">
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="green" width="150" height="360" info:text="Banana" es_info:text="Banana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="yellow" width="150" height="360" info:text="Apple" es_info:text="Manzana" />
<ListItem module="de.marcelpociot.collectionview" method="createCollectionItem" backgroundColor="blue" width="150" height="360" info:text="Banana" es_info:text="Banana" />
</ListSection>
<Widget id="is" src="nl.fokkezb.infiniteScroll" onEnd="myLoader" />
</ListView>
</Widget>
</Window>
</Alloy>
@wackyapps
Copy link

Hello,
I tried using this with collection view module on iOS.

This does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment