Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23954] iOS: Events not firing from the child view if created dynamically (using run-on-mainthread)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2017-01-03T12:39:34.000+0000
Affected Version/sRelease 5.4.0, Release 5.5.0
Fix Version/sn/a
ComponentsiOS
Labelsios, run-on-main-thread
ReporterNiraj Kumar
AssigneeEric Merriman
Created2016-09-17T20:15:25.000+0000
Updated2017-03-22T21:59:27.000+0000

Description

When creating views using Alloy or Classic code of Appcelerator API dynamically and adding those views to the window or view created in other controller, which has event associated with it; the event with the parent view does not get fired when clicked on the child view. Please look into the sample app with this link: [https://www.dropbox.com/s/3x82na9nqt7l3oa/SampleApp.zip?dl=0] Appcelerator SDK: 5.4.0.GA/5.5.0.GA *Workaround*: Disable run-on-main-thread temporary.

Comments

  1. Hans Knöchel 2016-09-18

    You are adding child-views to the container and have the click-listener on the container - which never gets clicked because you click on the children, not the container. So you should rather make the click-listener on each view and delegate the event through a callback to your index-controller.
  2. Niraj Kumar 2016-09-19

    Hi Hans, Thank you for the reply. I have tried the same code using Appcelerator SDK 5.3.1.GA and earlier and that is working fine. I hope to get the same response from the later SDKs too. Also, in 5.4.0.GA, if we try by adding labels only, it works fine. The problem is with the adding views dynamically only.
  3. Niraj Kumar 2016-09-27

    Should I expect to get the solution now?
  4. Niraj Kumar 2016-09-27

    @Hans: Thanks for the reply. Can you please help me to know where can I get the patch from?
  5. Hans Knöchel 2016-09-27

    Can you see a different behavior when having run-on-main-thread enabled/disabled? it might be relate to TIMOB-23934 which was fixed on master yesterday.
  6. Niraj Kumar 2016-09-27

    When I set the value for
     run-on-main-thread 
    to true, it does not work as expected. But making it false works fine. Thanks a lot.
  7. Hans Knöchel 2016-09-27

    Test-case:
       var index = Ti.UI.createWindow({
           layout: "vertical",
           backgroundColor: "white",
       });
       var viewContainer = Ti.UI.createView({
           layout: "vertical",
           backgroundColor: "white",
       });
       
       index.add(viewContainer);
       
       // Should also be triggered by it's childs
       index.addEventListener("click", function(e) {
           alert("clicked!");
       });
       
       for (var i = 0; i < 10; i++) {
           var view = Ti.UI.createView({
               height: 40,
               backgroundColor: "red"
           });
           view.add(Ti.UI.createLabel({
               text: "Label " + i
           }));
           viewContainer.add(view);
       }
       
       index.open();
       
    As suspected, it works with run-on-main-thread disabled, but is no duplicate of TIMOB-23934. Moved to TIMOB for further investigation!
  8. Hans Knöchel 2016-09-27

    Also interesting: The bubbled click-event from "index" to "viewContainer" works, but the children of "viewContainer" don't.
  9. Dongwoo Gim 2016-12-16

    Is this going on?
  10. Hans Knöchel 2017-01-03

    Resolving as Duplicate of TIMOB-23810 for further investigation by [~vijaysingh]!
  11. Lee Morris 2017-03-22

    Closing ticket as duplicate and links to the related ticket has been provided above.

JSON Source