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

Enable backwards compatibility when compiling with Xcode 14 #329

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
4 changes: 4 additions & 0 deletions Sources/Runestone/Library/UITextInput+Helpers.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import UIKit

#if compiler(>=5.9)

@available(iOS 17, *)
extension UITextInput where Self: NSObject {
var sbs_textSelectionDisplayInteraction: UITextSelectionDisplayInteraction? {
Expand All @@ -17,3 +19,5 @@ extension UITextInput where Self: NSObject {
return interactionAssistant.value(forKey: selectionViewManagerKey) as? UITextSelectionDisplayInteraction
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import UIKit

#if compiler(>=5.9)

@available(iOS 17, *)
extension UITextSelectionDisplayInteraction {
func sbs_enableCursorBlinks() {
setValue(true, forKey: "rosruc".reversed() + "Blinks")
}
}

#endif
4 changes: 4 additions & 0 deletions Sources/Runestone/TextView/Core/TextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1234,10 +1234,12 @@ private extension TextView {
isInputAccessoryViewEnabled = true
textInputView.removeInteraction(nonEditableTextInteraction)
textInputView.addInteraction(editableTextInteraction)
#if compiler(>=5.9)
if #available(iOS 17, *) {
// Workaround a bug where the caret does not appear until the user taps again on iOS 17 (FB12622609).
textInputView.sbs_textSelectionDisplayInteraction?.isActivated = true
}
#endif
}
}

Expand Down Expand Up @@ -1390,10 +1392,12 @@ extension TextView: TextInputViewDelegate {
if !view.viewHierarchyContainsCaret && self.editableTextInteraction.view != nil {
view.removeInteraction(self.editableTextInteraction)
view.addInteraction(self.editableTextInteraction)
#if compiler(>=5.9)
if #available(iOS 17, *) {
self.textInputView.sbs_textSelectionDisplayInteraction?.isActivated = true
self.textInputView.sbs_textSelectionDisplayInteraction?.sbs_enableCursorBlinks()
}
#endif
}
}
}
Expand Down