Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Fix deprecation warnings #118

Merged
merged 6 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

## Tempura unreleased

- Remove `UIView.universalSafeAreaInsets` in favor of `UIView.safeAreaInsets`. [#118](https://github.com/BendingSpoons/tempura-swift/pull/118)
- Make TempuraTesting build on Xcode 12.5 [#111](https://github.com/BendingSpoons/tempura-swift/pull/111)
- Remove deprecated `dispatch` and `unsafeDispatch` for `NavigationSideEffect` on `AnyStore` and `AnySideEffectContext`. Katana's normal dispatch accepting `Dispatchable`s should be used instead. [#114](https://github.com/BendingSpoons/tempura-swift/pull/114)
- Remove `__unsafeDispatch` and `__unsafeAwaitDispatch` for `NavigationSideEffect` on `ViewController`. The base methods accepting `Dispatchable`s should be used instead. [#114](https://github.com/BendingSpoons/tempura-swift/pull/114)
Expand Down
2 changes: 1 addition & 1 deletion Tempura/Sources/Core/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ import Foundation
/// }
/// ```

public protocol View: class {
public protocol View: AnyObject {
/// The setup phase should execute only once when the `View` is created,
/// here you tipically want to create and add all the children views as subviews.
func setup()
Expand Down
48 changes: 0 additions & 48 deletions Tempura/Sources/Core/ViewControllerModellableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,51 +65,3 @@ public extension ViewControllerModellableView {
}
}
}

/// Implementation of iOS 11 safeAreaInsets accessible even to older iOS versions.
/// see also https://developer.apple.com/documentation/uikit/uiview/positioning_content_relative_to_the_safe_area
public extension UIView {
/// Implementation of safeAreaInsets in order to be accessible even to older iOS versions.
var universalSafeAreaInsets: UIEdgeInsets {
if #available(iOS 11.0, *) {
return self.safeAreaInsets
} else {
return self.legacyIOSSafeAreaInsets
}
}

private var legacyIOSSafeAreaInsets: UIEdgeInsets {
guard let vc = self.recursiveViewController else {
return .zero
}
let rootView: UIView! = vc.view
var top = vc.topLayoutGuide.length
var bottom = vc.bottomLayoutGuide.length
// the safe area expressed in rootView coordinates
let rootViewSafeAreaFrame = CGRect(x: 0, y: top, width: rootView.bounds.width, height: rootView.bounds.height - top - bottom)
// convert the rootViewSafeAreaFrame in self coordinates
let convertedFrame = rootView.convert(rootViewSafeAreaFrame, to: self)
// find the portion of safe area that intersects with self.bounds
let intersectionFrame = self.bounds.intersection(convertedFrame)
top = intersectionFrame.minY
bottom = self.bounds.maxY - intersectionFrame.maxY

return UIEdgeInsets(
top: top,
left: 0,
bottom: bottom,
right: 0
)
}

/// Traverse up the hierarchy to find the first UIViewController
private var recursiveViewController: UIViewController? {
if let modellableView = self as? AnyViewControllerModellableView {
return modellableView.viewController
}
if let parent = self.superview {
return parent.recursiveViewController
}
return nil
}
}
4 changes: 2 additions & 2 deletions Tempura/Sources/Navigation/Navigator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,12 @@ extension UIApplication {
}

/// Defines a way to inspect a UIViewController asking for the next visible UIViewController in the visible stack.
public protocol CustomRouteInspectables: class {
public protocol CustomRouteInspectables: AnyObject {
/// Next view controllers to be inspected by the router
var nextRouteControllers: [UIViewController] { get }
}

public protocol RouteInspectable: class {
public protocol RouteInspectable: AnyObject {
/// Next view controller to be inspected by the router
var nextRouteController: UIViewController? { get }
}
Expand Down
2 changes: 1 addition & 1 deletion Tempura/Sources/Navigation/Routable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public typealias RoutingCompletion = () -> ()
/// }
/// }
/// ```
public protocol Routable: class {
public protocol Routable: AnyObject {
/// The identifier associated to this Routable.
/// ```swift
/// extension TodoListViewController: Routable {
Expand Down