Skip to content

Commit

Permalink
Ensure textkit 1 still works on older devices
Browse files Browse the repository at this point in the history
  • Loading branch information
charliescheer committed Dec 21, 2024
1 parent 4587835 commit a7c8b23
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
6 changes: 1 addition & 5 deletions Simplenote/Classes/SPTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 22 additions & 5 deletions Simplenote/SPTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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
Expand Down

0 comments on commit a7c8b23

Please sign in to comment.