Skip to content

Commit 0807570

Browse files
committed
Update trait observing in notice presenter
1 parent cc8759d commit 0807570

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ private class NoticeContainerView: UIView {
348348
])
349349

350350
activateNoticeWidthIfNeeded()
351+
observeTraitChanges()
351352
}
352353

353354
required init?(coder aDecoder: NSCoder) {
@@ -359,21 +360,25 @@ private class NoticeContainerView: UIView {
359360
return noticeView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.5)
360361
}()
361362

362-
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
363-
super.traitCollectionDidChange(previousTraitCollection)
364-
365-
activateNoticeWidthIfNeeded()
366-
367-
layoutIfNeeded()
363+
private func activateNoticeWidthIfNeeded() {
364+
noticeWidthConstraint.isActive = traitCollection.horizontalSizeClass == .regular
368365
}
369366

370-
private func activateNoticeWidthIfNeeded() {
371-
let isRegularWidth = traitCollection.containsTraits(in: UITraitCollection(horizontalSizeClass: .regular))
372-
noticeWidthConstraint.isActive = isRegularWidth
367+
private func observeTraitChanges() {
368+
let traits: [UITrait] = [
369+
UITraitPreferredContentSizeCategory.self,
370+
UITraitUserInterfaceIdiom.self,
371+
UITraitVerticalSizeClass.self,
372+
UITraitHorizontalSizeClass.self
373+
]
374+
375+
registerForTraitChanges(traits) {(self: Self, _: UITraitCollection) in
376+
self.activateNoticeWidthIfNeeded()
377+
self.layoutIfNeeded()
378+
}
373379
}
374380
}
375381

376-
377382
// MARK: - UNMutableNotificationContent Notice Methods
378383
//
379384
private extension UNMutableNotificationContent {

0 commit comments

Comments
 (0)