Created
July 4, 2019 19:28
-
-
Save exclusiveTanim/0c7f1be043a6604f6c45bc0946fc5b7b to your computer and use it in GitHub Desktop.
Case: 01069114
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
function initUI() { | |
const appWindow = Ti.UI.createWindow(); | |
const listView = createListViewWithLazyLoad(40, 15, 1); | |
activityIndicator = Ti.UI.createActivityIndicator({ | |
bottom: 10, | |
color: 'red', | |
zIndex: 1000, | |
style: Ti.UI.ActivityIndicatorStyle.DARK | |
}); | |
appWindow.add(listView); | |
appWindow.add(activityIndicator); | |
appWindow.open(); | |
} | |
function createListViewWithLazyLoad(initialSize, batchSize, threshold) { | |
const listSection = Ti.UI.createListSection(); | |
initSectionWithItems(listSection, initialSize); | |
const listView = Ti.UI.createListView({ | |
sections: [ listSection ], | |
}); | |
updateMarker(listView, threshold); | |
listView.addEventListener('marker', evt => { | |
activityIndicator.show(); | |
appendNextBatch(listSection, batchSize); | |
updateMarker(listView, threshold); | |
}); | |
listView.addEventListener('scrollend', function(e){ | |
activityIndicator.hide(); | |
}); | |
return listView; | |
} | |
function initSectionWithItems(listSection, size) { | |
let items = []; | |
for (let i = 0; i < size; i++) { | |
const item = { | |
properties: { | |
title: `Item #${i}` | |
} | |
}; | |
items.push(item); | |
} | |
listSection.items = items; | |
} | |
function updateMarker(listView, threshold) { | |
const { | |
sections: [ | |
{ | |
items: { | |
length | |
} | |
} | |
] | |
} = listView; | |
const itemIndex = length - threshold; | |
listView.setMarker({ | |
itemIndex, | |
sectionIndex: 0 | |
}); | |
} | |
function appendNextBatch(listSection, batchSize) { | |
let items = []; | |
const { items: { length } } = listSection; | |
for (let i = 0; i < batchSize; i++) { | |
const item = { | |
properties: { | |
title: `Item #${length + i}` | |
} | |
}; | |
items.push(item); | |
} | |
listSection.appendItems(items, { | |
animated: false | |
}); | |
} | |
var activityIndicator; | |
initUI(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment