iOS 18 set tab's badge
I have searched and made sure there are no existing issues for the issue I am filing
- [X] I have searched the existing issues
Description
On SDK 12.5.1.GA and iOS 18 / iPadOS 18, if you set the badge value of a Tab, it works only the fist time.
Expected Behavior
The tab must always show the correct badge (for example: tab.badge = '7' --> the badge must show '7', also if it's not the first time i've set it)
Actual behavior
The tab badge is updated only the first time
Reproducible sample
// create a tabGroup and a tab called "myTab"
var window = Ti.UI.createWindow({
title: 'My Tab'
});
var myTab = Ti.UI.createTab({
window: window,
title: 'My Tab',
icon: 'myicon.png'
});
// add myTab to the tabGroup
tabGroup.addTab(myTab);
// change tab's badge value
myTab.badge = '5';
myTab.badge = '7'; // tab badge remains '5'
// ATTENTION: I've found this workaround: if you modify (for example) the title of the tab, it works (the tab is refreshed?):
myTab.badge = '5';
myTab.badge = '7';
var tmp = myTab.title;
myTab.title = tmp + ' ';
myTab.title = tmp; // now the tab is refreshed and the badge shows '7'
Steps to reproduce
Create an app with a Tab Group. In a tab, set the badge value more than one time. See the reproducible sample.
Platform
iOS
SDK version you are using
12.5.1.GA
Alloy version you are using
No response
Hi, I've tested
var win1 = Ti.UI.createWindow();
var tab1 = Ti.UI.createTab({
window: win1,
icon: '/assets/images/tab1.png'
}),
tabGroup = Ti.UI.createTabGroup({
tabs: [tab1]
});
tab1.badge = 1;
tab1.badge = 2;
tab1.badge = 3;
tabGroup.open();
and it does show 3 for me. iOS 17 and 18.1 simulator. Android is working fine too
@gmasiero did you try my example above to verify if it is working for you too?
@gmasiero Your reproducible sample code is incomplete. How do you create and open your tab group?
I've tested with Ti 12.5.1.GA under iOS 17 & 18 and the badge was correctly updated.
Little update here as we had an report on Slack:
var win1 = Ti.UI.createWindow({
backgroundColor: 'blue',
title: 'Blue'
});
win1.add(Ti.UI.createLabel({text: 'I am a blue window.'}));
var win2 = Ti.UI.createWindow({
backgroundColor: 'red',
title: 'Red'
});
win2.add(Ti.UI.createLabel({text: 'I am a red window.'}));
var tab1 = Ti.UI.createTab({
window: win1,
title: 'Blue',
icon:"/images/appicon.png",
badge: 10
}),
tab2 = Ti.UI.createTab({
window: win2,
icon:"/images/appicon.png",
title: 'Red'
}),
tabGroup = Ti.UI.createTabGroup({
tabs: [tab1, tab2]
});
tabGroup.open();
setTimeout(function(){
tab2.badge=2;
}, 2000)
only the creation badge is visible on an iPad. The one from the timeout is only visible on iphone, not on ipad:
only the creation badge is visible on an iPad. The one from the timeout is only visible on iphone, not on ipad:
Oh, nice found. I can narrow down the issue to the floating tabbar on iPadOS 18+. The code example works fine under iOS 17, iPadOS 17 and iOS 18.
badgeValue is set correctly, but not displayed. And forcing a redraw of the tab controller doesn't have any effect.
~~A rewrite with the UITab API (iOS/iPadOS 18+) will probably be necessary :worried:~~
badgeValueis set correctly, but not displayed. And forcing a redraw of the tab controller doesn't have any effect.
That's so strange. Adding a space to the title and it will update on the iPad and it's only on ipad which is super strange. Perhaps some UI thread issue and a title change will trigger something else in the update part?
That's so strange. Adding a space to the title and it will update on the iPad and it's only on ipad which is super strange. Perhaps some UI thread issue and a title change will trigger something else in the update part?
Changing the title in general forced a update/redisplay. I suspect this is because a title change is animated in the floating tabbar under iPadOS 18+.
The actual cause was the re-creating of UITabBarItem in updateTabBarItem.
Reusing the UITabBarItem fixes the problem.
Edit: ...but raises a new issue https://github.com/tidev/titanium-sdk/pull/14324#issuecomment-3438098121.
https://github.com/user-attachments/assets/3b419f82-d857-4a5a-adcc-b27199f79334