Skip to content

Commit

Permalink
Few more availability guards
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Mar 28, 2024
1 parent ed9407b commit 42210a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions Projects/NeonExample/TextViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import Neon
import NSUI

final class TextViewController: NSUIViewController {
let textView = NSUITextView(usingTextLayoutManager: false)
let highlighter: TextViewHighlighter
private let textView: NSUITextView
private let highlighter: TextViewHighlighter

init() {
if #available(iOS 16.0, *) {
self.textView = NSUITextView(usingTextLayoutManager: false)
} else {
self.textView = NSUITextView()
}

// enable non-continguous layout for TextKit 1
if textView.textLayoutManager == nil {
if #available(macOS 12.0, iOS 16.0, *), textView.textLayoutManager == nil {
#if canImport(AppKit) && !targetEnvironment(macCatalyst)
textView.layoutManager?.allowsNonContiguousLayout = true
#else
Expand Down
4 changes: 2 additions & 2 deletions Sources/Neon/PlatformTextSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension NSTextContentManager: VersionedContent {

extension NSTextContainer {
func textRange(for rect: CGRect) -> NSRange? {
if #available(macOS 12.0, *), textLayoutManager != nil {
if #available(macOS 12.0, iOS 15.0, *), textLayoutManager != nil {
return nil
}

Expand All @@ -59,7 +59,7 @@ extension NSTextContainer {
extension TextView {
var tk2VisibleTextRange: NSRange? {
guard
#available(macOS 12.0, *),
#available(macOS 12.0, iOS 16.0, *),
let textLayoutManager,
let viewportRange = textLayoutManager.textViewportLayoutController.viewportRange,
let textContentManager = textLayoutManager.textContentManager
Expand Down

0 comments on commit 42210a0

Please sign in to comment.