-
-
Save nuno/167541fab1746c64cbfd to your computer and use it in GitHub Desktop.
Memory issue with https://github.com/mpociot/TiCollectionView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var args = arguments[0] || {};var url = "https://api.github.com/search/repositories?q=pushed:>2015-09-01&order=desc"; | |
var page = 1, | |
loading = false; | |
function init() { | |
$.activityIndicator.show(); | |
load(function(items) { | |
$.list.setItems(transform(items)); | |
$.activityIndicator.hide(); | |
$.is.init($.listView); | |
$.is.mark(); | |
}, function(e) { | |
Ti.API.error(e.error); | |
$.activityIndicator.hide(); | |
}); | |
} | |
function transform(items) { | |
return _.map(items, function(item) { | |
return { | |
avatar: { | |
image: item.owner.avatar_url | |
}, | |
name: { | |
text: item.name | |
}, | |
index: { | |
text: '?' | |
}, | |
properties: {height:100,width:100} | |
}; | |
}); | |
} | |
function load(callback, error) { | |
if(loading) return; | |
loading = true; | |
var client = Ti.Network.createHTTPClient({ | |
onload : function(e) { | |
var reps = JSON.parse(this.responseText); | |
callback && callback(reps.items); | |
page ++; | |
loading = false; | |
}, | |
onerror : function(e) { | |
error && error(e); | |
loading = false; | |
}, | |
timeout : 5000 | |
}); | |
client.open("GET", url+"&page="+page); | |
client.send(); | |
} | |
function onLoadMore(evt) { | |
load(function(items) { | |
$.list.appendItems(transform(items)); | |
evt.success(); | |
}, function(e) { | |
Ti.API.error(e.error); | |
evt.error("Error"); | |
}); | |
} | |
function cleanup() { | |
$.is.dettach(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"#nameWrapper": { | |
opacity:0.8, | |
backgroundColor: "#ffffff", | |
left: 5, | |
top: 5, | |
right: 5, | |
width: Titanium.UI.SIZE, | |
height: Titanium.UI.SIZE | |
} | |
"#name": { | |
left: 4, | |
top: 4, | |
right: 4, | |
bottom: 4, | |
font: { | |
fontSize: 11 | |
} | |
} | |
"#index": { | |
right: 5, | |
bottom: 5, | |
font: { | |
fontSize: 10 | |
}, | |
color: "#4c4c4c", | |
backgroundColor: "#ffffff" | |
} | |
"#activityIndicator[platform=android]": { | |
style: Titanium.UI.ActivityIndicatorStyle.BIG_DARK | |
} | |
"#activityIndicator[platform=ios]": { | |
style: Titanium.UI.iPhone.ActivityIndicatorStyle.DARK | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Alloy> | |
<Window onOpen="init" onClose="cleanup" title="Demo"> | |
<ListView id="listView" backgroundColor="white" | |
defaultItemTemplate="template" | |
module="CollectionView" method="createCollectionView" | |
columnWidth = "200" | |
verticalSpacing = "10" | |
horizontalSpacing = "10" | |
> | |
<Templates> | |
<ItemTemplate name="template"> | |
<View id="container"> | |
<ImageView id="avatar" bindId="avatar" width="Titanium.UI.FILL" height="Titanium.UI.FILL" /> | |
<View id="nameWrapper"> | |
<Label id="name" bindId="name" color="#000" /> | |
</View> | |
<Label id="index" bindId="index"/> | |
</View> | |
</ItemTemplate> | |
</Templates> | |
<ListSection id="list" module="de.marcelpociot.collectionview" method="createCollectionSection"> | |
</ListSection> | |
<Widget id="is" src="nl.fokkezb.infiniteScroll" onEnd="onLoadMore" /> | |
</ListView> | |
<ActivityIndicator id="activityIndicator" /> | |
</Window> | |
</Alloy> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment