diff --git a/Simplenote/Classes/SPTextView.m b/Simplenote/Classes/SPTextView.m index f7777054b..aa9175a95 100644 --- a/Simplenote/Classes/SPTextView.m +++ b/Simplenote/Classes/SPTextView.m @@ -20,14 +20,10 @@ @implementation SPTextView - (instancetype)init { - - SPInteractiveTextStorage *textStorage = [[SPInteractiveTextStorage alloc] init]; - - NSTextContainer *container = [self setupTextContainerWith:textStorage]; + NSTextContainer *container = [self setupTextContainer]; self = [super initWithFrame:CGRectZero textContainer:container]; if (self) { - self.interactiveTextStorage = textStorage; /* Issue #188: diff --git a/Simplenote/SPTextView.swift b/Simplenote/SPTextView.swift index 6e68361c0..ca10f8d73 100644 --- a/Simplenote/SPTextView.swift +++ b/Simplenote/SPTextView.swift @@ -8,14 +8,13 @@ extension SPTextView { @objc - func setupTextContainer(with textStorage: SPInteractiveTextStorage) -> NSTextContainer { - let container = SPFallbackTextContainer(size: .zero) + func setupTextContainer() -> NSTextContainer { + let container = makeContainer() container.widthTracksTextView = true container.heightTracksTextView = true - // This value is set incase we need to fall back to text kit 1 - // - container.textView = self + let textStorage = SPInteractiveTextStorage() + interactiveTextStorage = textStorage // TextKit 2 // @@ -27,12 +26,30 @@ extension SPTextView { textLayoutManager.textContainer = container } else { + let layoutManager = NSLayoutManager() layoutManager.addTextContainer(container) textStorage.addLayoutManager(layoutManager) } return container } + + private func makeContainer() -> NSTextContainer { + var container: NSTextContainer + if #available(iOS 17.0, *) { + let fallbackContainer = SPFallbackTextContainer(size: .zero) + + // This value is set incase we need to fall back to text kit 1 + // + fallbackContainer.textView = self + + container = fallbackContainer + } else { + container = NSTextContainer() + } + + return container + } } // MARK: NSTextContentStorageDelegate