Skip to content

Commit a7c8b23

Browse files
committed
Ensure textkit 1 still works on older devices
1 parent 4587835 commit a7c8b23

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Simplenote/Classes/SPTextView.m

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020
@implementation SPTextView
2121

2222
- (instancetype)init {
23-
24-
SPInteractiveTextStorage *textStorage = [[SPInteractiveTextStorage alloc] init];
25-
26-
NSTextContainer *container = [self setupTextContainerWith:textStorage];
23+
NSTextContainer *container = [self setupTextContainer];
2724

2825
self = [super initWithFrame:CGRectZero textContainer:container];
2926
if (self) {
30-
self.interactiveTextStorage = textStorage;
3127

3228
/*
3329
Issue #188:

Simplenote/SPTextView.swift

+22-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
extension SPTextView {
1010
@objc
11-
func setupTextContainer(with textStorage: SPInteractiveTextStorage) -> NSTextContainer {
12-
let container = SPFallbackTextContainer(size: .zero)
11+
func setupTextContainer() -> NSTextContainer {
12+
let container = makeContainer()
1313
container.widthTracksTextView = true
1414
container.heightTracksTextView = true
1515

16-
// This value is set incase we need to fall back to text kit 1
17-
//
18-
container.textView = self
16+
let textStorage = SPInteractiveTextStorage()
17+
interactiveTextStorage = textStorage
1918

2019
// TextKit 2
2120
//
@@ -27,12 +26,30 @@ extension SPTextView {
2726
textLayoutManager.textContainer = container
2827

2928
} else {
29+
let layoutManager = NSLayoutManager()
3030
layoutManager.addTextContainer(container)
3131
textStorage.addLayoutManager(layoutManager)
3232
}
3333

3434
return container
3535
}
36+
37+
private func makeContainer() -> NSTextContainer {
38+
var container: NSTextContainer
39+
if #available(iOS 17.0, *) {
40+
let fallbackContainer = SPFallbackTextContainer(size: .zero)
41+
42+
// This value is set incase we need to fall back to text kit 1
43+
//
44+
fallbackContainer.textView = self
45+
46+
container = fallbackContainer
47+
} else {
48+
container = NSTextContainer()
49+
}
50+
51+
return container
52+
}
3653
}
3754

3855
// MARK: NSTextContentStorageDelegate

0 commit comments

Comments
 (0)