Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28291] View events in a ListView ItemTemplate doesn't include property type

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionUnresolved
Affected Version/sRelease 9.3.0
Fix Version/sRelease 9.3.1
ComponentsAndroid
Labelslistview, regression
ReporterRodrigo Farfán
AssigneeGary Mathews
Created2020-12-15T12:22:43.000+0000
Updated2021-01-19T19:53:52.000+0000

Description

I've got a ListView with an ItemTemplate on which some Views have onSingletap and onDoubletap listeners My alloy View:
<Alloy>
  <Collection id="avisosCorporativos" src="AvisoCorporativo" instance="true"/>
  <Window id="win" onOpen="win_onOpen" onClose="win_onClose" backgroundColor="#fff">
    <ListView id="lvAvisos" defaultItemTemplate="template" height="Ti.UI.SIZE">
      <Templates>
          <ItemTemplate name="template" class="defaultTemplate">
            <View class="vTemplateContainer" onLongpress="gestureForwarder">
              <View class="vMessageRow1" bindId="vMessageRow1">
                <Label id="lMessageReadStatus" bindId="lMessageReadStatus"/>
                <Label id="lMessageSubject" bindId="lMessageSubject" onSingletap="gestureForwarder" onDoubletap="gestureForwarder"/>
              </View>
              <View class="vMessageRow2" bindId="vMessageRow2">
                <Label id="lMessageDate" bindId="lMessageDate"/>
                <Label id="lMessagePriority" bindId="lMessagePriority"/>
              </View>                    
            </View>                   
          </ItemTemplate>
      </Templates>
      <ListSection id="listSection" dataCollection="$.avisosCorporativos" dataTransform="_listSection_dataTransform">
        <ListItem lMessageReadStatus:text="{ReadStatus}" 
          lMessageSubject:text="{Asunto}"
          lMessageSubject:font="{Font}"
          lMessageDate:text="{Fecha}"
          lMessagePriority:text="{Priority}"
          />
      </ListSection>
    </ListView>
  </Window>
</Alloy>

In controller, gestureForwarder handler function simply logs the event payload "stringified" and attribute .type is undefined. I've fixed this rebuilding the SDK with a little modification. In ListItemProxy.java, in function generateViewFromTemplate, adding this line
payload.put(TiC.EVENT_PROPERTY_TYPE, eventName);
Besides this, I observe another 2 issues: 1) If I add onClick event for a view in the template that also has the onSingletap o onDoubletap, both events are triggered (click+singletap or click+doubletap). 2) The onLongpress event is also triggered without the .type property and, in this case, all the listview properties (sectionIndex, itemIndex, etc...) are not included either. (Same with swipe events) All this events are working fine on SDK 9.2 and lower.

Comments

  1. Ewan Harris 2020-12-15

    I can repro this issue, classic code that repros the missing type property. However I'm seeing that click+singletap are fired on 9.2.2.GA also so might not be identical to the Alloy code
       const win = Ti.UI.createWindow();
       const fruitSection = Ti.UI.createListSection({
         headerTitle: 'Fruits',
         items: [{ info: {text: 'Apple'}}, { info: {text: 'Banana'}}]
       });
       const listView = Ti.UI.createListView({
           templates: { 'template': {
               childTemplates: [
                 {
                   type: 'Ti.UI.View',
                   properties: {
                     borderColor: 'red',
                     borderRadius: 1,
                     height: 50
                   },
                   events: {
                     longpress: function(e) {
                       console.log('view longpress');
                       console.log(type = ${e.type});
                       console.log(e);
                     },
                     click: function(e) {
                       console.log('view click');
                       console.log(type = ${e.type});
                       console.log(e);
                     }
                   }
                 },
                 {
                     type: 'Ti.UI.Label',
                     bindId: 'info',
                     properties: {
                         color: 'black',
                         font: { fontFamily:'Arial', fontSize: '20dp', fontWeight:'bold' },
                         left: '60dp', top: 0,
                     }
                 }
             ]
         }},
         defaultItemTemplate: 'template',
         sections: [
           fruitSection
         ]
       });
       win.add(listView);
       win.open();
       
       
  2. Rodrigo Farfán 2020-12-15

    Hmmmm... maybe I'm confused about the click+singletap on 9.2 (must check it again). Regarding classic code and longpress event, did you notice what I said about the list related properties (sectionIndex, itemIndex,...)?
  3. Rene Pot 2020-12-16

    As we've also discussed on TiSlack, I would like to point out events bound on specific UI elements in ListViews might not behave as you can expect, and any "working" behaviour in the past is not something you should be trusting. If you need to bind eventListeners on UI elements it is recommended to use TableViews. Excerpt from the ListView documentation: List view is designed for performance. One side effect of the design is that you cannot directly manipulate the views--add children, set view properties and bind event callbacks--as you can in TableView. Instead, you interact with list items indirectly, using templates and data items. The ListView does however appear to have issues with not all event properties propagating properly it seems (like bindId)
  4. Gary Mathews 2020-12-17

    master: https://github.com/appcelerator/titanium_mobile/pull/12348
  5. Samir Mohammed 2021-01-18

    FR Passed, waiting on Jenkins build.
  6. Christopher Williams 2021-01-19

    merged to master, backport for 9_3_X merged for 9.3.1 target.

JSON Source