From c7f63a45879d70ef44414db65276a3fa8eb1912c Mon Sep 17 00:00:00 2001 From: Vlad Filyakov Date: Sat, 6 Apr 2019 00:27:02 +0000 Subject: [PATCH] Merged PR 253045: Demo - better support for RTL - UIView extension: fitIntoSuperview(...) supports usingLeadingTrailing = false (left/right-based constraints instead of leading/trailing) - DemoController: demo container is inserted into UIScrollView using left/right constraints, not leading/trailing due to bad support of RTL from UIScrollView - Demo list: added disclosure indicator Related work items: #708163 --- .../OfficeUIFabric.Demo/DemoController.swift | 3 ++- .../OfficeUIFabric.Demo/MasterViewController.swift | 1 + OfficeUIFabric/Extensions/UIView+Extensions.swift | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OfficeUIFabric.Demo/OfficeUIFabric.Demo/DemoController.swift b/OfficeUIFabric.Demo/OfficeUIFabric.Demo/DemoController.swift index 7263fff..293c07a 100644 --- a/OfficeUIFabric.Demo/OfficeUIFabric.Demo/DemoController.swift +++ b/OfficeUIFabric.Demo/OfficeUIFabric.Demo/DemoController.swift @@ -40,6 +40,7 @@ class DemoController: UIViewController { view.addSubview(scrollingContainer) scrollingContainer.fitIntoSuperview() scrollingContainer.addSubview(container) - container.fitIntoSuperview(usingConstraints: true, autoHeight: true) + // UIScrollView in RTL mode still have leading on the left side, so we cannot rely on leading/trailing-based constraints + container.fitIntoSuperview(usingConstraints: true, usingLeadingTrailing: false, autoHeight: true) } } diff --git a/OfficeUIFabric.Demo/OfficeUIFabric.Demo/MasterViewController.swift b/OfficeUIFabric.Demo/OfficeUIFabric.Demo/MasterViewController.swift index ee1724a..c7f8692 100644 --- a/OfficeUIFabric.Demo/OfficeUIFabric.Demo/MasterViewController.swift +++ b/OfficeUIFabric.Demo/OfficeUIFabric.Demo/MasterViewController.swift @@ -49,6 +49,7 @@ class MasterViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel!.text = demos[indexPath.row].title + cell.accessoryType = .disclosureIndicator return cell } } diff --git a/OfficeUIFabric/Extensions/UIView+Extensions.swift b/OfficeUIFabric/Extensions/UIView+Extensions.swift index f17cdcf..4113005 100644 --- a/OfficeUIFabric/Extensions/UIView+Extensions.swift +++ b/OfficeUIFabric/Extensions/UIView+Extensions.swift @@ -37,15 +37,23 @@ public extension UIView { } } - func fitIntoSuperview(usingConstraints: Bool = false, margins: UIEdgeInsets = .zero, autoWidth: Bool = false, autoHeight: Bool = false) { + func fitIntoSuperview(usingConstraints: Bool = false, usingLeadingTrailing: Bool = true, margins: UIEdgeInsets = .zero, autoWidth: Bool = false, autoHeight: Bool = false) { guard let superview = superview else { return } if usingConstraints { translatesAutoresizingMaskIntoConstraints = false - leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: margins.left).isActive = true + if usingLeadingTrailing { + leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: margins.left).isActive = true + } else { + leftAnchor.constraint(equalTo: superview.leftAnchor, constant: margins.left).isActive = true + } if autoWidth { - trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: -margins.right).isActive = true + if usingLeadingTrailing { + trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: -margins.right).isActive = true + } else { + rightAnchor.constraint(equalTo: superview.rightAnchor, constant: -margins.right).isActive = true + } } else { widthAnchor.constraint(equalTo: superview.widthAnchor, constant: -(margins.left + margins.right)).isActive = true }