Skip to content

Commit

Permalink
fix(android): obtain bindId for child templates
Browse files Browse the repository at this point in the history
  • Loading branch information
garymathews authored and sgtcoolguy committed Jan 19, 2021
1 parent 2cde1bc commit 88b1e2a
Showing 1 changed file with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,34 @@ public TiUIView createView(Activity activity)
*/
@Override
public boolean fireEvent(String eventName, Object data, boolean bubbles)
{
data = handleFireEvent(eventName, data);
return super.fireEvent(eventName, data, bubbles);
}
@Override
public boolean fireSyncEvent(String eventName, Object data, boolean bubbles)
{
data = handleFireEvent(eventName, data);
return super.fireSyncEvent(eventName, data, bubbles);
}

/**
* Handle event payload manipulation.
*
* @param eventName Name of fired event.
* @param data Data payload of fired event.
* @return Object of event payload.
*/
public Object handleFireEvent(String eventName, Object data)
{
// Inject row data into events.
final ListViewProxy listViewProxy = getListViewProxy();
if (listViewProxy != null) {
final KrollDict payload = data instanceof HashMap
? new KrollDict((HashMap<String, Object>) data) : new KrollDict();
final Object sourceObject = payload.containsKeyAndNotNull(TiC.EVENT_PROPERTY_SOURCE)
? payload.get(TiC.EVENT_PROPERTY_SOURCE) : this;
final TiViewProxy source = sourceObject instanceof TiViewProxy ? (TiViewProxy) sourceObject : this;

final Object parent = getParent();
if (parent instanceof ListSectionProxy) {
Expand All @@ -152,10 +174,14 @@ public boolean fireEvent(String eventName, Object data, boolean bubbles)
payload.put(TiC.PROPERTY_ITEM_ID, itemId);
}

if (this.template.containsKey(TiC.PROPERTY_BIND_ID)) {
for (final String key : binds.keySet()) {
if (binds.get(key).equals(source)) {

// Include `bindId` of template if specified.
payload.put(TiC.PROPERTY_BIND_ID, this.template.getString(TiC.PROPERTY_BIND_ID));
// Reverse lookup `bindId`.
// Include `bindId` of template if specified.
payload.put(TiC.PROPERTY_BIND_ID, key);
break;
}
}

final int accessoryType = getProperties().optInt(TiC.PROPERTY_ACCESSORY_TYPE,
Expand All @@ -170,11 +196,11 @@ public boolean fireEvent(String eventName, Object data, boolean bubbles)

// Fire `itemclick` event on ListView.
if (eventName.equals(TiC.EVENT_CLICK)) {
listViewProxy.fireEvent(TiC.EVENT_ITEM_CLICK, data);
listViewProxy.fireSyncEvent(TiC.EVENT_ITEM_CLICK, data);
}
}

return super.fireEvent(eventName, data, bubbles);
return data;
}

/**
Expand Down

0 comments on commit 88b1e2a

Please sign in to comment.