Skip to content

Commit 6b4acea

Browse files
committed
Update package
1 parent a686639 commit 6b4acea

17 files changed

+379
-243
lines changed

Sources/SwiftUIX/Intermodular/Extensions/AppKit or UIKit/AppKitOrUIKitTextView++.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,14 @@ extension AppKitOrUIKitTextView {
229229
private func _sizeThatFitsWithoutCopying(
230230
width: CGFloat
231231
) -> CGSize? {
232-
guard let textContainer = _SwiftUIX_textContainer, let layoutManager = _SwiftUIX_layoutManager, let textStorage = _SwiftUIX_textStorage else {
232+
guard
233+
let textContainer = _SwiftUIX_textContainer,
234+
let layoutManager = _SwiftUIX_layoutManager,
235+
let textStorage = _SwiftUIX_textStorage
236+
else {
233237
return nil
234238
}
235-
239+
236240
let originalSize = frame.size
237241
let originalTextContainerSize = textContainer.containerSize
238242

Sources/SwiftUIX/Intermodular/Extensions/CoreGraphics/CGSize++.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ extension CGSize {
5959
public var maximumDimensionLength: CGFloat {
6060
max(width, height)
6161
}
62+
63+
@_optimize(speed)
64+
@inline(__always)
65+
public static var _width1_height1: CGSize {
66+
CGSize(width: 1, height: 1)
67+
}
6268
}
6369

6470
extension CGSize {

Sources/SwiftUIX/Intermodular/Helpers/AppKit or UIKit/AppKitOrUIKitViewRepresentable.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,23 @@ extension AppKitOrUIKitViewRepresentable {
316316
nsView: AppKitOrUIKitViewType,
317317
context: Context
318318
) -> CGSize? {
319-
self.sizeThatFits(proposal, view: nsView, context: context)
319+
let represented = nsView as? _AppKitOrUIKitRepresented
320+
321+
represented?.representatableStateFlags.insert(.sizingInProgress)
322+
323+
let result: CGSize? = self.sizeThatFits(proposal, view: nsView, context: context)
324+
325+
represented?.representatableStateFlags.remove(.sizingInProgress)
326+
327+
return result
320328
}
321329
}
322330

323331
extension AppKitOrUIKitViewRepresentable {
324332
@MainActor
325-
public func makeNSView(context: Context) -> AppKitOrUIKitViewType {
333+
public func makeNSView(
334+
context: Context
335+
) -> AppKitOrUIKitViewType {
326336
makeAppKitOrUIKitView(context: context)
327337
}
328338

Sources/SwiftUIX/Intermodular/Helpers/SwiftUI/AnyViewModifier.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ public struct AnyViewModifier: ViewModifier {
3939

4040
extension View {
4141
@ViewBuilder
42-
func modifiers(_ modifiers: [AnyViewModifier]) -> some View {
42+
func modifiers(
43+
_ modifiers: [AnyViewModifier]
44+
) -> some View {
4345
if modifiers.isEmpty {
4446
self
4547
} else {
46-
modifiers.reduce(eraseToAnyView()) { view, modifier in
47-
view.modifier(modifier).eraseToAnyView()
48+
modifiers.reduce(into: eraseToAnyView()) { (view, modifier) -> () in
49+
view = view.modifier(modifier).eraseToAnyView()
4850
}
4951
}
5052
}

Sources/SwiftUIX/Intermodular/Helpers/SwiftUI/_opaque_View.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension _opaque_View where Self: View {
2828

2929
@inlinable
3030
public func eraseToAnyView() -> AnyView {
31-
.init(self)
31+
AnyView(self)
3232
}
3333
}
3434

Sources/SwiftUIX/Intramodular/Bridging/_AppKitOrUIKitRepresented.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public struct _AppKitOrUIKitRepresentableStateFlags: OptionSet {
2323

2424
public static let updateInProgress = Self(rawValue: 1 << 0)
2525
public static let didUpdateAtLeastOnce = Self(rawValue: 1 << 1)
26-
public static let dismantled = Self(rawValue: 1 << 2)
26+
public static let sizingInProgress = Self(rawValue: 1 << 2)
27+
public static let dismantled = Self(rawValue: 1 << 3)
2728
}
2829

2930
@_documentation(visibility: internal)

Sources/SwiftUIX/Intramodular/Bridging/_CocoaHostingView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ open class _CocoaHostingView<Content: View>: AppKitOrUIKitHostingView<CocoaHosti
6565
}
6666
}
6767

68+
#if os(macOS)
69+
override open var wantsDefaultClipping: Bool {
70+
super.wantsDefaultClipping
71+
}
72+
#endif
73+
6874
#if os(macOS)
6975
@_optimize(speed)
7076
@inline(__always)

Sources/SwiftUIX/Intramodular/Collection View/CocoaHostingCollectionViewSupplementaryView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ class CocoaHostingCollectionViewSupplementaryView<
7676
}
7777
}
7878

79-
override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize {
80-
return contentHostingController?.systemLayoutSizeFitting(targetSize) ?? .init(width: 1, height: 1)
79+
override func systemLayoutSizeFitting(
80+
_ targetSize: CGSize
81+
) -> CGSize {
82+
return contentHostingController?.systemLayoutSizeFitting(targetSize) ?? CGSize._width1_height1
8183
}
8284

8385
override func systemLayoutSizeFitting(
@@ -96,7 +98,7 @@ class CocoaHostingCollectionViewSupplementaryView<
9698
}
9799

98100
guard let contentHostingController = contentHostingController else {
99-
return .init(width: 1, height: 1)
101+
return CGSize._width1_height1
100102
}
101103

102104
return contentHostingController.systemLayoutSizeFitting(

Sources/SwiftUIX/Intramodular/Text/_PlatformTextView+Auxiliary.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,20 @@ extension _PlatformTextView {
5959
public func invalidateDisplay(
6060
for range: NSRange
6161
) {
62-
_SwiftUIX_layoutManager?.invalidateDisplay(forCharacterRange: range)
62+
guard let layoutManager = _SwiftUIX_layoutManager else {
63+
return
64+
}
65+
66+
layoutManager.invalidateDisplay(forCharacterRange: range)
6367
}
6468

6569
public func _ensureLayoutForTextContainer() {
6670
if let textContainer = _SwiftUIX_textContainer {
67-
_SwiftUIX_layoutManager?.invalidateLayout(forCharacterRange: .init(location: 0, length: _SwiftUIX_attributedText.length), actualCharacterRange: nil)
71+
_SwiftUIX_layoutManager?.invalidateLayout(
72+
forCharacterRange: .init(location: 0, length: _SwiftUIX_attributedText.length),
73+
actualCharacterRange: nil
74+
)
75+
6876
_SwiftUIX_layoutManager?.ensureLayout(for: textContainer)
6977
}
7078
}

Sources/SwiftUIX/Intramodular/Text/_PlatformTextView-AppKit.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#if os(macOS)
66

7+
import _SwiftUIX
78
import AppKit
89
import SwiftUI
910

@@ -61,7 +62,7 @@ extension _PlatformTextView {
6162
textStorage._assignIfNotEqual(foregroundColor, to: \.foregroundColor)
6263
}
6364

64-
if let typingAttribute = typingAttributes[NSAttributedString.Key.foregroundColor] as? AppKitOrUIKitColor, typingAttribute != foregroundColor {
65+
if let typingAttribute: AppKitOrUIKitColor = typingAttributes[NSAttributedString.Key.foregroundColor] as? AppKitOrUIKitColor, typingAttribute != foregroundColor {
6566
typingAttributes[NSAttributedString.Key.foregroundColor] = foregroundColor
6667
typingAttributes[NSAttributedString.Key.paragraphStyle] = defaultParagraphStyle
6768
}
@@ -112,11 +113,11 @@ extension _PlatformTextView {
112113
if _needsIntrinsicContentSizeInvalidation {
113114
invalidateIntrinsicContentSize()
114115

115-
if let intrinsicContentSize = _computeIntrinsicContentSize() {
116+
/*if let intrinsicContentSize = _computeIntrinsicContentSize() {
116117
self.representableCache._cachedIntrinsicContentSize = intrinsicContentSize
117118

118119
_enforcePrecomputedIntrinsicContentSize()
119-
}
120+
}*/
120121
}
121122

122123
if _wantsRelayout {

Sources/SwiftUIX/Intramodular/Text/_PlatformTextView-UIKit.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#if os(iOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
66

7+
import _SwiftUIX
8+
import Foundation
79
import SwiftUI
810
import UIKit
911

@@ -19,7 +21,7 @@ extension _PlatformTextView {
1921
view.hoverStyle = .none
2022
#endif
2123

22-
let requiresAttributedText = false
24+
let requiresAttributedText: Bool = false
2325
|| context.environment._textView_requiresAttributedText
2426
|| configuration.requiresAttributedText
2527
|| data.wrappedValue.isAttributed

Sources/SwiftUIX/Intramodular/Text/_PlatformTextView.swift

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#if os(iOS) || os(macOS) || os(tvOS) || os(visionOS) || targetEnvironment(macCatalyst)
66

7+
import _SwiftUIX
78
import Combine
89
import Swift
910
import SwiftUI
@@ -38,6 +39,7 @@ public protocol _PlatformTextViewType: _AppKitOrUIKitRepresented, AppKitOrUIKitT
3839

3940
func invalidateLayout(for range: NSRange)
4041
func invalidateDisplay(for range: NSRange)
42+
4143
func _ensureLayoutForTextContainer()
4244
}
4345

@@ -669,111 +671,6 @@ open class _PlatformTextView<Label: View>: AppKitOrUIKitTextView, NSLayoutManage
669671
}
670672
}
671673

672-
@available(iOS 13.0, macOS 11.0, tvOS 13.0, *)
673-
extension _PlatformTextView {
674-
func _sizeThatFits(
675-
proposal: AppKitOrUIKitLayoutSizeProposal
676-
) -> CGSize? {
677-
guard let targetWidth = proposal.replacingUnspecifiedDimensions(by: .zero).targetWidth else {
678-
assertionFailure()
679-
680-
return nil
681-
}
682-
683-
if let _fixedSize = configuration._fixedSize {
684-
if _fixedSize.value == (false, false) {
685-
return nil
686-
}
687-
}
688-
689-
if let cached = representableCache.sizeThatFits(proposal: proposal) {
690-
return cached
691-
} else {
692-
assert(proposal.size.maximum == nil)
693-
694-
let _sizeThatFits: CGSize? = _uncachedSizeThatFits(for: targetWidth)
695-
696-
guard var result: CGSize = _sizeThatFits else {
697-
return nil
698-
}
699-
700-
if !result._hasPlaceholderDimension(.width, for: .textContainer) {
701-
var _result = result._filterPlaceholderDimensions(for: .textContainer)
702-
703-
if let _fixedSize = configuration._fixedSize {
704-
switch _fixedSize.value {
705-
case (false, false):
706-
if (_result.width ?? 0) < targetWidth {
707-
_result.width = targetWidth
708-
}
709-
710-
if let targetHeight = proposal.targetHeight, (_result.height ?? 0) < targetHeight {
711-
_result.height = targetHeight
712-
}
713-
case (false, true):
714-
if (_result.width ?? 0) < targetWidth {
715-
if _numberOfLinesOfWrappedTextDisplayed > 1 {
716-
_result.width = targetWidth
717-
}
718-
}
719-
720-
if let targetHeight = proposal.targetHeight, (_result.height ?? 0) < targetHeight {
721-
_result.height = targetHeight
722-
}
723-
default:
724-
assertionFailure()
725-
726-
break
727-
}
728-
} else {
729-
_result.width = max(result.width, targetWidth)
730-
}
731-
732-
guard let _result = CGSize(_result) else {
733-
return nil
734-
}
735-
736-
result = _result
737-
} else {
738-
guard !targetWidth.isPlaceholderDimension(for: .textContainer) else {
739-
return nil
740-
}
741-
742-
result.width = targetWidth
743-
}
744-
745-
representableCache._sizeThatFitsCache[proposal] = result
746-
747-
return result
748-
}
749-
}
750-
751-
private func _uncachedSizeThatFits(
752-
for width: CGFloat
753-
) -> CGSize? {
754-
guard let textContainer = _SwiftUIX_textContainer, let layoutManager = _SwiftUIX_layoutManager else {
755-
return nil
756-
}
757-
758-
if
759-
!representableCache._sizeThatFitsCache.isEmpty,
760-
textContainer.containerSize.width == width,
761-
textContainer._hasNormalContainerWidth
762-
{
763-
let usedRect = layoutManager.usedRect(for: textContainer).size
764-
765-
/// DO NOT REMOVE.
766-
if usedRect.isAreaZero {
767-
return _sizeThatFitsWidth(width)
768-
}
769-
770-
return usedRect
771-
} else {
772-
return _sizeThatFitsWidth(width)
773-
}
774-
}
775-
}
776-
777674
// MARK: - Conformances
778675

779676
@_spi(Internal)
@@ -788,16 +685,4 @@ extension _PlatformTextView: _PlatformTextViewType {
788685
}
789686
}
790687

791-
// MARK: - Helpers
792-
793-
extension NSAttributedString {
794-
var _isSingleTextAttachment: Bool {
795-
guard length == 1, self.string.first! == Character(UnicodeScalar(NSTextAttachment.character)!) else {
796-
return false
797-
}
798-
799-
return true
800-
}
801-
}
802-
803688
#endif

0 commit comments

Comments
 (0)