* Support over 3 states in LayoutAdapter * Allow to inherite FloatingPanelState * Support a custome FloatingPanelState in ObjC * Replace Menu enum with UseCase enum in Samples.app * Rename UIExtensions to Extensions * Add CustomState use case in Samples app
41 lines
1.2 KiB
Swift
41 lines
1.2 KiB
Swift
// Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license.
|
|
|
|
import UIKit
|
|
|
|
protocol LayoutGuideProvider {
|
|
var topAnchor: NSLayoutYAxisAnchor { get }
|
|
var bottomAnchor: NSLayoutYAxisAnchor { get }
|
|
}
|
|
extension UILayoutGuide: LayoutGuideProvider {}
|
|
|
|
class CustomLayoutGuide: LayoutGuideProvider {
|
|
let topAnchor: NSLayoutYAxisAnchor
|
|
let bottomAnchor: NSLayoutYAxisAnchor
|
|
init(topAnchor: NSLayoutYAxisAnchor, bottomAnchor: NSLayoutYAxisAnchor) {
|
|
self.topAnchor = topAnchor
|
|
self.bottomAnchor = bottomAnchor
|
|
}
|
|
}
|
|
|
|
extension UIViewController {
|
|
var layoutInsets: UIEdgeInsets {
|
|
if #available(iOS 11.0, *) {
|
|
return view.safeAreaInsets
|
|
} else {
|
|
return UIEdgeInsets(top: topLayoutGuide.length,
|
|
left: 0.0,
|
|
bottom: bottomLayoutGuide.length,
|
|
right: 0.0)
|
|
}
|
|
}
|
|
|
|
var layoutGuide: LayoutGuideProvider {
|
|
if #available(iOS 11.0, *) {
|
|
return view!.safeAreaLayoutGuide
|
|
} else {
|
|
return CustomLayoutGuide(topAnchor: topLayoutGuide.bottomAnchor,
|
|
bottomAnchor: bottomLayoutGuide.topAnchor)
|
|
}
|
|
}
|
|
}
|