diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRecyclerAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRecyclerAdapter.cs index 912e1a407433..558f99d4c436 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRecyclerAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRecyclerAdapter.cs @@ -139,6 +139,16 @@ public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int var container = new ContainerView(parent.Context, content, MauiContext); container.MatchWidth = true; + + // In Auto or Disabled scroll modes, RecyclerView passes an EXACTLY heightMeasureSpec, + // causing items to be measured to the full RecyclerView height. + // Setting MeasureHeight = true forces UNSPECIFIED mode, allowing items to use their natural height (~48dp). + // This enables RecyclerView to detect when scrolling is needed and to create all required view holders. + if (_shellContext.Shell.FlyoutVerticalScrollMode != ScrollMode.Enabled) + { + container.MeasureHeight = true; + } + container.LayoutParameters = new LP(LP.MatchParent, LP.WrapContent); linearLayout.AddView(container); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs index 4a5ef866de94..75c19f1ffb26 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs @@ -310,6 +310,7 @@ protected virtual void UpdateFlyoutContent() _rootView.AddView(_flyoutContentView, index); UpdateContentPadding(); + UpdateVerticalScrollMode(); } @@ -932,7 +933,6 @@ public RecyclerViewContainer(Context context) : base(context) { SetClipToPadding(false); SetLayoutManager(_layoutManager = new ScrollLayoutManager(context, (int)Orientation.Vertical, false)); - SetLayoutManager(new LinearLayoutManager(context, (int)Orientation.Vertical, false)); } protected override void Dispose(bool disposing) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue32477.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue32477.cs new file mode 100644 index 000000000000..9b480c3e1fc8 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue32477.cs @@ -0,0 +1,52 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 32477, "[Android] Shell flyout does not disable scrolling when FlyoutVerticalScrollMode is set to Disabled", PlatformAffected.Android)] +public class Issue32477 : TestShell +{ + protected override void Init() + { + FlyoutVerticalScrollMode = ScrollMode.Disabled; + FlyoutBehavior = FlyoutBehavior.Locked; + var flyoutItem = new FlyoutItem + { + Title = "Menu" + }; + + // Add a ShellContent + flyoutItem.Items.Add(new ShellContent + { + Title = "Home", + ContentTemplate = new DataTemplate(typeof(Issue32477ContentPage)) + }); + + // Add FlyoutItem to the Shell + Items.Add(flyoutItem); + + // Add MenuItems (static links in flyout) + for (int i = 1; i <= 30; i++) + { + Items.Add(new MenuItem + { + Text = $"Item {i}" + }); + } + } + + class Issue32477ContentPage : ContentPage + { + public Issue32477ContentPage() + { + Content = new StackLayout + { + Children = + { + new Label + { + Text = "The flyout menu items should not be scrollable when the scroll mode is disabled." + } + } + }; + } + } + +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32477.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32477.cs new file mode 100644 index 000000000000..ec2224a6692b --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue32477.cs @@ -0,0 +1,30 @@ + +#if TEST_FAILS_ON_WINDOWS // Issue Link - https://github.com/dotnet/maui/issues/32416 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue32477 : _IssuesUITest +{ + public Issue32477(TestDevice testDevice) : base(testDevice) + { + } + public override string Issue => "[Android] Shell flyout does not disable scrolling when FlyoutVerticalScrollMode is set to Disabled"; + + [Test] + [Category(UITestCategories.FlyoutPage)] + public void VerifyFlyoutVerticalScrollModeDisabledOnAndroid() + { + App.WaitForElement("Item 1"); + + for (int i = 0; i < 5; i++) + { + App.ScrollDown("Item 5", ScrollStrategy.Gesture); + } + + App.WaitForElement("Item 1"); + } +} +#endif