Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20041] iOS: Window close event not fired on NavigationWindow with ListView

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-03-16T09:58:09.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.2.0
ComponentsiOS
LabelsCommunity, ios, mainthread, sdk-5.0.2
ReporterMichiel van Eerd
AssigneePedro Enrique
Created2015-10-15T11:58:31.000+0000
Updated2016-03-16T09:58:09.000+0000

Description

When opening a new window with a ListView from within a NavigationWindow, the close event of this window sometimes get fired and sometimes won't. Example:
<Alloy>
    <NavigationWindow id="navwin" platform="ios">
        <Window id="win1" title="Red Window" backgroundColor="red">
            <Button id="button" onClick="openBlueWindow">Open Blue Window</Button>
        </Window>
    </NavigationWindow>
</Alloy>
function openBlueWindow(e) {
    var win2 = Alloy.createController('win2').getView();
    win2.addEventListener("close", function() {
      console.log("CLOSED!");
    });
    $.navwin.openWindow(win2);
}
$.navwin.open();
<Alloy>
    <Window id="win2" title="Blue Window" backgroundColor="blue">
      <ListView id="list">
          <ListSection>
              <ListItem title="List item 1"></ListItem>
              <ListItem title="List item 2"></ListItem>
              <ListItem title="List item 3"></ListItem>
          </ListSection>
      </ListView>
    </Window>
</Alloy>
function closeWindow(){
    $.win2.close();
}
When you close window 2 the expected behaviour is to see "CLOSED!" in the console, but it only randomly shows.

