// // 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 } } }