@@ -13,6 +13,8 @@ import SwiftUI
13
13
public protocol _PlatformTextViewType : _AppKitOrUIKitRepresented , _AnyPlatformTextView {
14
14
associatedtype Label : View
15
15
16
+ var textKitVersion : _TextKitVersion { get }
17
+
16
18
var _SwiftUIX_textViewConfiguration : _TextViewConfiguration { get }
17
19
18
20
var _textEditorProxyBase : _TextEditorProxy . _Base ? { get }
@@ -46,13 +48,27 @@ public enum _AnyPlatformTextViewState {
46
48
47
49
}
48
50
51
+ /// The TextKit generation that a text view instance is using.
52
+ public enum _TextKitVersion {
53
+ case v1 // NSTextStorage + NSLayoutManager + NSTextContainer
54
+ case v2 // NSTextContentStorage + NSTextLayoutManager + NSTextContainer
55
+ }
56
+
49
57
open class _AnyPlatformTextView : AppKitOrUIKitTextView , AppKitOrUIKitTextInputDelegate {
50
58
public var representatableStateFlags : _AppKitOrUIKitRepresentableStateFlags = [ ]
51
59
public var representableCache : _AppKitOrUIKitRepresentableCache = nil
52
60
public var representableUpdater = EmptyObservableObject ( )
53
61
54
62
public let _wantsTextKit1 : Bool ?
55
63
64
+ public var isUsingTextKit2 : Bool {
65
+ ( _wantsTextKit1 ?? true ) == false
66
+ }
67
+
68
+ public var textKitVersion : _TextKitVersion {
69
+ self . isUsingTextKit2 == true ? . v2 : . v1
70
+ }
71
+
56
72
public internal( set) var _customTextStorage : NSTextStorage ?
57
73
58
74
@_spi ( Internal)
@@ -431,6 +447,28 @@ open class _PlatformTextView<Label: View>: _AnyPlatformTextView, NSLayoutManager
431
447
_lazy_observableTextCursor? . update ( )
432
448
}
433
449
450
+ @available ( iOS 16 . 0 , macOS 13 . 0 , tvOS 16 . 0 , watchOS 9 . 0 , * )
451
+ open func representableSizeThatFits(
452
+ _ proposal: ProposedViewSize ,
453
+ textViewConfiguration: _TextViewConfiguration ,
454
+ context: some _AppKitOrUIKitViewRepresentableContext
455
+ ) -> CGSize ? {
456
+ guard !representatableStateFlags. contains ( . dismantled) else {
457
+ return nil
458
+ }
459
+
460
+ let proposal = AppKitOrUIKitLayoutSizeProposal (
461
+ proposal,
462
+ fixedSize: textViewConfiguration. _fixedSize? . value
463
+ )
464
+
465
+ guard let size: CGSize = self . _sizeThatFits ( proposal: proposal) else {
466
+ return nil
467
+ }
468
+
469
+ return size
470
+ }
471
+
434
472
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
435
473
override open func layoutSubviews( ) {
436
474
super. layoutSubviews ( )
0 commit comments