[TIMOB-26758] Android: Changing TabbedBar properties "labels" and "index" before opening window causes a crash
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2019-04-03T09:26:38.000+0000 |
Affected Version/s | Release 8.0.0 |
Fix Version/s | Release 8.0.1 |
Components | Android |
Labels | android, engSchedule, parity, tabbedbar, tabs |
Reporter | Hans Knöchel |
Assignee | Joshua Quick |
Created | 2019-01-21T12:03:59.000+0000 |
Updated | 2019-04-03T09:26:38.000+0000 |
Description
*Summary:*
Changing
Ti.UI.TabbedBar
properties "labels" or "index" after creating the tabbed bar but before its parent window will cause a crash.
This is a parity issue. iOS allows these properties to be changed dynamically.
*Steps to reproduce:*
Build and run the below code on Android.
On app startup, notice it crashes.
var window = Ti.UI.createWindow();
var tabbedBar = Ti.UI.createTabbedBar();
tabbedBar.labels = ["One", "Two", "Three"];
tabbedBar.index = 1;
Ti.API.info("@@@ TabbedBar.index: " + tabbedBar.index);
window.add(tabbedBar);
window.open();
*Result:*
Will get the below error when setting the "labels" property.
[ERROR] TiExceptionHandler: Error: Attempt to invoke virtual method 'void ti.modules.titanium.ui.widget.TiUITabbedBar.setNewLabels()' on a null object reference
Will get the below error when setting the "index" property.
[ERROR] TiExceptionHandler: Error: Attempt to invoke virtual method 'void ti.modules.titanium.ui.widget.TiUITabbedBar.setSelectedIndex(int)' on a null object reference
*Work-Around:*
Move all property TabbedBar
property changing code to the window's open event handler.
Or avoid setting these property dynamically and assign them once via its creation properties.
var window = Ti.UI.createWindow();
var tabbedBar = Ti.UI.createTabbedBar({
labels: ["One", "Two", "Three"],
index: 1,
});
window.add(tabbedBar);
window.open();
Attachments
File | Date | Size |
---|---|---|
20190320_113615_2.mp4 | 2019-03-20T10:44:57.000+0000 | 4597403 |
I can reproduce this issue with the below code.
Thanks for bringing this issue to our attention. We'll look into it.
PR (master): https://github.com/appcelerator/titanium_mobile/pull/10646
Is there a chance to get this customer-prio bumped into 8.0.0? We need this for our production app and want to prevent curating a custom SDK.
PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10655
[~hknoechel], out of curiosity, is there a reason why you can't set the labels/index via the
TabbedBar
creation properties? That would work-around the problem.We have quite complex use cases where the index is adjusted based on user defaults (e.g. private vs shared expenses). Other use cases require the tabbed bar to change on runtime, e.g to change it's selection based on a certain state change. The only workaround for that would be to remove and re-add the whole tabbedbar, resulting in a flickering.
[~jquick] Can you please present a working workaround for this? The priority is only "medium" and severity "minor", which is not correct. This makes tabbed-bars in real apps useless, since no change of state (= index) can be applied after creation. This blocks our current Android beta version in which we already need to jump from one workaround to another, which is really frustrating already.
I think dynamically setting the
TabbedBar
"labels" and "index" properties via the window's "open" event is the best work-around for the moment.Alternatively, you can add methods to the
TabbedBar
prototype like the below and update the properties via the initial "postlayout" event.What do you think? *_Edit:_* _I tried to override the prototype's "index" and "labels" properties via
Object.defineProperty()
, but these properties appear to be non-configurable when defined on the C++ side. I can't override them._Unfortunately that is no suitable workaround for us. We need to change the properties after the user does certain actions, so the open event is too early.
FR Passed: Waiting on Jenkins builds.
As described on GitHub, this causes bad glitches in our app once the activity containing this feature is reopened. A video is attached (private scope). After checking this further, it seems to cause an infinite loop (likely because different to iOS), setting the index causes a change event which triggers it again. *EDIT*: I could isolate it to the "click" event being fired too many times. I still need to compare the concrete behavior with iOS, but it definitely should not fire if: - the tabbed-bar was just created - the tabs change - a click against a tab that is already selected is done
[~hknoechel], I'm not sure how to reproduce your issue. I tested it with the below and it did *NOT* get stuck in an infinite loop.
*Closing ticket* Fix verified in SDK Version
8.0.1.v20190402094527
and SDK Version8.1.0.v20190402113644
Test and other information can be found at: PR (master): https://github.com/appcelerator/titanium_mobile/pull/10646 PR (8.0.x): https://github.com/appcelerator/titanium_mobile/pull/10655 [~hknoechel] Feel free to reopen the ticket if you are still experiencing issues with steps on how to reproduce the issue.