material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.34k stars 3.06k forks source link

[NavigationView] Horizontal system insets handling #2749

Open pubiqq opened 2 years ago

pubiqq commented 2 years ago

How is the component supposed to handle horizontal system insets? The current behavior is definitely wrong, but there is no information in the documentation about how it's supposed to be.

yaraki commented 7 months ago

Screenshot_20240226_145655

dsn5ft commented 7 months ago

NavigationView is like the menu item content that can be placed within either a side nav drawer or a bottom sheet, or it can be used independently and placed anywhere on the screen. Since NavigationView itself doesn't really know how / where it's being used, I think it shouldn't make any assumptions about left/right/top/bottom insets.

yaraki commented 7 months ago

NavigationView is like the menu item content that can be placed within either a side nav drawer or a bottom sheet, or it can be used independently and placed anywhere on the screen. Since NavigationView itself doesn't really know how / where it's being used, I think it shouldn't make any assumptions about left/right/top/bottom insets.

That's true, but DrawerLayout expects NavigationView to set layout_gravity="start" (or it crashes). Therefore, NavigationView can know that it's on the start edge.

Also, NavigationView already handles top and bottom insets. It is natural to support horizontal insets, too.

maniac103 commented 5 days ago

Also, NavigationView already handles top and bottom insets. It is natural to support horizontal insets, too.

Additionally, there's another thing: NavigationView makes it impossible to correctly handle the insets (e.g. for display cutout) by implementing a subclass (or something) because it delegates all layout to subclasses we have no control over. In the case of display cutout (and likely also in the system bar case shown above), we'd need to apply the cutout insets to NavigationMenuItemView, but I don't see a suitable entry point for applying that inset.

If I think it shouldn't make any assumptions about left/right/top/bottom insets. is the official stance (is it?), can you make any suggestions for app developers on how to approach the insets handling themselves? FWIW, the navigation drawer demo in the catalog app exhibits that issue (white circle is display cutout):

grafik

Contrary to the image above, the catalog app does handle system bars correctly though, even though it probably would be nicer to use the drawer background as system bar background:

grafik

One can use the latter solution (apply padding to the 'start' side of NavigationView) also for the cutout case, but that looks plain ugly if one has a drawer header with colored background.