Remove unused code from UIKitExtras.

This commit is contained in:
Brent Simmons 2024-03-20 22:00:02 -07:00
parent c911a3b257
commit f0b8b10b2d
4 changed files with 5 additions and 107 deletions

View File

@ -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

View File

@ -17,19 +17,6 @@ extension UIView {
}
}
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 {
let renderer = UIGraphicsImageRenderer(bounds: bounds)
return renderer.image { rendererContext in

View File

@ -5,25 +5,13 @@
// 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) {
@ -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

View File

@ -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