Skip to content

Commit

Permalink
Use keyPath to read UIApplication.shared. (slackhq#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahselek authored Feb 12, 2020
1 parent 7f07cdf commit 1e7c053
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions PanModal/Presentable/PanModalPresentable+LayoutHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ extension PanModalPresentable where Self: UIViewController {
Gives us the safe area inset from the top.
*/
var topLayoutOffset: CGFloat {
return UIApplication.shared.keyWindow?.rootViewController?.topLayoutGuide.length ?? 0
guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else {
return 0
}
return application.keyWindow?.rootViewController?.topLayoutGuide.length ?? 0
}

/**
Length of the bottom layout guide of the presenting view controller.
Gives us the safe area inset from the bottom.
*/
var bottomLayoutOffset: CGFloat {
return UIApplication.shared.keyWindow?.rootViewController?.bottomLayoutGuide.length ?? 0
guard let application = UIApplication.value(forKeyPath: #keyPath(UIApplication.shared)) as? UIApplication else {
return 0
}
return application.keyWindow?.rootViewController?.bottomLayoutGuide.length ?? 0
}

/**
Expand Down

0 comments on commit 1e7c053

Please sign in to comment.