Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions WooCommerce/Classes/Tools/Notices/DefaultNoticePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ private class NoticeContainerView: UIView {
])

activateNoticeWidthIfNeeded()
observeTraitChanges()
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -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 {
Expand Down
Loading