Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-28189

Android: Opening TabGroup crashes when using AppCompat theme as of 9.3.0

    Details

    • Story Points:
      3
    • Sprint:
      2020 Sprint 21

      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:

      1. Create a Classic Titanium app project.
      2. Copy the below <application/> theme to project's "tiapp.xml" file.
      3. Copy the below "app.js" to the project.
      4. 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 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.

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
              Reviewer:
              Gary Mathews
              Tester:
              Samir Mohammed
            • Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                  Git Integration