Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27779] Android: Setting "labels" via TabbedBar "click" event hangs app

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2020-08-11T15:04:56.000+0000
Affected Version/sRelease 8.0.0
Fix Version/sRelease 9.1.0
ComponentsAndroid
Labelsandroid, hang, tabbedbar
ReporterTony Lau
AssigneeRiduanul Islam
Created2019-12-10T06:32:33.000+0000
Updated2020-08-11T15:04:56.000+0000

Description

*Steps to reproduce:*

Build and run the below code on Android.

Tap on one of the tabs.

Notice that the app hangs.

var window = Ti.UI.createWindow();
var tabbedBar = Ti.UI.createTabbedBar();
tabbedBar.labels = ["One", "Two", "Three"];
tabbedBar.addEventListener("click", function() {
	console.log(new Date() + " tbrSortTLby Click event triggerred");
	tabbedBar.labels = ['Three', 'Four', 'Five'];
});
window.add(tabbedBar);
window.open();
*Cause:* Setting the "labels" property causes the "click" event to be fired. So, setting "labels" within a "click" event listener will cause infinite recursion to occur which will eventually cause a crash. *Work-Around:* Defer setting the "labels" property via setTimeout() within the "click" listener.

Attachments

FileDateSize
AndroidSandBox.zip2019-12-28T09:22:31.000+00008669614
AndroidTabbedBarTrace.log2019-12-28T09:20:52.000+0000334019
Trace log pic.png2019-12-24T15:39:48.000+000045075

Comments

  1. Riduanul Islam 2019-12-20

    Hi, I've tested this issue in 3 different pattern but failed to reproduce this. Can you try this below code and help us to reproduce this:
       var window = Ti.UI.createWindow();
       var tabbedBar = Ti.UI.createTabbedBar();
       tabbedBar.labels = ["One", "Two", "Three"];
       window.add(tabbedBar);
       window.open();
       
    If you have another reproducible steps, let us know the full steps with code, also provide us the full log from command line. My Testing environments are following:
       Operating System
         Name                        = Mac OS X
         Version                     = 10.14.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       
       Node.js
         Node.js Version             = 8.9.4
         npm Version                 = 6.5.0
       
       Titanium CLI
         CLI Version                 = 5.2.2
       
       Titanium SDK
         SDK Version                 = 8.3.0.GA
       Device: Samsung Galaxy J7, android version-8.1.0
       Targeting Android SDK API: 29
       
  2. Tony Lau 2019-12-23

    The crash occur after the Window is opened with the tabbed bar displayed, and then try to change the labels in code. tabbedBar.labels = ["Four", "Five", "Six"];
  3. Riduanul Islam 2019-12-24

    Hi Tony Lau, Can you share complete trace log with us? See this image below for details information: !Trace log pic.png|thumbnail! Thanks.
  4. Tony Lau 2019-12-28

    I created a new project AndroidSandBox and able to reproduce the repeat "click" issue. index.html index.js function tbrSortTLbyClicked() { Ti.API.debug(new Date() + " tbrSortTLby Click event triggerred"); $.tbrSortTLby.labels = ['Three','Four','Five']; }; $.index.open(); index.tss ".container": { backgroundColor:"white" } "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000" } "#label": { font: { fontSize: 12 } } '#sortlistbar': { top: '10%', bottom: '0%', height: '6%', width: '98%', } '#tbrSortTLby': { left: 0, width: '85%', font: { fontSize: '18dip' }, height:Ti.UI.FILL, right: '5%' }
  5. Tony Lau 2019-12-28

    Click on any of the labels. e.g "One", the labels cahnged to "Four", "Five" and "Six" as expected but the trace log showed the click event is continuously triggered. Detail trace log and project code attached. [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 6 lines [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : zygote: Do partial code cache collection, code=29KB, data=22KB [INFO] : zygote: After code cache collection, code=29KB, data=22KB [INFO] : zygote: Increasing code cache capacity to 128KB [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 1 line [DEBUG] : Sat Dec 28 2019 01:01:19 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 7 lines [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 6 lines [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : zygote: Do partial code cache collection, code=61KB, data=42KB [INFO] : zygote: After code cache collection, code=61KB, data=42KB [INFO] : zygote: Increasing code cache capacity to 256KB [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 35 lines [DEBUG] : Sat Dec 28 2019 01:01:20 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:21 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 26 lines [DEBUG] : Sat Dec 28 2019 01:01:21 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:21 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:21 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 25 lines [DEBUG] : Sat Dec 28 2019 01:01:21 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:22 GMT-0800 (PST) tbrSortTLby Click event triggerred [INFO] : chatty: uid=10088(u0_a88) com.mysandbox.android identical 43 lines [DEBUG] : Sat Dec 28 2019 01:01:22 GMT-0800 (PST) tbrSortTLby Click event triggerred [DEBUG] : Sat Dec 28 2019 01:01:22 GMT-0800 (PST) tbrSortTLby Click event triggerred
  6. Tony Lau 2020-02-17

    Need more info? Hope this can be fixed in SDK 9
  7. Michael Gangolf 2020-02-23

    Since you are setting new labels inside the click event I think it will trigger the event again because it is selecting the first new value. Chaging it to this:
       var changed = false;
       
       function tbrSortTLbyClicked() {
       	if (!changed) {
       		$.tbrSortTLby.removeEventListener("click", tbrSortTLbyClicked);
       		console.log(new Date() + " tbrSortTLby Click event triggerred");
       		$.tbrSortTLby.labels = ['Three', 'Four', 'Five'];
       		$.tbrSortTLby.addEventListener("click", tbrSortTLbyClicked);
       		changed = true;
       	} else {
       
       	}
       }
       
       
       $.index.open();
       
    will remove the event listener, change the labels and add it again. No loop. Also added a "changed" variable so you will be able to select one of the new values inside the new labels. When the bar is created it will first set the values and then attach the select-listener: https://github.com/appcelerator/titanium_mobile/blob/0558c28b54dfb195d7a5c22851060e416e9811f8/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java#L86-L87 when you change the values now the listener is catching the select event and that will trigger the click: https://github.com/appcelerator/titanium_mobile/blob/0558c28b54dfb195d7a5c22851060e416e9811f8/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUITabbedBar.java#L325-L345 So you have to remove the click event before changing the value or you could do that inside the SDK when setting new labels.
  8. Michael Gangolf 2020-02-23

    PR: https://github.com/appcelerator/titanium_mobile/pull/11495 classic test code:
       var window = Ti.UI.createWindow();
       var tabbedBar = Ti.UI.createTabbedBar();
       tabbedBar.labels = ["One", "Two", "Three"];
       tabbedBar.addEventListener("click", function() {
       	console.log(new Date() + " tbrSortTLby Click event triggerred");
       	tabbedBar.labels = ['Three', 'Four', 'Five'];
       })
       window.add(tabbedBar);
       window.open();
       
  9. Samir Mohammed 2020-03-27

    FR passed, waiting on Jenkins build.
  10. Samir Mohammed 2020-07-22

    Looks like this will need a back port for 9_1_X now.
  11. Joshua Quick 2020-07-22

    PR (9.1.x): https://github.com/appcelerator/titanium_mobile/pull/11838
  12. Christopher Williams 2020-07-23

    merged PRs to master and 9_1_X. Manually cherry-picked to 9_3_X
  13. Samir Mohammed 2020-08-11

    *Closing ticket*. Bug Fixed in SDK version 9.1.0.v20200810120239, 9.2.0.v20200810085310 and 9.3.0.v20200810090511. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11495 https://github.com/appcelerator/titanium_mobile/pull/11838

JSON Source