Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28189] Android: Opening TabGroup crashes when using AppCompat theme as of 9.3.0

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2020-11-24T18:41:04.000+0000
Affected Version/sRelease 9.3.0
Fix Version/sRelease 9.3.0
ComponentsAndroid
LabelsTabGroup, android, open, regression, theme
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-10-13T00:05:51.000+0000
Updated2020-11-24T18:41:04.000+0000

Description

*Summary:* When the app is using a Theme.AppCompat derived theme, opening a TabGroup will throw an exception as of Titanium 9.3.0 stating the app needs to use Theme.MaterialComponents. It should only throw this exception when using the "badge" or "badgeColor" property. This regression was caught before release. *Steps to reproduce:*

Create a Classic Titanium app project.

Copy the below <application/> theme to project's "tiapp.xml" file.

Copy the below "app.js" to the project.

Build and run on Android.

tiapp.xml
<ti:app>
	<android xmlns:android="http://schemas.android.com/apk/res/android">
		<manifest>
			<application android:theme="@style/Theme.AppCompat"/>
		</manifest>
	</android>
</ti:app>
app.js
function createTab(title) {
	var window = Ti.UI.createWindow({ title: title });
	window.add(Ti.UI.createLabel({ text: title + " View" }));
	var tab = Ti.UI.createTab({
		title: title,
		window: window,
	});
	return tab;
}

var tabGroupSettings = {
	tabs: [createTab("Tab 1"), createTab("Tab 2"), createTab("Tab 3")],
};
if (OS_ANDROID) {
	tabGroupSettings.shiftMode = false;
	tabGroupSettings.style = Ti.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION;
}
var tabGroup = Ti.UI.createTabGroup(tabGroupSettings);
tabGroup.open();
*Result:* App crashes with the following exception...
[ERROR] TiExceptionHandler: (main) [206,322] Unable to start activity ComponentInfo{com.appcelerator.testing/org.appcelerator.titanium.TiActivity}: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler:     com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:248)
[ERROR] TiExceptionHandler:     com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:222)
[ERROR] TiExceptionHandler:     com.google.android.material.badge.BadgeDrawable.<init>(BadgeDrawable.java:361)
[ERROR] TiExceptionHandler:     com.google.android.material.badge.BadgeDrawable.createFromAttributes(BadgeDrawable.java:294)
[ERROR] TiExceptionHandler:     com.google.android.material.badge.BadgeDrawable.create(BadgeDrawable.java:262)
[ERROR] TiExceptionHandler:     com.google.android.material.bottomnavigation.BottomNavigationMenuView.getOrCreateBadge(BottomNavigationMenuView.java:647)
[ERROR] TiExceptionHandler:     com.google.android.material.bottomnavigation.BottomNavigationView.getOrCreateBadge(BottomNavigationView.java:674)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigationTabGroup.updateBadge(TiUIBottomNavigationTabGroup.java:296)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigationTabGroup.updateDrawablesAfterNewItem(TiUIBottomNavigationTabGroup.java:195)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigationTabGroup.addTabItemInController(TiUIBottomNavigationTabGroup.java:171)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.tabgroup.TiUIAbstractTabGroup.addTab(TiUIAbstractTabGroup.java:263)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigationTabGroup.addTab(TiUIBottomNavigationTabGroup.java:65)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:480)
[ERROR] TiExceptionHandler:     ti.modules.titanium.ui.TabGroupProxy.onWindowActivityCreated(TabGroupProxy.java:462)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:756)
[ERROR] TiExceptionHandler:     org.appcelerator.titanium.TiActivity.onCreate(TiActivity.java:47)
[ERROR] TiExceptionHandler:     android.app.Activity.performCreate(Activity.java:8000)
[ERROR] TiExceptionHandler:     android.app.Activity.performCreate(Activity.java:7984)
[ERROR] TiExceptionHandler:     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
[ERROR] TiExceptionHandler:     android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
[ERROR] TiExceptionHandler:     android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
[ERROR] TiExceptionHandler:     android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
[ERROR] TiExceptionHandler:     android.os.Handler.dispatchMessage(Handler.java:106)
[ERROR] TiExceptionHandler:     android.os.Looper.loop(Looper.java:223)
[ERROR] TiExceptionHandler:     android.app.ActivityThread.main(ActivityThread.java:7656)
[ERROR] TiExceptionHandler:     java.lang.reflect.Method.invoke(Native Method)
[ERROR] TiExceptionHandler:     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
[ERROR] TiExceptionHandler:     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
*Expected Result:* Should not crash if the [Tab.badge](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Tab-property-badge) property is not set. However, if the code does set this property, then this error does make sense because it can't natively work without using a Theme.MaterialComponents derived theme. So, it should only throw or log the exception when this property is assigned.

Comments

  1. Joshua Quick 2020-10-13

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12175
  2. Samir Mohammed 2020-10-21

    FR Passed, waiting on Jenkins build.
  3. Christopher Williams 2020-10-21

    merged to master for 9.3.0 target
  4. Lokesh Choudhary 2020-11-24

    Closing.

JSON Source