Skip to content

Commit 666d77c

Browse files
committed
Fix #1952: Use SafeArea Autolayout Constraints when FormViewController Is Presented Modally
1 parent 523af88 commit 666d77c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Source/Core/Core.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,36 @@ open class FormViewController: UIViewController, FormViewControllerProtocol, For
458458

459459
if tableView == nil {
460460
tableView = UITableView(frame: view.bounds, style: tableViewStyle)
461-
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
462461
tableView.cellLayoutMarginsFollowReadableWidth = false
463462
}
464463
if tableView.superview == nil {
465464
view.addSubview(tableView)
466465
}
466+
/**
467+
* Fix for #1952: `UITableView.scrollRectToVisible(, animated:)` and `UITableView.scrollToRow()` don't work properly
468+
* in `keyboardWillShow()` due to, what seems to be, a bug in iOS when autoresizing mask is used for a `UIViewController` that is
469+
* presented modally as `.formSheet/.pageSheet` within a `UINavigationController`.
470+
* The check below preserves the existing behavior of using autoresizing masks in other cases.
471+
*/
472+
var useAutoresizingMask = true
473+
if #available(iOS 13, *) {
474+
if presentingViewController != nil && navigationController != nil {
475+
useAutoresizingMask = false
476+
477+
// Need to set the background color as otherwise black shows underneath the translucent navigation bar.
478+
view.backgroundColor = .systemBackground
479+
tableView.translatesAutoresizingMaskIntoConstraints = false
480+
NSLayoutConstraint.activate([
481+
tableView.topAnchor.constraint(equalTo: tableView.superview!.safeAreaLayoutGuide.topAnchor),
482+
tableView.bottomAnchor.constraint(equalTo: tableView.superview!.safeAreaLayoutGuide.bottomAnchor),
483+
tableView.leadingAnchor.constraint(equalTo: tableView.superview!.safeAreaLayoutGuide.leadingAnchor),
484+
tableView.trailingAnchor.constraint(equalTo: tableView.superview!.safeAreaLayoutGuide.trailingAnchor)
485+
])
486+
}
487+
}
488+
if useAutoresizingMask {
489+
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
490+
}
467491
if tableView.delegate == nil {
468492
tableView.delegate = self
469493
}

0 commit comments

Comments
 (0)