In Android : Reverse layout only when default layout direction is theā€¦ (#7809)
authorElashi <mohd_ashi@yahoo.com>
Tue, 22 Oct 2019 16:50:36 +0000 (19:50 +0300)
committerShane Neuville <shneuvil@microsoft.com>
Tue, 22 Oct 2019 16:50:36 +0000 (10:50 -0600)
* In Android : Reverse layout only when default layout direction is the opposite of the user settings (#7393)

* - remove ReverseLayout and just rely on LayoutDirection

* - fix formatting

Xamarin.Forms.Platform.Android/CollectionView/EdgeSnapHelper.cs
Xamarin.Forms.Platform.Android/CollectionView/ItemsViewRenderer.cs
Xamarin.Forms.Platform.Android/CollectionView/SingleSnapHelper.cs

index 4919d7e..205c6fb 100644 (file)
@@ -1,5 +1,6 @@
 using Android.Support.V7.Widget;
 using AView = Android.Views.View;
+using ALayoutDirection = Android.Views.LayoutDirection;
 
 namespace Xamarin.Forms.Platform.Android
 {
@@ -14,6 +15,9 @@ namespace Xamarin.Forms.Platform.Android
 
                protected static bool IsLayoutReversed(RecyclerView.LayoutManager layoutManager)
                {
+                       if (layoutManager.LayoutDirection == (int)(ALayoutDirection.Rtl))
+                               return true;
+
                        if (layoutManager is LinearLayoutManager linearLayoutManager)
                        {
                                return linearLayoutManager.ReverseLayout;
@@ -22,13 +26,13 @@ namespace Xamarin.Forms.Platform.Android
                        return false;
                }
 
-               protected int[] CalculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, AView targetView, 
+               protected int[] CalculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, AView targetView,
                        int direction = 1)
                {
                        var orientationHelper = CreateOrientationHelper(layoutManager);
                        var isHorizontal = layoutManager.CanScrollHorizontally();
                        var rtl = isHorizontal && IsLayoutReversed(layoutManager);
-                       
+
                        var size = orientationHelper.GetDecoratedMeasurement(targetView);
 
                        var hiddenPortion = size - VisiblePortion(targetView, orientationHelper, rtl);
@@ -50,7 +54,7 @@ namespace Xamarin.Forms.Platform.Android
                        var size = orientationHelper.GetDecoratedMeasurement(view);
 
                        var portionInViewPort = VisiblePortion(view, orientationHelper, reversed && isHorizontal);
-                       
+
                        // Is the first visible view at least halfway on screen?
                        return portionInViewPort >= size / 2;
                }
index af0acc1..89a432b 100644 (file)
@@ -536,17 +536,6 @@ namespace Xamarin.Forms.Platform.Android
                        {
                                return;
                        }
-
-                       var effectiveFlowDirection = ((IVisualElementController)Element).EffectiveFlowDirection;
-
-                       if (effectiveFlowDirection.IsRightToLeft())
-                       {
-                               linearLayoutManager.ReverseLayout = true;
-                       }
-                       else if (effectiveFlowDirection.IsLeftToRight())
-                       {
-                               linearLayoutManager.ReverseLayout = false;
-                       }
                }
 
                protected virtual int DetermineTargetPosition(ScrollToRequestEventArgs args)
index bab11a4..dc5c523 100644 (file)
@@ -1,5 +1,6 @@
 using Android.Support.V7.Widget;
 using AView = Android.Views.View;
+using ALayoutDirection = Android.Views.LayoutDirection;
 
 namespace Xamarin.Forms.Platform.Android
 {
@@ -17,6 +18,9 @@ namespace Xamarin.Forms.Platform.Android
 
                protected static bool IsLayoutReversed(RecyclerView.LayoutManager layoutManager)
                {
+                       if (layoutManager.LayoutDirection == (int)(ALayoutDirection.Rtl))
+                               return true;
+
                        if (layoutManager is LinearLayoutManager linearLayoutManager)
                        {
                                return linearLayoutManager.ReverseLayout;