Remove iOS-version-checks (#806)

This commit is contained in:
Nathan Mattes 2022-12-24 00:40:15 +01:00
parent 80c145111a
commit a51f203546
3 changed files with 13 additions and 34 deletions

View File

@ -10,14 +10,9 @@ import SwiftUI
class AltViewController: UIViewController {
private var alt: String
let label = {
if #available(iOS 16, *) {
// TODO: update code below to use TextKit 2 when dropping iOS 15 support
return UITextView(usingTextLayoutManager: false)
} else {
return UITextView()
}
return UITextView()
}()
init(alt: String, sourceView: UIView?) {
self.alt = alt
super.init(nibName: nil, bundle: nil)

View File

@ -7,7 +7,6 @@
import SwiftUI
@available(iOS 15.0, *)
struct MediaAltTextOverlay: View {
var altDescription: String?
@ -69,7 +68,6 @@ struct MediaAltTextOverlay: View {
}
}
@available(iOS 15.0, *)
struct MediaAltTextOverlay_Previews: PreviewProvider {
static var previews: some View {
MediaAltTextOverlay(altDescription: "Hello, world!")

View File

@ -73,20 +73,12 @@ public final class MediaView: UIView {
return label
}()
let _altViewController: UIViewController! = {
if #available(iOS 15.0, *) {
let vc = UIHostingController(rootView: MediaAltTextOverlay())
vc.view.backgroundColor = .clear
return vc
} else {
return nil
}
let altViewController: UIHostingController<MediaAltTextOverlay> = {
let vc = UIHostingController(rootView: MediaAltTextOverlay())
vc.view.backgroundColor = .clear
return vc
}()
@available(iOS 15.0, *)
var altViewController: UIHostingController<MediaAltTextOverlay> {
_altViewController as! UIHostingController<MediaAltTextOverlay>
}
public override init(frame: CGRect) {
super.init(frame: frame)
_init()
@ -228,9 +220,8 @@ extension MediaView {
} else {
accessibilityLabel = altDescription
}
if #available(iOS 15.0, *) {
altViewController.rootView.altDescription = altDescription
}
altViewController.rootView.altDescription = altDescription
}
private func layoutBlurhash() {
@ -262,11 +253,9 @@ extension MediaView {
}
private func layoutAlt() {
if #available(iOS 15.0, *) {
altViewController.view.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(altViewController.view)
altViewController.view.pinToParent()
}
altViewController.view.translatesAutoresizingMaskIntoConstraints = false
container.addSubview(altViewController.view)
altViewController.view.pinToParent()
}
public func prepareForReuse() {
@ -303,10 +292,7 @@ extension MediaView {
// reset container
container.removeFromSuperview()
container.removeConstraints(container.constraints)
if #available(iOS 15.0, *) {
altViewController.rootView.altDescription = nil
}
altViewController.rootView.altDescription = nil
// reset configuration
configuration = nil