-
Notifications
You must be signed in to change notification settings - Fork 716
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
RTL support #21
Comments
Also curious about this, low priority but something we'd like to support in our app. |
@jeromelaban @MartinZikmund Any pointers on how to start working on this? Thanks! |
@Youssef1313 identifying where the RTL support is lacking would be a great start. Some of the controls do support it, either because the platform provides it by default, or because we imported code that supports it, but we're not tracking it yet. |
It should also somehow tie in with the localization infrastructure - e.g. the RTL should be enabled automatically when the current culture has |
I've tried setting |
@Youssef1313 on which platforms have you tried ? Can you post screenshots of the results as well ? |
Oh I was trying on the UWP project. I should have tried on another platform. Will re-take a look. |
Is there any update for RTL support? |
We should break this down into individual platforms and prioritize each |
Any update. This feature is very important for RTL languages and speakers |
Hello, I did some attached property that do the job maybe will give you a starting point here is the code controls that reversed are private static void ChangeDirection(UIElement element, ElementFlowDirection dir)
{
var grids = new List<Grid>();
var stackPanels = new List<StackPanel>();
var frameWorkElements = new List<FrameworkElement>();
var textBlocks = new List<TextBlock>();
var textBoxes = new List<TextBox>();
var controls = new List<Control>();
UIElementHelper.FindChildren(grids, element);
UIElementHelper.FindChildren(stackPanels, element);
UIElementHelper.FindChildren(frameWorkElements, element);
UIElementHelper.FindChildren(textBlocks, element);
UIElementHelper.FindChildren(textBoxes, element);
UIElementHelper.FindChildren(controls, element);
grids.ForEach(ReverseGridChilds);
stackPanels.ForEach(ReverseStackPanel);
frameWorkElements.ForEach(ReverseMarginsAndHorizontalAlignment);
textBoxes.ForEach(ReverseTextBoxes);
textBlocks.ForEach(ReverseTextBlock);
controls.ForEach(ReversePadding);
}
private static void ReverseGridChilds(Grid grid)
{
var childs = grid.Children;
var colCount = grid.ColumnDefinitions.Count;
var colDefs = grid.ColumnDefinitions.ToList();
colDefs = Enumerable.Reverse(colDefs).ToList();
grid.ColumnDefinitions.Clear();
foreach (var item in colDefs)
{
grid.ColumnDefinitions.Add(item);
}
if (colCount <= 0)
return;
var array = Enumerable.Range(0, colCount).ToArray();
array = Enumerable.Reverse(array).ToArray();
foreach (var item in childs)
{
var frame = item as FrameworkElement;
var colNo = Grid.GetColumn(frame);
var colSpan = Grid.GetColumnSpan(frame);
if (colNo > array.Length - 1)
continue;
int targetVale = array[colNo];
if (colSpan > 1)
{
Grid.SetColumnSpan(frame, colSpan);
int targetValue = targetVale / colSpan;
Grid.SetColumn(frame, targetValue);
}
else
{
Grid.SetColumn(frame, targetVale);
}
}
}
private static void ReverseStackPanel(StackPanel panel)
{
if (panel.Orientation != Orientation.Horizontal)
return;
var childs = panel.Children.ToArray();
childs = Enumerable.Reverse(childs).ToArray();
panel.Children.Clear();
foreach (var item in childs)
{
panel.Children.Add(item);
}
}
private static void ReverseMarginsAndHorizontalAlignment(FrameworkElement element)
{
var top = element.Margin.Top;
var bottom = element.Margin.Bottom;
var left = element.Margin.Left;
var right = element.Margin.Right;
element.Margin = new Thickness(right, top, left, bottom);
if (element.HorizontalAlignment == HorizontalAlignment.Left)
{
element.HorizontalAlignment = HorizontalAlignment.Right;
}
else if (element.HorizontalAlignment == HorizontalAlignment.Right)
{
element.HorizontalAlignment = HorizontalAlignment.Left;
}
}
private static void ReversePadding(Control element)
{
var top = element.Padding.Top;
var bottom = element.Padding.Bottom;
var left = element.Padding.Left;
var right = element.Padding.Right;
element.Padding = new Thickness(right, top, left, bottom);
}
private static void ReverseTextBoxes(TextBox textBox)
{
var alignment = textBox.TextAlignment;
var shouldNotChanged = alignment == TextAlignment.Center || alignment == TextAlignment.Justify;
if (shouldNotChanged)
return;
var isLeft = alignment == TextAlignment.Left || alignment == TextAlignment.Start;
var isRight = alignment == TextAlignment.Right || alignment == TextAlignment.End;
#if ANDROID
textBox.TextAlignment = TextAlignment.Start;
if (textBox.LayoutDirection == Android.Views.LayoutDirection.Ltr)
{
textBox.LayoutDirection = Android.Views.LayoutDirection.Rtl;
textBox.TextDirection = Android.Views.TextDirection.Rtl;
}
else
{
textBox.LayoutDirection = Android.Views.LayoutDirection.Ltr;
textBox.TextDirection = Android.Views.TextDirection.Ltr;
}
#else
if (isLeft)
{
textBox.TextAlignment = TextAlignment.Right;
}
else if (isRight)
{
textBox.TextAlignment = TextAlignment.Left;
}
#endif
}
private static void ReverseTextBlock(TextBlock text)
{
var textAlignment = text.TextAlignment;
var isLeft = textAlignment == TextAlignment.Left;
var isRight = textAlignment == TextAlignment.Right;
#if ANDROID
text.TextAlignment = TextAlignment.Start;
if (text.LayoutDirection == Android.Views.LayoutDirection.Ltr)
{
text.LayoutDirection = Android.Views.LayoutDirection.Rtl;
text.TextDirection = Android.Views.TextDirection.Rtl;
}
else
{
text.LayoutDirection = Android.Views.LayoutDirection.Ltr;
text.TextDirection = Android.Views.TextDirection.Ltr;
}
#else
if (isLeft)
{
text.TextAlignment = TextAlignment.Right;
}
else if (isRight)
{
text.TextAlignment = TextAlignment.Left;
}
#endif
}
} |
@balbarak thank you a lot! We will try to prioritize this as soon as possible! |
Thanks @balbarak. Opened #13524 to support that on Skia. There are some specific elements that shouldn't probably inherit FlowDirection
After getting #13524 merged, I'll work on getting this for other platforms plus handle the specific elements that don't inherit FlowDirection. |
* feat: Added Icon to the project * feat: Added new info about the target platform * feat: added appIcons to the sample project * fix: fixed output path for app icons * chore: removed default app icons values from appxmanifest * chore: renamed MaiuIcon > UnoIcon * feat: make sure crazy paths still works * feat: added support for wpf * chore: renamed Maui names to Uno names * chore: fixed merge * feat: Added Output on C# code * feat: Added output on targets and use it * feat: updated WinUI to use the Output property * chore: removed null as default value * chore: removed info tha isn't needed * test: updated tests to match the current API * fix: updated targets * fix: changed property to be the OS and not the TFM * fix: fixed app icon for wpf * fix: fixed images for wpf * chore: removed duplicated code * chore: clean up on DpiPath class * chore: removed duplicated ApplicationIcon property
FlowDirection is not supported yet, when do you plan to add it to support RTL in all platforms.
The text was updated successfully, but these errors were encountered: