diff --git a/WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift b/WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift index 06261bc2b9e..11df0af8d08 100644 --- a/WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift +++ b/WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift @@ -348,6 +348,7 @@ private class NoticeContainerView: UIView { ]) activateNoticeWidthIfNeeded() + observeTraitChanges() } required init?(coder aDecoder: NSCoder) { @@ -359,21 +360,25 @@ private class NoticeContainerView: UIView { return noticeView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.5) }() - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - activateNoticeWidthIfNeeded() - - layoutIfNeeded() + private func activateNoticeWidthIfNeeded() { + noticeWidthConstraint.isActive = traitCollection.horizontalSizeClass == .regular } - private func activateNoticeWidthIfNeeded() { - let isRegularWidth = traitCollection.containsTraits(in: UITraitCollection(horizontalSizeClass: .regular)) - noticeWidthConstraint.isActive = isRegularWidth + private func observeTraitChanges() { + let traits: [UITrait] = [ + UITraitPreferredContentSizeCategory.self, + UITraitUserInterfaceIdiom.self, + UITraitVerticalSizeClass.self, + UITraitHorizontalSizeClass.self + ] + + registerForTraitChanges(traits) {(self: Self, _: UITraitCollection) in + self.activateNoticeWidthIfNeeded() + self.layoutIfNeeded() + } } } - // MARK: - UNMutableNotificationContent Notice Methods // private extension UNMutableNotificationContent {