From 0807570768b40d44d56784e0d0b3b9d11f9c7e2d Mon Sep 17 00:00:00 2001 From: RafaelKayumov Date: Tue, 30 Sep 2025 14:54:21 +0300 Subject: [PATCH] Update trait observing in notice presenter --- .../Notices/DefaultNoticePresenter.swift | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) 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 {