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
|
return UIResponder._currentFirstResponder
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func resignCurrentFirstResponder() {
|
|
||||||
if let responder = currentFirstResponder {
|
|
||||||
responder.resignFirstResponder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc internal func findFirstResponder(sender: AnyObject) {
|
@objc internal func findFirstResponder(sender: AnyObject) {
|
||||||
UIResponder._currentFirstResponder = self
|
UIResponder._currentFirstResponder = self
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -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 {
|
public func asImage() -> UIImage {
|
||||||
let renderer = UIGraphicsImageRenderer(bounds: bounds)
|
let renderer = UIGraphicsImageRenderer(bounds: bounds)
|
||||||
return renderer.image { rendererContext in
|
return renderer.image { rendererContext in
|
||||||
|
@ -5,25 +5,13 @@
|
|||||||
// Created by Maurice Parker on 4/15/19.
|
// Created by Maurice Parker on 4/15/19.
|
||||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
import UIKit
|
import UIKit
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
extension UIViewController {
|
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
|
// MARK: Error Handling
|
||||||
|
|
||||||
public func presentError(title: String, message: String, dismiss: (() -> Void)? = nil) {
|
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
|
#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