From c9d9045a7f9580cd071ab647f547493f95ce28ca Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sun, 28 Apr 2019 15:44:35 -0500 Subject: [PATCH] Respond in realtime to dynamic type changes with the unread indicator --- iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift index fb9aef0c2..a86edb2b7 100644 --- a/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift +++ b/iOS/MasterFeed/Cell/MasterFeedUnreadCountView.swift @@ -14,8 +14,10 @@ class MasterFeedUnreadCountView : UIView { private let cornerRadius = 8.0 private let bgColor = UIColor.darkGray private let textColor = UIColor.white - private let textFont = UIFont.preferredFont(forTextStyle: .caption1) - private lazy var textAttributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + private var textAttributes: [NSAttributedString.Key: AnyObject] { + let textFont = UIFont.preferredFont(forTextStyle: .caption1) + return [NSAttributedString.Key.foregroundColor: textColor, NSAttributedString.Key.font: textFont, NSAttributedString.Key.kern: NSNull()] + } private var textSizeCache = [Int: CGSize]() var unreadCount = 0 { @@ -42,6 +44,12 @@ class MasterFeedUnreadCountView : UIView { self.isOpaque = false } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + textSizeCache = [Int: CGSize]() + invalidateIntrinsicContentSize() + setNeedsDisplay() + } + override var intrinsicContentSize: CGSize { if !intrinsicContentSizeIsValid { var size = CGSize.zero