@@ -14,6 +14,10 @@ open class UKModalController<VM: ModalVM>: UIViewController {
1414 /// A model that defines the appearance properties.
1515 public let model : VM
1616
17+ private var containerWidthConstraint : NSLayoutConstraint ?
18+
19+ // MARK: - Subviews
20+
1721 /// The optional header view of the modal.
1822 public var header : UIView ?
1923 /// The main body view of the modal.
@@ -154,14 +158,36 @@ open class UKModalController<VM: ModalVM>: UIViewController {
154158 greaterThanOrEqualToConstant: 80
155159 ) . isActive = true
156160
157- let containerWidthConstraint = self . container. width ( self . model. size. maxWidth) . width
158- containerWidthConstraint? . priority = . defaultHigh
161+ self . containerWidthConstraint = self . container. width ( self . model. size. maxWidth) . width
162+ self . containerWidthConstraint? . priority = . defaultHigh
159163
160- let bodyWrapperWidthConstraint = self . bodyWrapper. width ( self . model. size. maxWidth) . width
161- bodyWrapperWidthConstraint? . priority = . defaultHigh
164+ self . bodyWrapper. widthAnchor. constraint ( equalTo: self . container. widthAnchor) . isActive = true
162165
163166 self . container. centerHorizontally ( )
164167 }
168+
169+ open override func viewWillTransition(
170+ to size: CGSize ,
171+ with coordinator: any UIViewControllerTransitionCoordinator
172+ ) {
173+ self . containerWidthConstraint? . isActive = false
174+ super. viewWillTransition ( to: size, with: coordinator)
175+ }
176+
177+ open override func viewDidLayoutSubviews( ) {
178+ super. viewDidLayoutSubviews ( )
179+
180+ let availableWidth = self . view. bounds. width
181+ let requiredWidth = self . model. size. maxWidth
182+ + self . model. outerPaddings. leading
183+ + self . model. outerPaddings. trailing
184+ if availableWidth > requiredWidth {
185+ self . containerWidthConstraint? . priority = . required
186+ } else {
187+ self . containerWidthConstraint? . priority = . defaultHigh
188+ }
189+ self . containerWidthConstraint? . isActive = true
190+ }
165191}
166192
167193// MARK: - Style Helpers
0 commit comments