diff --git a/CHANGELOG.md b/CHANGELOG.md index f5355ff..a64dfea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed an issue that could cause the calendar to programmatically scroll to a month or day to which it had previously scrolled - Fixed Storyboard support by removing the `fatalError` in `init?(coder: NSCoder)` +- Fixed an issue that could cause the calendar to layout unnecessarily due to a trait collection change notification ### Changed - Removed all deprecated code, simplifying the public API in preparation for a 2.0 release diff --git a/Sources/Public/CalendarView.swift b/Sources/Public/CalendarView.swift index da6664a..938f011 100644 --- a/Sources/Public/CalendarView.swift +++ b/Sources/Public/CalendarView.swift @@ -165,6 +165,13 @@ public final class CalendarView: UIView { public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) + + // This can be called with a different trait collection instance, even if nothing in the trait + // collection has changed (noticed from SwiftUI). We guard against this to prevent and + // unnecessary layout pass. + guard traitCollection.layoutDirection != previousTraitCollection?.layoutDirection else { + return + } setNeedsLayout() }