Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24817] Android: Implement ListView Alloy widget support #9955

Merged
merged 9 commits into from
Jul 30, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private DataItem bindProxiesAndProperties(KrollDict properties, boolean isRootTe
{
Object proxy = null;
String id = null;
Object props = null;
KrollDict props = null;
DataItem item = null;
if (properties.containsKey(TiC.PROPERTY_TI_PROXY)) {
proxy = properties.get(TiC.PROPERTY_TI_PROXY);
Expand All @@ -162,14 +162,22 @@ private DataItem bindProxiesAndProperties(KrollDict properties, boolean isRootTe
parent.addChild(item);
}
dataItems.put(id, item);

props = viewProxy.getProperties();
}

if (properties.containsKey(TiC.PROPERTY_PROPERTIES)) {
props = properties.get(TiC.PROPERTY_PROPERTIES);
KrollDict templateProperties = properties.getKrollDict(TiC.PROPERTY_PROPERTIES);
if (templateProperties != null) {
if (props != null) {
props.putAll(templateProperties);
} else {
props = templateProperties;
}
}
}

if (props instanceof HashMap) {
item.setDefaultProperties(new KrollDict((HashMap) props));
if (props != null) {
item.setDefaultProperties(props);
}

return item;
Expand Down
36 changes: 26 additions & 10 deletions android/modules/ui/src/js/listview.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ exports.bootstrap = function(Titanium) {
function processTemplate(properties) {
var cellProxy = Titanium.UI.createListItem();
properties.tiProxy = cellProxy;
var events = properties.events;
addEventListeners(events, cellProxy);
var events = properties.events;
addEventListeners(events, cellProxy);
}

//Recursive function that process childTemplates and append corresponding proxies to
//property 'tiProxy'. I.e: type: "Titanium.UI.Label" -> tiProxy: LabelProxy object
//Recursive function that process childTemplates and append corresponding proxies to
//property 'tiProxy'. I.e: type: "Titanium.UI.Label" -> tiProxy: LabelProxy object
function processChildTemplates(properties) {
if (!properties.hasOwnProperty('childTemplates')) return;

Expand Down Expand Up @@ -80,13 +80,29 @@ exports.bootstrap = function(Titanium) {

//convert name of UI elements into a constructor function.
//I.e: lookup("Titanium.UI.Label") returns Titanium.UI.createLabel function
function lookup(name) {
var lastDotIndex = name.lastIndexOf('.');
var proxy = eval(name.substring(0, lastDotIndex));
if (typeof(proxy) == undefined) return;
function lookup(namespace) {

var proxyName = name.slice(lastDotIndex + 1);
return proxy['create' + proxyName];
// handle Titanium widgets
if (/^(Ti|Titanium)/.test(namespace)) {
const namespaceIndex = namespace.lastIndexOf('.'),
proxyName = namespace.slice(namespaceIndex + 1),
parentNamespace = namespace.substring(0, namespaceIndex),
parentProxy = eval(parentNamespace);

if (parentProxy) {
return parentProxy['create' + proxyName];
}

// handle Alloy widgets
} else {
const widget = Module.main.require('/alloy/widgets/' + namespace + '/controllers/widget');
if (widget) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should handle plain CommonJS modules here as well? For iOS, we use a fallback case to do this. We require common-js modules to export a view via getView as well, which is a suitable requirement to have a formal way of knowing where the main view was exported.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garymathews Ping! The iOS PR was just merged.

return function (parameters) {
const obj = new widget(parameters);
return obj.getView();
};
}
}
}

//overwrite list view constructor function with our own.
Expand Down