Comments

  1. Michiel van Eerd 2015-10-15

    Happens on iOS 9 simulator with SDK 5.0.0.GA and above. Happens on iOS 8.4 simulator on SDK 5.0.0.GA and above, so SDK 4.1.1.GA is okay on iOS 8.4.
  2. Gertjan Smits 2015-10-19

    Took me a while to figure out what went wrong, but I also have this issue, in a classic project, I prepared my testcase before I found this ticket, so I'm submitting it anyway:
       var mainWindow = Titanium.UI.createWindow({
       	backgroundColor: '#fff'
       });
       
       mainWindow.open();
       
       setTimeout(openWindow, 2500);
       
       function openWindow() {
       	var anotherWindow = Ti.UI.createWindow({
       		backgroundColor: '#fff'
       	});
       
       	var listView = Ti.UI.createListView({
       		width: Ti.UI.FILL,
       		height: Ti.UI.FILL,
       		defaultItemTemplate: 'defaultTemplate',
       		templates: {
       			'defaultTemplate': {
       				properties: {
       					width: Ti.UI.FILL,
       					height: 100
       				},
       				childTemplates: [{
       					type: 'Ti.UI.Label',
       					bindId: 'label',
       					properties: {
       						touchEnabled: false,
       						width: Ti.UI.FILL,
       						height: Ti.UI.SIZE
       					}
       				}]
       			}
       		}
       	});
       
       	listView.sections = [Ti.UI.createListSection({
       		items: [{
       			label: {
       				text: "Wow a row"
       			}
       		}, {
       			label: {
       				text: "Another row!"
       			}
       		}]
       	})];
       
       	anotherWindow.add(listView);
       
       	// handlers
       	anotherWindow.addEventListener('close', function() {
       		// this is never executed
       		Ti.API.info('- window close handler');
       	});
       
       	anotherWindow.addEventListener('open', function() {
       		Ti.API.info('- window open handler');
       	});
       
       	//
       	Ti.API.info("opening window...");
       	anotherWindow.open();
       
       	setTimeout(function() {
       		Ti.API.info("calling close...");
       		anotherWindow.close();
       	}, 5000);
       }
       
  3. Gertjan Smits 2015-10-19

    For some reason my code in my above comment is indented kind of weird, but on a colleagues screen it looks fine, to be sure, I've put it here: [http://jsfiddle.net/GertjanSmits/fqkdw8pe/].
  4. Michiel van Eerd 2015-10-19

    Good to hear (not for you of course) I'm not the only one as I was beginning to think I did something wrong. Strange no one else noticied this before. Hopefully someone of Appcelerator picks this one up!
  5. Yoram 2015-11-24

    I have EXACTLY the same problem!! I have it on iOS and Android on my both apps. Same problem appears everywhere, devices, emulator and it's exactly as you said, on a random way. It looks like sometimes "something" is removing the "close" event listener that I attached before and it's annoying since all application is based on that. I had never that problem before SDK 5 and I'm with Titanium since SDK 1.7
  6. Michiel van Eerd 2015-11-24

    I have not experienced this on Android, but as it's random behaviour, maybe I just did not noticed it yet. I also build much of my application actions around the close event, for example do some API calls after a window is closed. So this is a VERY big bug for me too!
  7. Yoram 2015-11-24

    Same here. Lots based on that close event and YES it's s big bug for me and I don't know what to do to tweak the situation. I have a feeling it's a bug in a garbage collector or something like that because event somehow get lost :(
  8. Angel Petkov 2016-03-10

    [~michielve] Hello , could you please try the sample code provided by Gertjan , with the newest SDK which can be found [here](http://builds.appcelerator.com.s3.amazonaws.com/index.html#5_2_X). I ran the code multiple times and the event handler for the windows close is being called. If you are still having the issue after testing with the new SDK, I will investigate this further !
       var mainWindow = Titanium.UI.createWindow({
       	backgroundColor: '#fff'
       });
        
       mainWindow.open();
        
       setTimeout(openWindow, 2500);
        
       function openWindow() {
       	var anotherWindow = Ti.UI.createWindow({
       		backgroundColor: '#fff'
       	});
        
       	var listView = Ti.UI.createListView({
       		width: Ti.UI.FILL,
       		height: Ti.UI.FILL,
       		defaultItemTemplate: 'defaultTemplate',
       		templates: {
       			'defaultTemplate': {
       				properties: {
       					width: Ti.UI.FILL,
       					height: 100
       				},
       				childTemplates: [{
       					type: 'Ti.UI.Label',
       					bindId: 'label',
       					properties: {
       						touchEnabled: false,
       						width: Ti.UI.FILL,
       						height: Ti.UI.SIZE
       					}
       				}]
       			}
       		}
       	});
        
       	listView.sections = [Ti.UI.createListSection({
       		items: [{
       			label: {
       				text: "Wow a row"
       			}
       		}, {
       			label: {
       				text: "Another row!"
       			}
       		}]
       	})];
        
       	anotherWindow.add(listView);
        
       	// handlers
       	anotherWindow.addEventListener('close', function() {
       		// this is never executed
       		Ti.API.info('- window close handler');
       	});
        
       	anotherWindow.addEventListener('open', function() {
       		Ti.API.info('- window open handler');
       	});
        
       	//
       	Ti.API.info("opening window...");
       	anotherWindow.open();
        
       	setTimeout(function() {
       		Ti.API.info("calling close...");
       		anotherWindow.close();
       	}, 5000);
       }
       
  9. Hans Knöchel 2016-03-15

    Just to troubleshoot: Does this work with <run-on-main-thread>true</run-on-main-thread> enabled in the <ios/> section of your tiapp.xml? It looks very suspicious to be a main-thread issue. EDIT: Created an easy-to-run example of your original alloy-demo: https://gist.github.com/hansemannn/ab83c7730999b7ea3100 Would be very interesting to see if it works with main-thread enabled (which will be default in the 5.4.0 release)
  10. Yoram 2016-03-15

    I wanted to test your "run-on-main-thread" suggestion but before that, I tried to test it again (because SDK updated couple times since then). So, I noticed that somehow the problem is gone and all works fine now!!:) It looks like last update of SDK 5.2.0GA fix that issue. I tested on iOS emulator 9.2 (iPhone6S), SDK 5.2.0GA and it's working great now! Tested also on Genymotion emulator (for Android), SDK 5.2.0GA - Also works great now! Btw, in the title appears "*+iOS+*: Window close event not fired on NavigationWindow with ListView". I am sure the same problem was for Android as well. I tested it couple of times and *+Android had the same problem+*!
  11. Hans Knöchel 2016-03-15

    Thanks for the feedback [~mry], appreciate that! Android and iOS are developed independently, so that might have been another (already fixed) issue. Also note, that the <run-on-main-thread/> fix is not enabled by default in 5.2.0.GA. Although you can enable it and most of your code will work like a charm, it is not 100 % stable for all use-cases, yet. This will be part of the upcoming 5.4.0.GA release in a few months. We will wait for other ticket watchers to confirm that the above solution works for them and close it after that. Thanks guys!
  12. Yoram 2016-03-15

  13. Thomas Wiesen 2016-03-15

    I can also confirm that the bug seems to have been fixed with version 5.2.0.GA. :) Thanks!
  14. Hans Knöchel 2016-03-15

  15. Michiel van Eerd 2016-03-16

    I can also confirm that with iOS 9.2 + SDK 5.2.0.GA this issue seems to be resolved! Many thanks! Note: I did not do anything with run-on-main-thread, so I guess the default is used for SDK 5.2.0.GA.
  16. Hans Knöchel 2016-03-16

    Reporter and watchers confirmed that the issue is fixed with latest 5.2.0.GA

JSON Source