From 42210a0b0fef44b2643bb4208b7a5ad433a8cb22 Mon Sep 17 00:00:00 2001 From: Matt <85322+mattmassicotte@users.noreply.github.com> Date: Thu, 28 Mar 2024 17:12:56 -0400 Subject: [PATCH] Few more availability guards --- Projects/NeonExample/TextViewController.swift | 12 +++++++++--- Sources/Neon/PlatformTextSystem.swift | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Projects/NeonExample/TextViewController.swift b/Projects/NeonExample/TextViewController.swift index fb12abb..9983105 100644 --- a/Projects/NeonExample/TextViewController.swift +++ b/Projects/NeonExample/TextViewController.swift @@ -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 diff --git a/Sources/Neon/PlatformTextSystem.swift b/Sources/Neon/PlatformTextSystem.swift index 2b833dd..f3b9e2c 100644 --- a/Sources/Neon/PlatformTextSystem.swift +++ b/Sources/Neon/PlatformTextSystem.swift @@ -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 } @@ -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