Skip to content

fix(dev): open the Android dev menu in apps with an AppCompat theme - #948

Open
malopezr7 wants to merge 1 commit into
margelo:mainfrom
malopezr7:fix/dev-sheet-appcompat-theme
Open

malopezr7 wants to merge 1 commit into
margelo:mainfrom
malopezr7:fix/dev-sheet-appcompat-theme

Conversation

@malopezr7

Copy link
Copy Markdown
Contributor

Opening the dev menu crashes an Android app whose Activity theme is not a Material theme, for example Theme.AppCompat.DayNight.NoActionBar:

java.lang.ClassCastException: android.graphics.drawable.ColorDrawable cannot be cast to com.google.android.material.shape.MaterialShapeDrawable
	at com.margelo.nitro.dev.DevSheet$special$$inlined$doOnNextLayout$1.onLayoutChange(View.kt:53)
	...
	at com.google.android.material.bottomsheet.BottomSheetBehavior.onLayoutChild(BottomSheetBehavior.java:638)

BottomSheetDialog(activity) takes its theme from the Activity theme's bottomSheetDialogTheme. AppCompat themes don't set it, so Material falls back to Theme.Design.Light.BottomSheetDialog, whose sheet style has no shape appearance and a ?android:attr/colorBackground background. The sheet's background is then a ColorDrawable, and the cast in DevSheet throws. The 0.0.1-alpha.16 release notes say apps with a compatible AppCompat theme can keep it.

This builds the dialog on a ContextThemeWrapper with Theme.Material3.DayNight.NoActionBar, as HybridNavigationTabs does for its tab bar. DevSheet sets its own fill color and corners, and DevStyle only reads night mode, so the menu's content looks the same. Apps with a MaterialComponents theme or their own bottomSheetDialogTheme now get the Material 3 sheet animation and insets for this menu.

ModalSheet in nitro-ui-navigation casts the sheet background the same way. I haven't reproduced it there, so it isn't changed here.

Verification

Pixel 9 emulator, Android 37, example app connected to the dev server, menu opened with m. With the example's theme switched to Theme.AppCompat.DayNight.NoActionBar (not part of this PR):

  • main: the process dies with the trace above.
  • This branch: the menu opens with rounded top corners in light and dark mode, and logcat has no fatal exception.

With the example's own Theme.Material3.DayNight.NoActionBar, screenshots of the open menu on main and on this branch show no pixel below the status bar that differs by more than 16/255, in light and dark mode. I only ran the AppCompat and Material 3 themes.

./gradlew :runtime:testDebugUnitTest and bun run android --build-only --abi arm64-v8a pass. I didn't run it on Android versions below 37; the theme is the one the tab bar already uses. bun run typecheck fails in packages/bundler/test/inlinePlatform.test.ts, which this PR doesn't touch.

BottomSheetDialog takes its sheet style from the theme's
bottomSheetDialogTheme. An AppCompat theme doesn't set it, so Material
falls back to a sheet with a plain color background, and the cast to
MaterialShapeDrawable in DevSheet throws when the sheet is laid out.
Build the dialog on Material 3, as the tab bar already does.
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

@malopezr7 is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant