diff --git a/VDS/Components/Modal/ModalDialog.swift b/VDS/Components/Modal/ModalDialog.swift index ce03e88e..bf95f9bf 100644 --- a/VDS/Components/Modal/ModalDialog.swift +++ b/VDS/Components/Modal/ModalDialog.swift @@ -77,19 +77,7 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol { lazy var primaryAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self).with { $0.accessibilityLabel = "Modal" } - - // Min height for content area 136 px. Total window min height 232 px which is including top and bottom space. - private var minHeight: CGFloat = 232.0 - - // Max height is total window height. It is 70% of viewport height. - private var maxHeight: CGFloat = 0.0 - - // Default width 560 px. A maximum width is only applied to a provided width and not to the default. - private var defaultWidth: CGFloat = 560.0 - - // Max width: 70% of viewport width. - private var maxWidth: CGFloat = 0.0 - + // close button with the 48 x 48 px private var closeCrossButtonSize = 48.0 @@ -108,8 +96,6 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol { // MARK: - Constraints //-------------------------------------------------- private var contentStackViewBottomConstraint: NSLayoutConstraint? - private var heightConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Overrides @@ -118,16 +104,6 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol { open override func setup() { super.setup() - // Max Width: 70% of viewport width. - // Maximum width is only applied to a provided width and not to the default. - maxWidth = UIDevice.isIPad && !modalModel.fullScreenDialog ? UIScreen.main.bounds.size.width * (70/100): UIScreen.main.bounds.size.width - - // Max Height: Total window height 70% of viewport height. - // For Tablet: By default the model's height is dynamic and is based on the amount of content - // it contains. it can expand between a minimum and maximum height. The minimum height is determined by the minimum - // height of the content area plus the top and bottom padding. - maxHeight = UIDevice.isIPad && !modalModel.fullScreenDialog ? UIScreen.main.bounds.size.height * (70/100) : UIScreen.main.bounds.size.height - titleLabel.accessibilityTraits = .header layer.cornerRadius = 12 @@ -176,19 +152,12 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol { contentStackViewBottomConstraint = contentStackView.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor) contentStackViewBottomConstraint?.activate() - heightConstraint = heightAnchor.constraint(equalToConstant: maxHeight) - heightConstraint?.activate() - widthConstraint = widthAnchor.constraint(equalToConstant: maxWidth) - widthConstraint?.activate() } /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - maxWidth = UIDevice.isIPad && !modalModel.fullScreenDialog ? UIScreen.main.bounds.size.width * (70/100) : UIScreen.main.bounds.size.width - maxHeight = UIDevice.isIPad && !modalModel.fullScreenDialog ? UIScreen.main.bounds.size.height * (70/100) : UIScreen.main.bounds.size.height - // Update surface and background backgroundColor = backgroundColorConfiguration.getColor(self) scrollView.indicatorStyle = surface == .light ? .black : .white @@ -247,8 +216,6 @@ open class ModalDialog: View, UIScrollViewDelegate, ParentViewProtocol { contentStackView.layoutIfNeeded() scrollView.setNeedsLayout() scrollView.layoutIfNeeded() - widthConstraint?.constant = maxWidth - heightConstraint?.constant = maxHeight } /// Used to update any Accessibility properties. diff --git a/VDS/Components/Modal/ModalDialogViewController.swift b/VDS/Components/Modal/ModalDialogViewController.swift index 834a1212..8e0a2dcf 100644 --- a/VDS/Components/Modal/ModalDialogViewController.swift +++ b/VDS/Components/Modal/ModalDialogViewController.swift @@ -89,29 +89,36 @@ open class ModalDialogViewController: UIViewController, Surfaceable { view.addSubview(modalDialog) - // Activate constraints - UIDevice.isIPad ? - NSLayoutConstraint.activate([ - // Constraints for the floating modal view for Tablet. - modalDialog.centerXAnchor.constraint(equalTo: view.centerXAnchor), - modalDialog.centerYAnchor.constraint(equalTo: view.centerYAnchor), - modalDialog.leadingAnchor.constraint(greaterThanOrEqualTo: view.leadingAnchor), - modalDialog.trailingAnchor.constraint(lessThanOrEqualTo: view.trailingAnchor), - modalDialog.topAnchor.constraint(greaterThanOrEqualTo: view.topAnchor), - modalDialog.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor) - ]) : NSLayoutConstraint.activate([ - // Constraints for fullscreen modal view for Phone. - modalDialog.leadingAnchor.constraint(equalTo: view.leadingAnchor), - modalDialog.trailingAnchor.constraint(equalTo: view.trailingAnchor), - modalDialog.topAnchor.constraint(equalTo: view.topAnchor), - modalDialog.bottomAnchor.constraint(equalTo: view.bottomAnchor) - ]) } /// Used to make changes to the View based off a change events or from local properties. open func updateView() { - view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8) modalDialog.surface = surface modalDialog.modalModel = modalModel + + + // Activate constraints + modalDialog.removeConstraints() + let isFullScreen = UIDevice.isIPad && !modalModel.fullScreenDialog ? false : true + + if isFullScreen { + view.backgroundColor = modalDialog.backgroundColor + modalDialog + .pinLeading() + .pinTrailing() + modalDialog.pinTop(anchor: UIDevice.isIPad ? view.safeAreaLayoutGuide.topAnchor : view.topAnchor) + modalDialog.pinBottom(UIDevice.isIPad ? view.bottomAnchor : view.safeAreaLayoutGuide.bottomAnchor) + + } else { + view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.8) + NSLayoutConstraint.activate([ + // Constraints for the floating modal view for Tablet. + modalDialog.centerXAnchor.constraint(equalTo: view.centerXAnchor), + modalDialog.centerYAnchor.constraint(equalTo: view.centerYAnchor), + modalDialog.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.7), + modalDialog.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.7) + ]) + } + } }