diff --git a/CHANGELOG.md b/CHANGELOG.md index 9692c5d..fc54cfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.8.2 + +- Fix the `traitCollectionWithFallback` behaviour on iOS 13 to return the view's predicted traits and prior iOS 13 to respect the key window's traits before falling back to the main screen traits. + # 1.8.1 - Added signal transformations `contains(where:)` and `allSatisfy(where:)` as wrappers for boolean `reduce()` transforms. diff --git a/Flow/Info.plist b/Flow/Info.plist index a310bc0..61ecdb0 100644 --- a/Flow/Info.plist +++ b/Flow/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.8.1 + 1.8.2 CFBundleSignature ???? CFBundleVersion diff --git a/Flow/UIView+Signal.swift b/Flow/UIView+Signal.swift index 7c8c1c5..3b43ce0 100644 --- a/Flow/UIView+Signal.swift +++ b/Flow/UIView+Signal.swift @@ -42,9 +42,18 @@ public extension UIView { } public extension UITraitEnvironment { - /// Returns the current traitCollection or the screen's traitCollection if `self` has no window + /// Returns the current traitCollection. + /// + /// Prior iOS 13 (where the traitCollection is always available), there is a fallback if `self` has no window - it falls back to the app's key window traitCollection or if that's not available to the main screen's traitCollection. var traitCollectionWithFallback: UITraitCollection { - return hasWindowTraitCollection ?? UIScreen.main.traitCollection + guard #available (iOS 13, *) else { + switch self { + case let view as UIView where view.window != nil: return view.traitCollection + case let viewController as UIViewController where viewController.isViewLoaded && viewController.view?.window != nil: return viewController.traitCollection + default: return UIApplication.shared.keyWindow?.traitCollection ?? UIScreen.main.traitCollection + } + } + return self.traitCollection } } @@ -86,16 +95,6 @@ public extension UIView { } } -private extension UITraitEnvironment { - var hasWindowTraitCollection: UITraitCollection? { - switch self { - case let view as UIView where view.window != nil: return view.traitCollection - case let viewController as UIViewController where viewController.isViewLoaded && viewController.view?.window != nil: return viewController.traitCollection - default: return nil - } - } -} - private extension UIView { func signal(for keyPath: KeyPath>) -> Signal { return Signal { callback in diff --git a/FlowFramework.podspec b/FlowFramework.podspec index bd16be9..77c6dc9 100644 --- a/FlowFramework.podspec +++ b/FlowFramework.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "FlowFramework" - s.version = "1.8.1" + s.version = "1.8.2" s.module_name = "Flow" s.summary = "Working with asynchronous flows" s.description = <<-DESC diff --git a/FlowTests/Info.plist b/FlowTests/Info.plist index ba72822..77e06cb 100644 --- a/FlowTests/Info.plist +++ b/FlowTests/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 1.0 + 1.8.2 CFBundleSignature ???? CFBundleVersion