         }
     }
 
+    /// The user interface direction for the FormatBar semantic content attribute.
+    ///
+    private var layoutDirection: UIUserInterfaceLayoutDirection {
+        return UIView.userInterfaceLayoutDirection(for: self.semanticContentAttribute)
+    }
+
     /// System-applied height constraint, used to resize the format bar as necessary.
     ///
     fileprivate var heightConstraint: NSLayoutConstraint? = nil
+
+    /// Overflow toggle item leading constraint when using RTL layout or nil for LTR layout
+    ///
+    var overflowToggleItemRTLLeadingConstraint: NSLayoutConstraint?
 
     // MARK: - Initializers
 

        UserDefaults.standard.set(shouldExpand, forKey: Constants.overflowExpandedUserDefaultsKey)

        formatter?.formatBar(self, didChangeOverflowState: (shouldExpand) ? .visible : .hidden)
    }

    private func setOverflowItemsVisible(_ visible: Bool, animated: Bool = true) {

            trailingAnchor = safeAreaLayoutGuide.trailingAnchor
        }

        ///Overflow toggle item

        let overflowTrailingConstraint = overflowToggleItem.trailingAnchor.constraint(equalTo: trailingAnchor)
        overflowTrailingConstraint.priority = .defaultLow

        //Create the correct `overflowLeadingConstraint` for the current layout direction.
        let overflowLeadingConstraint: NSLayoutConstraint
        switch layoutDirection {
        case .leftToRight:
            overflowLeadingConstraint = overflowToggleItem.leadingAnchor.constraint(greaterThanOrEqualTo: scrollableStackView.trailingAnchor)
        case .rightToLeft:
            overflowLeadingConstraint = NSLayoutConstraint(
                item: overflowToggleItem,
                attribute: .leading,
                relatedBy: .greaterThanOrEqual,
                toItem: scrollableStackView,
                attribute: .trailing,
                multiplier: -1,
                constant: 0
            )
            self.overflowToggleItemRTLLeadingConstraint = overflowLeadingConstraint
        }

        ///Trailing item

        let trailingItemTrailingConstraint = trailingItemContainer.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -Constants.trailingButtonMargin)
        trailingItemTrailingConstraint.priority = .defaultLow

        //Create the correct `trailingItemLeadingConstraint` for the current layout direction.
        let trailingItemLeadingConstraint: NSLayoutConstraint
        switch layoutDirection {
        case .leftToRight:
            trailingItemLeadingConstraint = trailingItemContainer.leadingAnchor.constraint(greaterThanOrEqualTo: scrollableStackView.trailingAnchor)
        case .rightToLeft:
            trailingItemLeadingConstraint = trailingItemContainer.leadingAnchor.constraint(greaterThanOrEqualTo: scrollableStackView.leadingAnchor)
        }

        NSLayoutConstraint.activate([
            overflowToggleItem.topAnchor.constraint(equalTo: topAnchor),
            overflowToggleItem.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            overflowLeadingConstraint,
            overflowTrailingConstraint
        ])

        NSLayoutConstraint.activate([
            trailingItemContainer.topAnchor.constraint(equalTo: topAnchor),
            trailingItemContainer.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor),
            trailingItemLeadingConstraint,
            trailingItemTrailingConstraint
        ])

