Comments (13)
@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.
from uno.
It should also somehow tie in with the localization infrastructure - e.g. the RTL should be enabled automatically when the current culture has CultureInfo.TextInfo.IsRightToLeft = true
from uno.
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 StackPanel
Grid
TextBox
TextBlock
FrameworkElement
Control
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
}
}
from uno.
Also curious about this, low priority but something we'd like to support in our app.
from uno.
@jeromelaban @MartinZikmund Any pointers on how to start working on this? Thanks!
from uno.
I've tried setting FlowDirection="RightToLeft"
on TextBlock
and StackPanel
, Grid
, and it seems to work correctly. Are there known specific controls that doesn't support RTL?
from uno.
@Youssef1313 on which platforms have you tried ? Can you post screenshots of the results as well ?
from uno.
Oh I was trying on the UWP project. I should have tried on another platform. Will re-take a look.
from uno.
Is there any update for RTL support?
from uno.
We should break this down into individual platforms and prioritize each
from uno.
Any update.
This feature is very important for RTL languages and speakers
from uno.
@balbarak thank you a lot! We will try to prioritize this as soon as possible!
from uno.
Thanks @balbarak.
Opened #13524 to support that on Skia.
There are some specific elements that shouldn't probably inherit FlowDirection
- Image
- WebView
- MediaPlayerElement
After getting #13524 merged, I'll work on getting this for other platforms plus handle the specific elements that don't inherit FlowDirection.
from uno.
Related Issues (20)
- [Uno.Sdk] Find a solution for NETSDK1083 different than `UseRidGraph` HOT 1
- `ItemsStackPanel` not playing well with `ItemsControl` HOT 3
- `AssertInitialWindowSize` is failing on WinUI
- [WASM] `TextBlock` `SelectAll` and `CopySelectionToClipboard`
- On iOS and android pressing the switch on main page of gallery make the page scroll HOT 1
- `InvalidateRender` unnecessarily boxes `List<T>` enumerators
- Samples list loses selection state on scrolling HOT 1
- Pixel rounding on wasm HOT 3
- Support for Tizen
- Support for tvOS
- `InteractionTracker` may not be playing nice with touch and manipulation events
- [X11] Switch from `DllImport`s to `LibraryImport`s for better performance HOT 1
- `SetOffsetsBeforeLoading` is flaky on X11
- [IR] Port recent IR changes from WinUI HOT 1
- Skia TextBox Alignment/Padding not behaving as expected HOT 2
- `RatingControl.ApplyScaleExpressionAnimation` throws exception when enabled HOT 2
- [Single Project][Windows] Colour not showing for SVG HOT 1
- GeneratePackageOnBuild ignored in Uno.Sdk HOT 1
- FeedView shows UndefinedTemplate when starting as WinAppSDK HOT 1
- Changing code and running a unit test does not build the tested project automatically
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uno.