Skip to content

Commit

Permalink
fix(android): touchEnabled for ListView
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Dec 6, 2023
1 parent 3c0794f commit c1f9603
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,22 @@ public Object handleEvent(String eventName, Object data, boolean fireItemClick)
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 KrollDict properties = getProperties();

final Object parent = getParent();
boolean sectionTouchEnabled = true;

if (parent instanceof ListSectionProxy) {
final ListSectionProxy section = (ListSectionProxy) parent;

// Include section specific properties.
payload.putIfAbsent(TiC.PROPERTY_SECTION, section);
payload.putIfAbsent(TiC.PROPERTY_SECTION_INDEX, listViewProxy.getIndexOfSection(section));
payload.putIfAbsent(TiC.PROPERTY_ITEM_INDEX, getIndexInSection());
sectionTouchEnabled = section.getProperties().optBoolean(TiC.PROPERTY_TOUCH_ENABLED, true);
}

final Object itemId = getProperties().get(TiC.PROPERTY_ITEM_ID);
final Object itemId = properties.get(TiC.PROPERTY_ITEM_ID);
if (itemId != null) {

// Include `itemId` if specified.
Expand All @@ -156,9 +160,12 @@ public Object handleEvent(String eventName, Object data, boolean fireItemClick)
}
}

final int accessoryType = getProperties().optInt(TiC.PROPERTY_ACCESSORY_TYPE,
final int accessoryType = properties.optInt(TiC.PROPERTY_ACCESSORY_TYPE,
UIModule.LIST_ACCESSORY_TYPE_NONE);
final boolean isAccessoryDetail = accessoryType == UIModule.LIST_ACCESSORY_TYPE_DETAIL;
final boolean touchEnabled = properties.optBoolean(TiC.PROPERTY_TOUCH_ENABLED, true);
final boolean listViewTouchEnabled = listViewProxy.getProperties()
.optBoolean(TiC.PROPERTY_TOUCH_ENABLED, true);

// If item is `LIST_ACCESSORY_TYPE_DETAIL` then `accessoryClicked` will be `true`.
payload.put(TiC.EVENT_PROPERTY_ACCESSORY_CLICKED, isAccessoryDetail);
Expand All @@ -167,7 +174,8 @@ public Object handleEvent(String eventName, Object data, boolean fireItemClick)
data = payload;

// Fire `itemclick` event on ListView.
if (fireItemClick && eventName.equals(TiC.EVENT_CLICK)) {
if (fireItemClick && eventName.equals(TiC.EVENT_CLICK) && touchEnabled
&& sectionTouchEnabled && listViewTouchEnabled) {
listViewProxy.fireSyncEvent(TiC.EVENT_ITEM_CLICK, data);
}
}
Expand Down

0 comments on commit c1f9603

Please sign in to comment.