-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup using text kit 2 classes with SPTextView
- Loading branch information
1 parent
d344c21
commit 7e6befc
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// SPTextView.swift | ||
// Simplenote | ||
// | ||
// Created by Charlie Scheer on 12/19/24. | ||
// Copyright © 2024 Automattic. All rights reserved. | ||
// | ||
|
||
extension SPTextView { | ||
/* | ||
SPInteractiveTextStorage *textStorage = [[SPInteractiveTextStorage alloc] init]; | ||
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init]; | ||
|
||
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:CGSizeMake(0, CGFLOAT_MAX)]; | ||
container.widthTracksTextView = YES; | ||
container.heightTracksTextView = YES; | ||
[layoutManager addTextContainer:container]; | ||
[textStorage addLayoutManager:layoutManager]; | ||
*/ | ||
|
||
@objc | ||
func setupTextContainer(with textStorage: SPInteractiveTextStorage) -> NSTextContainer { | ||
let container = NSTextContainer(size: .zero) | ||
container.widthTracksTextView = true | ||
container.heightTracksTextView = true | ||
|
||
|
||
if #available(iOS 16.0, *) { | ||
let textLayoutManager = NSTextLayoutManager() | ||
let contentStorage = NSTextContentStorage() | ||
contentStorage.addTextLayoutManager(textLayoutManager) | ||
textLayoutManager.textContainer = container | ||
|
||
} else { | ||
layoutManager.addTextContainer(container) | ||
textStorage.addLayoutManager(layoutManager) | ||
} | ||
|
||
return container | ||
} | ||
} |