Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flyout Icon - RTL support #26737

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void SetInitialPresented()
else
UpdatePresented(((FlyoutPage)Element).IsPresented);

UpdateLeftBarButton();
UpdateBarButton();
}

public override void ViewWillLayoutSubviews()
Expand Down Expand Up @@ -219,7 +219,7 @@ public override void ViewWillTransitionToSize(CoreGraphics.CGSize toSize, IUIVie
UpdatePresented(false);
}

UpdateLeftBarButton();
UpdateBarButton();
}

void UpdatePresented(bool newValue, bool animated = false)
Expand Down Expand Up @@ -349,7 +349,7 @@ void EmptyContainers()
void HandleFlyoutPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Page.IconImageSourceProperty.PropertyName || e.PropertyName == Page.TitleProperty.PropertyName)
UpdateLeftBarButton();
UpdateBarButton();
}

void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
Expand All @@ -369,6 +369,8 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.Page.PrefersHomeIndicatorAutoHiddenProperty.PropertyName ||
e.PropertyName == PlatformConfiguration.iOSSpecific.Page.PrefersStatusBarHiddenProperty.PropertyName)
UpdatePageSpecifics();
else if (e.Is(VisualElement.FlowDirectionProperty))
UpdateBarButton();
}

void LayoutChildren(bool animated)
Expand Down Expand Up @@ -559,7 +561,7 @@ void UpdateFlyoutPageContainers()
UpdatePageSpecifics();
}

void UpdateLeftBarButton()
void UpdateBarButton()
{
var FlyoutPage = Element as FlyoutPage;
if (!(FlyoutPage?.Detail is NavigationPage))
Expand All @@ -571,7 +573,7 @@ void UpdateLeftBarButton()

UIViewController firstPage = detailRenderer?.ViewControllers.FirstOrDefault();
if (firstPage != null)
NavigationRenderer.SetFlyoutLeftBarButton(firstPage, FlyoutPage);
NavigationRenderer.SetFlyoutBarButton(firstPage, FlyoutPage, IsRTL);
}

void UpdateApplyShadow(bool value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,40 +922,53 @@ bool DidPopItem(UINavigationBar _, UINavigationItem __)
return true;
}

internal static void SetFlyoutLeftBarButton(UIViewController containerController, FlyoutPage FlyoutPage)
internal static void SetFlyoutBarButton(UIViewController containerController, FlyoutPage FlyoutPage, bool isRTL)
{
if (isRTL)
containerController.NavigationItem.LeftBarButtonItem = null;
else
containerController.NavigationItem.RightBarButtonItem = null;

if (!FlyoutPage.ShouldShowToolbarButton())
{
containerController.NavigationItem.LeftBarButtonItem = null;
containerController.NavigationItem.RightBarButtonItem = null;
return;
}


FlyoutPage.Flyout.IconImageSource.LoadImage(FlyoutPage.FindMauiContext(), result =>
{
var icon = result?.Value;
UIBarButtonItem uIBarButtonItem = null;

if (icon != null)
{
try
{
containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(icon, UIBarButtonItemStyle.Plain, OnItemTapped);
uIBarButtonItem = new UIBarButtonItem(icon, UIBarButtonItemStyle.Plain, OnItemTapped);
}
catch (Exception)
{
// Throws Exception otherwise would catch more specific exception type
}
}

if (icon == null || containerController.NavigationItem.LeftBarButtonItem == null)
if (icon == null || uIBarButtonItem == null)
{
containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(FlyoutPage.Flyout.Title, UIBarButtonItemStyle.Plain, OnItemTapped);
uIBarButtonItem = new UIBarButtonItem(FlyoutPage.Flyout.Title, UIBarButtonItemStyle.Plain, OnItemTapped);
}

if (FlyoutPage != null && !string.IsNullOrEmpty(FlyoutPage.AutomationId))
SetAutomationId(containerController.NavigationItem.LeftBarButtonItem, $"btn_{FlyoutPage.AutomationId}");
SetAutomationId(uIBarButtonItem, $"btn_{FlyoutPage.AutomationId}");

uIBarButtonItem.SetAccessibilityHint(FlyoutPage);
uIBarButtonItem.SetAccessibilityLabel(FlyoutPage);

if (isRTL)
containerController.NavigationItem.RightBarButtonItem = uIBarButtonItem;
else
containerController.NavigationItem.LeftBarButtonItem = uIBarButtonItem;

containerController.NavigationItem.LeftBarButtonItem.SetAccessibilityHint(FlyoutPage);
containerController.NavigationItem.LeftBarButtonItem.SetAccessibilityLabel(FlyoutPage);
});

void OnItemTapped(object sender, EventArgs e)
Expand Down Expand Up @@ -1481,7 +1494,7 @@ internal void UpdateLeftBarButtonItem(Page pageBeingRemoved = null)
return;
}

SetFlyoutLeftBarButton(this, n._parentFlyoutPage);
SetFlyoutBarButton(this, n._parentFlyoutPage, isRTL: false);
}


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26726.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Maui.Controls.Sample.Issues
{

[Issue(IssueTracker.Github, 26726, "Flyout Icon Positioned Incorrectly in RTL mode", PlatformAffected.iOS)]
class Issue26726 : FlyoutPage
{
public Issue26726()
{
Flyout = new ContentPage { Title = "Flyout" };
Detail = new NavigationPage(new ContentPage
{
Title = "Detail",
Content = new StackLayout
{
Children = {
new Button
{
Text = "Set RightToLeft",
Command = new Command(() => FlowDirection = FlowDirection.RightToLeft),
AutomationId = "ShowRightToLeft"
}
}
}
});
}

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue26726 : _IssuesUITest
{
public override string Issue => "Flyout Icon Positioned Incorrectly in RTL mode";

public Issue26726(TestDevice testDevice) : base(testDevice) { }

[Test]
[Category(UITestCategories.FlyoutPage)]
public void FlyoutIconShouldBeCorrectlyPositioned()
{
App.WaitForElement("ShowRightToLeft");
App.Click("ShowRightToLeft");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading