Skip to content

Commit

Permalink
Fix everything up for RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen committed May 23, 2023
1 parent 67d5fca commit 2d600de
Show file tree
Hide file tree
Showing 4 changed files with 490 additions and 87 deletions.
63 changes: 11 additions & 52 deletions ShanedlerSamples/Library/Common/HostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,20 @@ namespace Maui.FixesAndWorkarounds
{
public static partial class HostExtensions
{
public static MauiAppBuilder ConfigureInputTransparentFixes(this MauiAppBuilder builder)
public static MauiAppBuilder ConfigureRTLFixes(this MauiAppBuilder builder)
{
builder.ConfigureMauiHandlers(_ =>
builder.ConfigureMauiHandlers(handlers =>
{
ViewHandler.ViewMapper.ModifyMapping(nameof(ViewHandler.ContainerView), (handler, view, action) =>
{
action.Invoke(handler, view);
#if ANDROID
if (handler.ContainerView is Microsoft.Maui.Platform.WrapperView wrapper)
wrapper.InputTransparent = false;
#endif
});
ViewHandler.ViewMapper.ModifyMapping(nameof(IView.InputTransparent), (handler, view, action) =>
{
action.Invoke(handler, view);
#if WINDOWS
if (handler.PlatformView is Microsoft.Maui.Platform.LayoutPanel lp)
{
lp.IsHitTestVisible = true;
}
#endif
if (handler is ILayoutHandler && view is Microsoft.Maui.ILayout)
{
}
else
{
VisualElement.ControlsVisualElementMapper.UpdateProperty(handler, view, nameof(IView.InputTransparent));
}
});
ViewHandler.ViewMapper.ModifyMapping(nameof(Layout.CascadeInputTransparent), (handler, view, action) =>
{
action.Invoke(handler, view);
#if WINDOWS
if (handler.PlatformView is Microsoft.Maui.Platform.LayoutPanel lp)
{
lp.IsHitTestVisible = true;
}
#if IOS || MACCATALYST
handlers.AddHandler(typeof(Microsoft.Maui.ILayout), typeof(CustomLayoutHandler));
handlers.AddHandler(typeof(Layout), typeof(CustomLayoutHandler));
handlers.AddHandler(typeof(Page), typeof(CustomPageHandler));
handlers.AddHandler(typeof(ContentView), typeof(CustomContentViewHandler));
handlers.AddHandler(typeof(Button), typeof(CustomButtonViewHandler));

Check failure on line 22 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomButtonViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 22 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomButtonViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 22 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomButtonViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 22 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomButtonViewHandler' could not be found (are you missing a using directive or an assembly reference?)
handlers.AddHandler(typeof(Label), typeof(CustomLabelViewHandler));

Check failure on line 23 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomLabelViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomLabelViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomLabelViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomLabelViewHandler' could not be found (are you missing a using directive or an assembly reference?)
handlers.AddHandler(typeof(Entry), typeof(CustomEntryViewHandler));

Check failure on line 24 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomEntryViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 24 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / build-plugin-ci

The type or namespace name 'CustomEntryViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 24 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomEntryViewHandler' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 24 in ShanedlerSamples/Library/Common/HostExtensions.cs

View workflow job for this annotation

GitHub Actions / release-nuget

The type or namespace name 'CustomEntryViewHandler' could not be found (are you missing a using directive or an assembly reference?)
#endif
if (handler is ILayoutHandler && view is Microsoft.Maui.ILayout)
{
}
else
{
VisualElement.ControlsVisualElementMapper.UpdateProperty(handler, view, nameof(Layout.CascadeInputTransparent));
}
});
});

return builder;
}

Expand All @@ -88,12 +47,12 @@ public static MauiAppBuilder ConfigureMauiWorkarounds(this MauiAppBuilder builde

if (addAllWorkaround)
{
builder.ConfigureInputTransparentFixes();
builder.ConfigureShellWorkarounds();
builder.ConfigureTabbedPageWorkarounds();
builder.ConfigureEntryNextWorkaround();
builder.ConfigureKeyboardAutoScroll();
builder.ConfigureFlyoutPageWorkarounds();
builder.ConfigureRTLFixes();
#if ANDROID
builder.ConfigureEntryFocusOpensKeyboard();
#endif
Expand Down
20 changes: 13 additions & 7 deletions ShanedlerSamples/Library/Common/ViewExtensions.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal static void ChangeFocusedView(this UIView view, UIView? newView)
internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, double widthConstraint, double heightConstraint)
{
var virtualView = viewHandler.VirtualView;
var platformView = (viewHandler as IPlatformViewHandler)?.ContainerView
var platformView = (viewHandler as IPlatformViewHandler)?.ContainerView
?? (viewHandler as IPlatformViewHandler)?.PlatformView;

if (platformView == null || virtualView == null)
Expand Down Expand Up @@ -227,21 +227,26 @@ internal static Size GetDesiredSizeFromHandler(this IViewHandler viewHandler, do

internal static void PlatformArrangeHandler(this IViewHandler viewHandler, Rect rect)
{
var pHandler = (IPlatformViewHandler)viewHandler;
var platformView = pHandler.ContainerView ?? pHandler.PlatformView;
var platformView = (viewHandler.ContainerView ?? viewHandler.PlatformView) as UIView;

if (platformView == null)
return;

var centerX = rect.Center.X;
var boundsX = (double)platformView.Bounds.X;
var destinationWidth = rect.Width;

var parent = platformView.Superview;
if (parent?.EffectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.RightToLeft)
{
// We'll need to adjust the center point to reflect the RTL layout
centerX = parent.Bounds.Right - rect.Center.X;
boundsX = boundsX - (rect.Center.X - centerX);
// Find the center of the parent
var parentCenter = parent.Bounds.Right - (parent.Bounds.Width / 2);

// Figure out how far the center of the destination rect is from the center of the parent
var distanceFromParentCenter = parentCenter - centerX;

// Mirror the center to the other side of the center of the parent
centerX = centerX + (distanceFromParentCenter * 2);
}

// We set Center and Bounds rather than Frame because Frame is undefined if the CALayer's transform is
Expand All @@ -250,7 +255,8 @@ internal static void PlatformArrangeHandler(this IViewHandler viewHandler, Rect

// The position of Bounds is usually (0,0), but in some cases (e.g., UIScrollView) it's the content offset.
// So just leave it whatever value iOS thinks it should be (adjusted for RTL if appropriate)
platformView.Bounds = new CGRect(boundsX, platformView.Bounds.Y, rect.Width, rect.Height);
var leftEdge = centerX - (destinationWidth / 2);
platformView.Bounds = new CGRect(leftEdge, platformView.Bounds.Y, destinationWidth, rect.Height);

viewHandler.Invoke(nameof(IView.Frame), rect);
}
Expand Down
Loading

0 comments on commit 2d600de

Please sign in to comment.