From 58a96d14b7749832fecf75e1be08e69eb512f0db Mon Sep 17 00:00:00 2001
From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Date: Thu, 11 May 2023 15:21:12 -0300
Subject: [PATCH] RTL: fix layout width resizing

Change-Id: I65234d22ecd1e3cb3fc6544a449ec8fc1e78aee0
GitLab: #235
---
 src/app/commoncomponents/DualPaneView.qml  | 43 +++++++++++++++-------
 src/app/commoncomponents/JamiSplitView.qml | 19 ++++++----
 2 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/src/app/commoncomponents/DualPaneView.qml b/src/app/commoncomponents/DualPaneView.qml
index fb1eaeff7..98d0073bc 100644
--- a/src/app/commoncomponents/DualPaneView.qml
+++ b/src/app/commoncomponents/DualPaneView.qml
@@ -25,6 +25,8 @@ BaseView {
     required property Item leftPaneItem
     required property Item rightPaneItem
 
+    property bool isRTL: UtilsAdapter.isRTL
+
     property alias leftPane: leftPane
     property alias rightPane: rightPane
 
@@ -33,34 +35,34 @@ BaseView {
     property real minorPaneMinWidth: JamiTheme.mainViewLeftPaneMinWidth
     property real majorPaneMinWidth: JamiTheme.mainViewPaneMinWidth
 
-    property real previousMinorPaneWidth: leftPane.width
-    property real previousMajorPaneWidth: rightPane.width
+    property real previousMinorPaneWidth: isRTL ? leftPane.width : rightPane.width
+    property real previousMajorPaneWidth: isRTL ? rightPane.width : leftPane.width
 
     property bool isSinglePane
 
     onPresented: {
         if (leftPaneItem)
-            leftPaneItem.parent = leftPane;
+            leftPaneItem.parent = leftPane
         if (rightPaneItem)
-            rightPaneItem.parent = rightPane;
-        splitView.restoreSplitViewState();
-        resolvePanes();
+            rightPaneItem.parent = rightPane
+        splitView.restoreSplitViewState()
+        resolvePanes()
     }
     onDismissed: splitView.saveSplitViewState()
 
     Component.onCompleted: {
         // Avoid double triggering this handler during instantiation.
-        onIsSinglePaneChanged.connect(isSinglePaneChangedHandler);
+        onIsSinglePaneChanged.connect(isSinglePaneChangedHandler)
     }
 
     onWidthChanged: resolvePanes()
     function resolvePanes() {
-        isSinglePane = width < majorPaneMinWidth + previousMinorPaneWidth;
+        isSinglePane = width < majorPaneMinWidth + previousMinorPaneWidth
     }
 
     // Override this if needed.
     property var isSinglePaneChangedHandler: function () {
-        rightPaneItem.parent = isSinglePane ? leftPane : rightPane;
+        rightPaneItem.parent = isSinglePane ? leftPane : rightPane
     }
 
     JamiSplitView {
@@ -83,11 +85,24 @@ BaseView {
         clip: true
         required property bool isMinorPane
         onWidthChanged: {
-            if (!isSinglePane && isMinorPane)
-                previousMinorPaneWidth = width;
+            if (!isSinglePane && ((isRTL && !isMinorPane) || (!isRTL && isMinorPane)))
+                previousMinorPaneWidth = width
+            if (!isSinglePane && ((isRTL && isMinorPane) || (!isRTL && !isMinorPane)))
+                previousMajorPaneWidth = width
         }
-        SplitView.minimumWidth: isSinglePane ? viewNode.width : (isMinorPane ? minorPaneMinWidth : majorPaneMinWidth)
-        SplitView.maximumWidth: isSinglePane ? viewNode.width : viewNode.width - (isMinorPane ? majorPaneMinWidth : minorPaneMinWidth)
-        SplitView.preferredWidth: isMinorPane ? minorPaneMinWidth : majorPaneMinWidth
+
+        Connections {
+            target: UtilsAdapter
+
+            function onIsRTLChanged() {
+                var bck = previousMinorPaneWidth
+                previousMinorPaneWidth = previousMajorPaneWidth
+                previousMajorPaneWidth = bck
+            }
+        }
+
+        SplitView.minimumWidth: isSinglePane ? viewNode.width : (isMinorPane && !isRTL ? minorPaneMinWidth : majorPaneMinWidth)
+        SplitView.maximumWidth: isSinglePane ? viewNode.width : viewNode.width - (isMinorPane && !isRTL ? majorPaneMinWidth : minorPaneMinWidth)
+        SplitView.preferredWidth: isMinorPane && !isRTL ? minorPaneMinWidth : majorPaneMinWidth
     }
 }
diff --git a/src/app/commoncomponents/JamiSplitView.qml b/src/app/commoncomponents/JamiSplitView.qml
index b30f31171..2b14024e5 100644
--- a/src/app/commoncomponents/JamiSplitView.qml
+++ b/src/app/commoncomponents/JamiSplitView.qml
@@ -24,10 +24,18 @@ SplitView {
 
     property bool isRTL: UtilsAdapter.isRTL
     property bool isSinglePane: false
-    property bool isSwapped: UtilsAdapter.isRTL
+    property bool isSwapped: false
 
-    onIsRTLChanged: swapItems()
-    onIsSinglePaneChanged: swapItems()
+    onIsRTLChanged: {
+        if (isRTL && isSinglePane && !isSwapped)
+            return
+        if ((isRTL && !isSwapped) || (!isRTL && isSwapped))
+            swapItems()
+    }
+    onIsSinglePaneChanged: {
+        if (isSwapped || isRTL)
+            swapItems()
+    }
 
     property string splitViewStateKey: objectName
     property bool autoManageState: !(parent instanceof BaseView)
@@ -49,16 +57,13 @@ SplitView {
     }
 
     function swapItems() {
-        if ((isSinglePane && !isSwapped) // Do not swap in isSinglePane mode
-            || (!isRTL && !isSwapped)) // Do not swap if not RTL
-            return;
+        isSwapped = !isSwapped
         var qqci = children[0];
         if (qqci.children.length > 1) {
             // swap the children
             var tempPane = qqci.children[0];
             qqci.children[0] = qqci.children[1];
             qqci.children.push(tempPane);
-            isSwapped = true
         }
     }
 
-- 
GitLab