@@ -456,14 +456,22 @@ open class FormViewController: UIViewController, FormViewControllerProtocol, For
456456 navigationAccessoryView = customNavigationAccessoryView ?? NavigationAccessoryView ( frame: CGRect ( x: 0 , y: 0 , width: view. frame. width, height: 44.0 ) )
457457 navigationAccessoryView. autoresizingMask = . flexibleWidth
458458
459+ var shouldSetupConstraints = false
459460 if tableView == nil {
460461 tableView = UITableView ( frame: view. bounds, style: tableViewStyle)
461- tableView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
462462 tableView. cellLayoutMarginsFollowReadableWidth = false
463+ shouldSetupConstraints = true
463464 }
464465 if tableView. superview == nil {
465466 view. addSubview ( tableView)
466467 }
468+ if shouldSetupConstraints {
469+ setupTableViewConstraintsIfPresented ( )
470+ }
471+ // Always set up a mask. If the UITableView uses constraints, `translatesAutoresizingMaskIntoConstraints` will
472+ // be set to false, and so the autoresizing mask will be ignored.
473+ tableView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
474+
467475 if tableView. delegate == nil {
468476 tableView. delegate = self
469477 }
@@ -739,6 +747,28 @@ open class FormViewController: UIViewController, FormViewControllerProtocol, For
739747 tableView? . endUpdates ( )
740748 }
741749
750+ /**
751+ * Fix for #1952: `UITableView.scrollRectToVisible(, animated:)` and `UITableView.scrollToRow()` don't work properly
752+ * in `keyboardWillShow()` due to, what seems to be, a bug in iOS when autoresizing mask is used for a `UIViewController` that is
753+ * presented modally as `.formSheet/.pageSheet` within a `UINavigationController`.
754+ * The check below preserves the existing behavior of using autoresizing masks in other cases.
755+ */
756+ open func setupTableViewConstraintsIfPresented( ) {
757+ if #available( iOS 13 , * ) {
758+ if presentingViewController != nil && navigationController != nil {
759+ // Need to set the background color as otherwise black shows underneath the translucent navigation bar.
760+ view. backgroundColor = . systemBackground
761+ tableView. translatesAutoresizingMaskIntoConstraints = false
762+ NSLayoutConstraint . activate ( [
763+ tableView. topAnchor. constraint ( equalTo: tableView. superview!. safeAreaLayoutGuide. topAnchor) ,
764+ tableView. bottomAnchor. constraint ( equalTo: tableView. superview!. safeAreaLayoutGuide. bottomAnchor) ,
765+ tableView. leadingAnchor. constraint ( equalTo: tableView. superview!. safeAreaLayoutGuide. leadingAnchor) ,
766+ tableView. trailingAnchor. constraint ( equalTo: tableView. superview!. safeAreaLayoutGuide. trailingAnchor)
767+ ] )
768+ }
769+ }
770+ }
771+
742772 // MARK: Private
743773
744774 var oldBottomInset : CGFloat ?
0 commit comments