Skip to content

Commit

Permalink
Merge pull request #91 from iZettle/ios13/fix-traitCollection-signal
Browse files Browse the repository at this point in the history
Remove the traitCollection fallback on iOS 13 and bump Flow to 1.8.2
  • Loading branch information
nataliq-pp authored Jul 24, 2019
2 parents 51ba63b + 79c5a2e commit 3f93992
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Flow/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.8.1</string>
<string>1.8.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
23 changes: 11 additions & 12 deletions Flow/UIView+Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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<T>(for keyPath: KeyPath<CallbackerView, Callbacker<T>>) -> Signal<T> {
return Signal { callback in
Expand Down
2 changes: 1 addition & 1 deletion FlowFramework.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion FlowTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.8.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down

0 comments on commit 3f93992

Please sign in to comment.