mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
3.0 KiB
Swift
90 lines
3.0 KiB
Swift
//
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension UIEdgeInsets {
|
|
public init(top: CGFloat, leading: CGFloat, bottom: CGFloat, trailing: CGFloat) {
|
|
self.init(top: top,
|
|
left: CurrentAppContext().isRTL ? trailing : leading,
|
|
bottom: bottom,
|
|
right: CurrentAppContext().isRTL ? leading : trailing)
|
|
}
|
|
}
|
|
|
|
@objc
|
|
public extension UINavigationController {
|
|
@objc
|
|
public func pushViewController(viewController: UIViewController,
|
|
animated: Bool,
|
|
completion: (() -> Void)?) {
|
|
CATransaction.begin()
|
|
CATransaction.setCompletionBlock(completion)
|
|
pushViewController(viewController, animated: animated)
|
|
CATransaction.commit()
|
|
}
|
|
|
|
@objc
|
|
public func popViewController(animated: Bool,
|
|
completion: (() -> Void)?) {
|
|
CATransaction.begin()
|
|
CATransaction.setCompletionBlock(completion)
|
|
popViewController(animated: animated)
|
|
CATransaction.commit()
|
|
}
|
|
|
|
@objc
|
|
public func popToViewController(viewController: UIViewController,
|
|
animated: Bool,
|
|
completion: (() -> Void)?) {
|
|
CATransaction.begin()
|
|
CATransaction.setCompletionBlock(completion)
|
|
self.popToViewController(viewController, animated: animated)
|
|
CATransaction.commit()
|
|
}
|
|
}
|
|
|
|
extension UIView {
|
|
public func renderAsImage() -> UIImage? {
|
|
return renderAsImage(opaque: false, scale: UIScreen.main.scale)
|
|
}
|
|
|
|
public func renderAsImage(opaque: Bool, scale: CGFloat) -> UIImage? {
|
|
if #available(iOS 10, *) {
|
|
let format = UIGraphicsImageRendererFormat()
|
|
format.scale = scale
|
|
format.opaque = opaque
|
|
let renderer = UIGraphicsImageRenderer(bounds: self.bounds,
|
|
format: format)
|
|
return renderer.image { (context) in
|
|
self.layer.render(in: context.cgContext)
|
|
}
|
|
} else {
|
|
UIGraphicsBeginImageContextWithOptions(bounds.size, opaque, scale)
|
|
if let _ = UIGraphicsGetCurrentContext() {
|
|
drawHierarchy(in: bounds, afterScreenUpdates: true)
|
|
let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
UIGraphicsEndImageContext()
|
|
return image
|
|
}
|
|
owsFailDebug("Could not create graphics context.")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
@objc
|
|
public class func spacer(withWidth width: CGFloat) -> UIView {
|
|
let view = UIView()
|
|
view.autoSetDimension(.width, toSize: width)
|
|
return view
|
|
}
|
|
|
|
@objc
|
|
public class func spacer(withHeight height: CGFloat) -> UIView {
|
|
let view = UIView()
|
|
view.autoSetDimension(.height, toSize: height)
|
|
return view
|
|
}
|
|
}
|