Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes compiler version checks #318

Merged
merged 2 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Example/Example/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ final class MainViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
#if compiler(>=5.7)
if #available(iOS 16, *) {
contentView.textView.isFindInteractionEnabled = true
}
#endif
contentView.textView.inputAccessoryView = toolsView
setupMenuButton()
setupTextView()
Expand All @@ -48,7 +46,6 @@ final class MainViewController: UIViewController {
}

private extension MainViewController {
#if compiler(>=5.7)
@available(iOS 16, *)
@objc private func presentFind() {
contentView.textView.findInteraction?.presentFindNavigator(showingReplace: false)
Expand All @@ -58,7 +55,6 @@ private extension MainViewController {
@objc private func presentFindAndReplace() {
contentView.textView.findInteraction?.presentFindNavigator(showingReplace: true)
}
#endif

private func setupTextView() {
var text = ""
Expand Down Expand Up @@ -89,7 +85,6 @@ private extension MainViewController {

private func makeFeaturesMenuElements() -> [UIMenuElement] {
var menuElements: [UIMenuElement] = []
#if compiler(>=5.7)
if #available(iOS 16, *) {
menuElements += [
UIMenu(options: .displayInline, children: [
Expand All @@ -102,7 +97,6 @@ private extension MainViewController {
])
]
}
#endif
menuElements += [
UIAction(title: "Go to Line") { [weak self] _ in
self?.presentGoToLineAlert()
Expand Down
2 changes: 0 additions & 2 deletions Sources/Runestone/TextView/Appearance/DefaultTheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public final class DefaultTheme: Runestone.Theme {
}
}

#if compiler(>=5.7)
@available(iOS 16.0, *)
public func highlightedRange(forFoundTextRange foundTextRange: NSRange, ofStyle style: UITextSearchFoundTextStyle) -> HighlightedRange? {
switch style {
Expand All @@ -83,7 +82,6 @@ public final class DefaultTheme: Runestone.Theme {
return nil
}
}
#endif
}

private extension UIColor {
Expand Down
4 changes: 0 additions & 4 deletions Sources/Runestone/TextView/Appearance/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public protocol Theme: AnyObject {
///
/// See <doc:CreatingATheme> for more information on higlight names.
func shadow(for highlightName: String) -> NSShadow?
#if compiler(>=5.7)
/// Highlighted range for a text range matching a search query.
///
/// This function is called when highlighting a search result that was found using the standard find/replace interaction enabled using <doc:TextView/isFindInteractionEnabled>.
Expand All @@ -63,7 +62,6 @@ public protocol Theme: AnyObject {
/// - Returns: The object used for highlighting the provided text range, or `nil` if the range should not be highlighted.
@available(iOS 16, *)
func highlightedRange(forFoundTextRange foundTextRange: NSRange, ofStyle style: UITextSearchFoundTextStyle) -> HighlightedRange?
#endif
}

public extension Theme {
Expand Down Expand Up @@ -91,7 +89,6 @@ public extension Theme {
nil
}

#if compiler(>=5.7)
@available(iOS 16, *)
func highlightedRange(forFoundTextRange foundTextRange: NSRange, ofStyle style: UITextSearchFoundTextStyle) -> HighlightedRange? {
switch style {
Expand All @@ -105,5 +102,4 @@ public extension Theme {
return nil
}
}
#endif
}
14 changes: 0 additions & 14 deletions Sources/Runestone/TextView/Core/EditMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,25 @@ protocol EditMenuControllerDelegate: AnyObject {
final class EditMenuController: NSObject {
weak var delegate: EditMenuControllerDelegate?

#if compiler(>=5.7)
@available(iOS 16, *)
private var editMenuInteraction: UIEditMenuInteraction? {
_editMenuInteraction as? UIEditMenuInteraction
}
private var _editMenuInteraction: Any?
#endif

func setupEditMenu(in view: UIView) {
#if compiler(>=5.7)
if #available(iOS 16, *) {
setupEditMenuInteraction(in: view)
} else {
setupMenuController()
}
#else
setupMenuController()
#endif
}

func presentEditMenu(from view: UIView, forTextIn range: NSRange) {
let startCaretRect = caretRect(at: range.location)
let endCaretRect = caretRect(at: range.location + range.length)
let menuWidth = min(endCaretRect.maxX - startCaretRect.minX, view.frame.width)
let menuRect = CGRect(x: startCaretRect.minX, y: startCaretRect.minY, width: menuWidth, height: startCaretRect.height)
#if compiler(>=5.7)
if #available(iOS 16, *) {
let point = CGPoint(x: menuRect.midX, y: menuRect.minY)
let configuration = UIEditMenuConfiguration(identifier: nil, sourcePoint: point)
Expand All @@ -45,9 +38,6 @@ final class EditMenuController: NSObject {
} else {
UIMenuController.shared.showMenu(from: view, rect: menuRect)
}
#else
UIMenuController.shared.showMenu(from: view, rect: menuRect)
#endif
}

func editMenu(for textRange: UITextRange, suggestedActions: [UIMenuElement]) -> UIMenu? {
Expand All @@ -59,14 +49,12 @@ final class EditMenuController: NSObject {
}

private extension EditMenuController {
#if compiler(>=5.7)
@available(iOS 16, *)
private func setupEditMenuInteraction(in view: UIView) {
let editMenuInteraction = UIEditMenuInteraction(delegate: self)
_editMenuInteraction = editMenuInteraction
view.addInteraction(editMenuInteraction)
}
#endif

private func setupMenuController() {
// This is not necessary starting from iOS 16.
Expand Down Expand Up @@ -100,7 +88,6 @@ private extension EditMenuController {
}
}

#if compiler(>=5.7)
@available(iOS 16, *)
extension EditMenuController: UIEditMenuInteractionDelegate {
func editMenuInteraction(_ interaction: UIEditMenuInteraction,
Expand All @@ -113,4 +100,3 @@ extension EditMenuController: UIEditMenuInteractionDelegate {
}
}
}
#endif
4 changes: 0 additions & 4 deletions Sources/Runestone/TextView/Core/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ open class TextView: UIScrollView {
}
/// When enabled the text view will present a menu with actions actions such as Copy and Replace after navigating to a highlighted range.
public var showMenuAfterNavigatingToHighlightedRange = true
#if compiler(>=5.7)
/// A boolean value that enables a text view’s built-in find interaction.
///
/// After enabling the find interaction, use [`presentFindNavigator(showingReplace:)`](https://developer.apple.com/documentation/uikit/uifindinteraction/3975832-presentfindnavigator) on <doc:findInteraction> to present the find navigator.
Expand All @@ -586,18 +585,15 @@ open class TextView: UIScrollView {
public var findInteraction: UIFindInteraction? {
textSearchingHelper.findInteraction
}
#endif

private let textInputView: TextInputView
private let editableTextInteraction = UITextInteraction(for: .editable)
private let nonEditableTextInteraction = UITextInteraction(for: .nonEditable)
#if compiler(>=5.7)
@available(iOS 16.0, *)
private var editMenuInteraction: UIEditMenuInteraction? {
_editMenuInteraction as? UIEditMenuInteraction
}
private var _editMenuInteraction: Any?
#endif
private let tapGestureRecognizer = QuickTapGestureRecognizer()
private var _inputAccessoryView: UIView?
private let _inputAssistantItem = UITextInputAssistantItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import UIKit

final class UITextSearchingHelper: NSObject {
weak var textView: TextView?
#if compiler(>=5.7)
var isFindInteractionEnabled = false {
didSet {
if isFindInteractionEnabled != oldValue {
Expand All @@ -17,22 +16,19 @@ final class UITextSearchingHelper: NSObject {
@available(iOS 16, *)
var findInteraction: UIFindInteraction? {
get {
// swiftlint:disable implicit_return
guard let _findInteraction = _findInteraction else {
return nil
}
guard let findInteraction = _findInteraction as? UIFindInteraction else {
fatalError("Expected _findInteraction to be of type \(UIFindInteraction.self)")
}
return findInteraction
// swiftlint:enable implicit_return
}
set {
_findInteraction = newValue
}
}
private var _findInteraction: Any?
#endif

private let queue = OperationQueue()
private var _textView: TextView {
Expand All @@ -54,7 +50,6 @@ final class UITextSearchingHelper: NSObject {
}
}

#if compiler(>=5.7)
@available(iOS 16, *)
extension UITextSearchingHelper: UITextSearching {
var supportsTextReplacement: Bool {
Expand Down Expand Up @@ -201,4 +196,3 @@ private extension SearchQuery.MatchMethod {
}
}
}
#endif