From a27685d3be4040ca9dd004e8e600256f93014cd8 Mon Sep 17 00:00:00 2001 From: Nataliya Patsovska Date: Wed, 24 Jul 2019 16:31:53 +0200 Subject: [PATCH 1/2] Remove the traitCollection fallback on iOS 13 On iOS 13 UIKit now predicts the initial traits for a view before it's rendered so no need to return the screen's trait collection instead. Moreover, it's better to use the app's key window for determing the fallback traitCollection instead of the screen since for apps that support split screen that will be different based on the configuration chosen by the user. --- Flow/UIView+Signal.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) 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 From 79c5a2e0295c8f4dee23fdc5d40f289fe402e2d8 Mon Sep 17 00:00:00 2001 From: Nataliya Patsovska Date: Wed, 24 Jul 2019 16:39:34 +0200 Subject: [PATCH 2/2] Bump version to 1.8.2 --- CHANGELOG.md | 4 ++++ Flow/Info.plist | 2 +- FlowFramework.podspec | 2 +- FlowTests/Info.plist | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) 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/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