mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-22 23:58:36 +01:00
Remove unused code from UIKitExtras.
This commit is contained in:
parent
c911a3b257
commit
f0b8b10b2d
@ -28,15 +28,8 @@ extension UIResponder {
|
||||
return UIResponder._currentFirstResponder
|
||||
}
|
||||
|
||||
public static func resignCurrentFirstResponder() {
|
||||
if let responder = currentFirstResponder {
|
||||
responder.resignFirstResponder()
|
||||
}
|
||||
}
|
||||
|
||||
@objc internal func findFirstResponder(sender: AnyObject) {
|
||||
UIResponder._currentFirstResponder = self
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -16,21 +16,8 @@ extension UIView {
|
||||
self.frame = rect
|
||||
}
|
||||
}
|
||||
|
||||
public func addChildAndPin(_ view: UIView) {
|
||||
view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(view)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
safeAreaLayoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
safeAreaLayoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
safeAreaLayoutGuide.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
])
|
||||
|
||||
}
|
||||
|
||||
public func asImage() -> UIImage {
|
||||
|
||||
public func asImage() -> UIImage {
|
||||
let renderer = UIGraphicsImageRenderer(bounds: bounds)
|
||||
return renderer.image { rendererContext in
|
||||
layer.render(in: rendererContext.cgContext)
|
||||
|
@ -5,27 +5,15 @@
|
||||
// Created by Maurice Parker on 4/15/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
extension UIViewController {
|
||||
|
||||
// MARK: Autolayout
|
||||
|
||||
public func addChildAndPinView(_ controller: UIViewController) {
|
||||
view.addChildAndPin(controller.view)
|
||||
addChild(controller)
|
||||
}
|
||||
|
||||
public func replaceChildAndPinView(_ controller: UIViewController) {
|
||||
view.subviews.forEach { $0.removeFromSuperview() }
|
||||
children.forEach { $0.removeFromParent() }
|
||||
addChildAndPinView(controller)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Error Handling
|
||||
|
||||
|
||||
public func presentError(title: String, message: String, dismiss: (() -> Void)? = nil) {
|
||||
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
||||
let dismissTitle = NSLocalizedString("OK", comment: "OK")
|
||||
@ -37,32 +25,4 @@ extension UIViewController {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: SwiftUI
|
||||
|
||||
public struct ViewControllerHolder {
|
||||
public weak var value: UIViewController?
|
||||
}
|
||||
|
||||
public struct ViewControllerKey: EnvironmentKey {
|
||||
public static var defaultValue: ViewControllerHolder { return ViewControllerHolder(value: nil ) }
|
||||
}
|
||||
|
||||
extension EnvironmentValues {
|
||||
public var viewController: UIViewController? {
|
||||
get { return self[ViewControllerKey.self].value }
|
||||
set { self[ViewControllerKey.self].value = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
extension UIViewController {
|
||||
public func present<Content: View>(style: UIModalPresentationStyle = .automatic, @ViewBuilder builder: () -> Content) {
|
||||
let controller = UIHostingController(rootView: AnyView(EmptyView()))
|
||||
controller.modalPresentationStyle = style
|
||||
controller.rootView = AnyView(
|
||||
builder().environment(\.viewController, controller)
|
||||
)
|
||||
self.present(controller, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,42 +0,0 @@
|
||||
//
|
||||
// UIViewController+.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/15/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
|
||||
extension UIWindow {
|
||||
|
||||
public var topViewController: UIViewController? {
|
||||
|
||||
var top = self.rootViewController
|
||||
while true {
|
||||
if let presented = top?.presentedViewController {
|
||||
top = presented
|
||||
} else if let nav = top as? UINavigationController {
|
||||
top = nav.visibleViewController
|
||||
} else if let tab = top as? UITabBarController {
|
||||
top = tab.selectedViewController
|
||||
} else if let split = top as? UISplitViewController {
|
||||
switch split.displayMode {
|
||||
case .allVisible:
|
||||
top = split.viewControllers.first
|
||||
case .primaryHidden:
|
||||
top = split.viewControllers.last
|
||||
default:
|
||||
top = split.viewControllers.first
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return top
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user