Skip to content

Commit 169e13e

Browse files
committed
Update package
1 parent 880b3a4 commit 169e13e

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

Sources/SwiftUIX/Intramodular/Text/_PlatformTextView.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import SwiftUI
1313
public protocol _PlatformTextViewType: _AppKitOrUIKitRepresented, _AnyPlatformTextView {
1414
associatedtype Label: View
1515

16+
var textKitVersion: _TextKitVersion { get }
17+
1618
var _SwiftUIX_textViewConfiguration: _TextViewConfiguration { get }
1719

1820
var _textEditorProxyBase: _TextEditorProxy._Base? { get }
@@ -46,13 +48,27 @@ public enum _AnyPlatformTextViewState {
4648

4749
}
4850

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+
4957
open class _AnyPlatformTextView: AppKitOrUIKitTextView, AppKitOrUIKitTextInputDelegate {
5058
public var representatableStateFlags: _AppKitOrUIKitRepresentableStateFlags = []
5159
public var representableCache: _AppKitOrUIKitRepresentableCache = nil
5260
public var representableUpdater = EmptyObservableObject()
5361

5462
public let _wantsTextKit1: Bool?
5563

64+
public var isUsingTextKit2: Bool {
65+
(_wantsTextKit1 ?? true) == false
66+
}
67+
68+
public var textKitVersion: _TextKitVersion {
69+
self.isUsingTextKit2 == true ? .v2 : .v1
70+
}
71+
5672
public internal(set) var _customTextStorage: NSTextStorage?
5773

5874
@_spi(Internal)
@@ -431,6 +447,28 @@ open class _PlatformTextView<Label: View>: _AnyPlatformTextView, NSLayoutManager
431447
_lazy_observableTextCursor?.update()
432448
}
433449

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+
434472
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
435473
override open func layoutSubviews() {
436474
super.layoutSubviews()

Sources/SwiftUIX/Intramodular/Text/_TextView-Sizing.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@ extension _TextView {
2020
return nil // TODO: Implement sizing for custom text views as well
2121
}
2222

23-
guard !view.representatableStateFlags.contains(.dismantled) else {
24-
return nil
25-
}
26-
27-
let proposal = AppKitOrUIKitLayoutSizeProposal(
23+
return view.representableSizeThatFits(
2824
proposal,
29-
fixedSize: resolvedTextViewConfiguration._fixedSize?.value
25+
textViewConfiguration: resolvedTextViewConfiguration,
26+
context: context
3027
)
31-
32-
guard let size: CGSize = view._sizeThatFits(proposal: proposal) else {
33-
return nil
34-
}
35-
36-
return size
3728
}
3829
}
3930

0 commit comments

Comments
 (0)