Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5979] iOS 12 - TabGroup.activeTab.openWindow opens window blank

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionNeeds more info
Resolution Date2018-12-02T09:50:41.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsios
ReporterDavid Bankier
AssigneeShak Hossain
Created2018-10-17T06:32:52.000+0000
Updated2018-12-02T09:50:41.000+0000

Description

When using TabGroup.activeTab.openWindow the windows that opens sometimes does not appear. The sample code below generally replicates the problem the first time the function is called, without the (code heavy) window, instead a black screen appears.
'use strict';
function createWindow() {
  var win = Ti.UI.createWindow();

  function getRandomColor() {
    var letters = '0123456789ABCDEF';
    var color = '#';
    for (var i = 0; i < 6; i++) {
      color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
  }
  function rand() {
    return Math.floor(Math.random() * 10);
  }
  function createRow(i) {
    var r = Ti.UI.createTableViewRow({
      backgroundColor: getRandomColor(),
      height: 50
    });
    var l = Ti.UI.createLabel({
      text: 'Loading...' + i,
      left: 0
    });
    r.add(l);
    r.go = function() {
      setTimeout(function() {
        l.text = 'Loaded ' + i;
        //r.backgroundColor = getRandomColor();
        l.animate({
          duration: 500,
          autoreverse: true,
          repeat: 5,
          left: 250
        });
      }, rand() * 200);
    };
    return r;
  }
  var rows = [];
  for (var i = 0; i < 10000; i++) {
    rows.push(createRow(i));
  }

  function createSection() {
    var s = Ti.UI.createTableViewSection();
    rows.forEach(r => {
      s.add(r);
      setTimeout(function() {
        r.go();
      }, 0);
    });
    return s;
  }

  var table = Ti.UI.createTableView({
    data: [createSection()]
  });

  win.add(table);
  return win;
}

function createTabGroup() {
  var tabs = ['blue', 'red', 'green', 'yellow'].map(function(c) {
    var win = Ti.UI.createWindow({
      backgroundColor: c,
      title: c
    });
    win.add(Ti.UI.createLabel({ text: 'I am a' + c + ' window.' }));
    win.addEventListener('click', openTab);

    var tab = Ti.UI.createTab({
      window: win,
      title: c
    });
    return tab;
  });
  var tabGroup = Ti.UI.createTabGroup({
    tabs: tabs
  });
  return tabGroup;
}
var tabGroup = createTabGroup();

let win;
function openTab() {
  //if (win) { tabGroup.activeTab.close(win); }
  win = createWindow();
  tabGroup.activeTab.open(win);
}
setInterval(openTab, 3000);

tabGroup.open();

Comments

  1. David Bankier 2018-10-17

    This can be replicated in the simulator and with or without jscore.
  2. Jan Vennemann 2018-10-17

    So i guess this is just an example to replicate the problem, right? Anyhow, the excessive use of setTimeout(func, 0) seems to be an issue. What happens under the hood is that a new thread will be created so the timer does not block on the main thread until it is triggered. You call setTimeout 10000 times every three seconds in this example. All these calls pile up until eventually it crashes somewhere in the internal thread handling of the kernel because the device cannot process all these threads fast enough. I had ~1500 threads active at the time of the crashes which is just way too much for the OS to handle. Removing the setTimeout removed the main issue for me and more windows opened after some time. However, i guess you were doing this to properly schedule the animate calls after adding a new row?
  3. David Bankier 2018-10-17

    This is just example code. The issue happens even without the interval/timeout. I am using it to save clicks and taps as it is hard to replicate. I have large apps where tapping on a menu item opens a window in this manner (without a timeout) and sometimes appears blank.
  4. Jan Vennemann 2018-10-17

    Can you provide a sample project? With the example code the app is crashing due to the massive amount of threads. On sim it's going black for a short time but then it also crashes. Are you seeing crashes too? Do you have crash reports you can share? Or will it just open a black window but keeps running?
  5. Keith Storm 2018-11-19

    I am experiencing this same issue on my apps as well. Not using any setTimeout code. Just randomly get a blank window instead of my window with tableview. The app does not crash for me, just blank window. It appears to happen more frequently on older devices. It is pretty common with iPhone 6 devices.
  6. Sharif AbuDarda 2018-11-20

    Hello [~kstorm001], Can you provide a standalone sample code that generates the issue for the older iOS device? We will lest on our end. Thanks.

JSON Source