unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.94k stars 724 forks source link

[Gallery][Android] NavigationView does not close when selecting an item #5039

Closed jeromelaban closed 3 years ago

jeromelaban commented 3 years ago

Current behavior

The NavigationView pane does not close when selecting an item.

Expected behavior

The NavigationView pane should close.

Environment

https://dev.azure.com/uno-platform/Uno%20Platform/_build/results?buildId=23968&view=results

Xiaoy312 commented 3 years ago
clicking the already selected item doesnt close the pane, this is same on UWP
the actually failure only occurs in "wide mode"
    ^ need a 1080x800 tablet for this
    the pane never closes after clicking any item, selected or not
        ^ we can force close it with: nv.ItemInvoked += (s, e) => nv.IsPaneOpen = false;

NavView
    DisplayMode: NavigationViewDisplayMode.Expanded
    ExpandedModeThresholdWidth: 720

callstack when nav-view closes while not in "wide mode" (DisplayMode=Minimal)
    Windows.UI.Xaml.Controls.NavigationView.OnSplitViewPaneClosed at C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\NavigationView\NavigationView.cs:712,4
    Windows.UI.Xaml.Controls.SplitView.UpdateVisualStates at C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\SplitView\SplitView.cs:397,5
    Windows.UI.Xaml.Controls.SplitView.<SetNeedsUpdateVisualStates>b__96_0 at C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\SplitView\SplitView.cs:418,6
    ^ it is unclear why this path is not taken for "wide mode" (Expanded)
Xiaoy312 commented 3 years ago

The same issue is present in muxc::NavigationView as well. And, the same workaround still works.

Xiaoy312 commented 3 years ago

update: OK, so here is the real problem: Both the old (Windows...) and new (Microsoft...) .UI.Xaml.ControlsNavigationView uses SplitView in its template. And, the default android style of SplitView from Uno.Material uses BindableDrawerLayout as its control and the latter binds on SplitView.IsPaneOpen for opening/closing.

This BindableDrawerLayout essentially functions like a SplitView in Minimal mode. So, on device where screen width < 720, this works nicely. However, on device that exceeds this threshold, the NavView would be using the Expanded mode and SplitView using the CompactInline mode. This means the pane would normally be always opened, and pushes the content to the side, instead of overlaying on top of it. However, the SplitView using the BindableDrawerLayout implementation does not support this behavior.