-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
FlowDirectionExtensions.cs
45 lines (40 loc) · 1.21 KB
/
FlowDirectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using Android.Widget;
using ALayoutDirection = Android.Views.LayoutDirection;
using ATextDirection = Android.Views.TextDirection;
using AView = Android.Views.View;
namespace Xamarin.Forms.Platform.Android
{
internal static class FlowDirectionExtensions
{
internal static FlowDirection ToFlowDirection(this ALayoutDirection direction)
{
switch (direction)
{
case ALayoutDirection.Ltr:
return FlowDirection.LeftToRight;
case ALayoutDirection.Rtl:
return FlowDirection.RightToLeft;
default:
return FlowDirection.MatchParent;
}
}
internal static void UpdateFlowDirection(this AView view, IVisualElementController controller)
{
if (view == null || controller == null || (int)Forms.SdkInt < 17)
return;
// if android:targetSdkVersion < 17 setting these has no effect
if (controller.EffectiveFlowDirection.IsRightToLeft())
{
view.LayoutDirection = ALayoutDirection.Rtl;
if (view is TextView textView)
textView.TextDirection = ATextDirection.Rtl;
}
else if (controller.EffectiveFlowDirection.IsLeftToRight())
{
view.LayoutDirection = ALayoutDirection.Ltr;
if (view is TextView textView)
textView.TextDirection = ATextDirection.Ltr;
}
}
}
}