Skip to content

Commit 4923b61

Browse files
committed
updated
1 parent 65b4c6b commit 4923b61

File tree

10 files changed

+142
-111
lines changed

10 files changed

+142
-111
lines changed

Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"location" : "https://github.com/flocked/FZUIKit.git",
2525
"state" : {
2626
"branch" : "main",
27-
"revision" : "5f12b512d332c17440af0bebb25ffa295b6702ff"
27+
"revision" : "31a7f38c18bfc669e8379ec3971c4b6da47b2b54"
2828
}
2929
}
3030
],

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSItemContentConfiguration/NSItemContentView+Content.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extension NSItemContentView {
2929
var previousSize: CGSize = .zero
3030
var centerYConstraint: NSLayoutConstraint?
3131
var intrinsicSize = CGSize(NSView.noIntrinsicMetric, NSView.noIntrinsicMetric)
32-
var _scaleTransform: Scale = .none
33-
var _rotation: Rotation = .zero
3432

3533
var view: NSView? {
3634
didSet {
@@ -273,16 +271,8 @@ extension NSItemContentView {
273271
view = configuration.view
274272
overlayView = configuration.overlayView
275273

276-
if contentProperties.scaleTransform != _scaleTransform {
277-
anchorPoint = .center
278-
_scaleTransform = contentProperties.scaleTransform
279-
animator(isAnimating).scale = _scaleTransform
280-
}
281-
if contentProperties.rotation != _rotation {
282-
anchorPoint = .center
283-
_rotation = contentProperties.rotation
284-
animator(isAnimating).rotation = _rotation
285-
}
274+
_scaleTransform = contentProperties.scaleTransform
275+
_rotation = contentProperties.rotation
286276

287277
toolTip = contentProperties.toolTip
288278
animator(isAnimating).isHidden = !configuration.hasContent

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSItemContentConfiguration/NSItemContentView.swift

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ open class NSItemContentView: NSView, NSContentView, EditingContentView {
5656

5757
If you apply a new configuration without primary text to the content view, the system removes this layout guide from the view and deactivates any constraints associated with it.
5858
*/
59-
public internal(set) var textLayoutGuide: NSLayoutGuide?
59+
public var textLayoutGuide: NSLayoutGuide? { textStackView.textField.layoutGuide }
6060

6161
/**
6262
A guide for positioning the secondary text in the content view.
@@ -65,7 +65,7 @@ open class NSItemContentView: NSView, NSContentView, EditingContentView {
6565

6666
If you apply a new configuration without secondary text to the content view, the system removes this layout guide from the view and deactivates any constraints associated with it.
6767
*/
68-
public internal(set) var secondaryTextLayoutGuide: NSLayoutGuide?
68+
public var secondaryTextLayoutGuide: NSLayoutGuide? { textStackView.secondaryTextField.layoutGuide }
6969

7070
/**
7171
A guide for positioning the image or view in the content view.
@@ -98,24 +98,22 @@ open class NSItemContentView: NSView, NSContentView, EditingContentView {
9898
(rect.intersects(contentView.frame) && !contentView.isHidden) || (rect.intersects(textField.frame) && !textField.isHidden) || (rect.intersects(secondaryTextField.frame) && !secondaryTextField.isHidden)
9999
}
100100

101-
let textField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
102-
let secondaryTextField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
101+
var textField: ListItemTextField { textStackView.textField }
102+
var secondaryTextField: ListItemTextField { textStackView.secondaryTextField }
103103
lazy var contentView = ItemContentView(configuration: appliedConfiguration)
104104
var textFieldAlignment: NSTextAlignment?
105105
var secondaryTextFieldAlignment: NSTextAlignment?
106106
var textFieldConstraint: NSLayoutConstraint?
107107
var secondaryTextFieldConstraint: NSLayoutConstraint?
108108

109-
lazy var textStackView = NSStackView(views: [textField, secondaryTextField]).orientation(.vertical).alignment(.leading).spacing(appliedConfiguration.textToSecondaryTextPadding)
109+
lazy var textStackView = TextStackView()
110110

111111
lazy var stackView = NSStackView(views: [contentView, textStackView])
112112
.orientation(appliedConfiguration.contentPosition.orientation)
113113
.alignment(appliedConfiguration.contentAlignment)
114114
.spacing(appliedConfiguration.contentToTextPadding)
115115

116116
var stackviewConstraints: [NSLayoutConstraint] = []
117-
var _scaleTransform: Scale = .none
118-
var _rotation: Rotation = .zero
119117

120118
@available(*, unavailable)
121119
public required init?(coder _: NSCoder) {
@@ -144,28 +142,15 @@ open class NSItemContentView: NSView, NSContentView, EditingContentView {
144142
func updateConfiguration() {
145143
let isAnimating = NSAnimationContext.hasActiveGrouping && NSAnimationContext.current.duration > 0.0
146144
contentView.centerYConstraint?.activate(false)
145+
146+
textStackView.update(with: appliedConfiguration, for: self)
147+
148+
_scaleTransform = appliedConfiguration.scaleTransform
149+
_rotation = appliedConfiguration.rotation
147150

148-
textField.properties = appliedConfiguration.textProperties
149-
textField.updateText(appliedConfiguration.text, appliedConfiguration.attributedText, appliedConfiguration.placeholderText, appliedConfiguration.attributedPlaceholderText)
150-
secondaryTextField.properties = appliedConfiguration.secondaryTextProperties
151-
secondaryTextField.updateText(appliedConfiguration.secondaryText, appliedConfiguration.secondaryAttributedText, appliedConfiguration.secondaryPlaceholderText, appliedConfiguration.secondaryAttributedPlaceholderText)
152-
textField.isEnabled = firstSuperview(for: NSCollectionView.self)?.isEnabled ?? true
153-
secondaryTextField.isEnabled = textField.isEnabled
154-
155-
if appliedConfiguration.scaleTransform != _scaleTransform {
156-
anchorPoint = .center
157-
_scaleTransform = appliedConfiguration.scaleTransform
158-
animator(isAnimating).scale = _scaleTransform
159-
}
160-
if appliedConfiguration.rotation != _rotation {
161-
anchorPoint = .center
162-
_rotation = appliedConfiguration.rotation
163-
animator(isAnimating).rotation = _rotation
164-
}
165151
animator(isAnimating).alphaValue = appliedConfiguration.alpha
166152

167153
contentView.configuration = appliedConfiguration
168-
textStackView.animator(isAnimating).spacing = appliedConfiguration.textToSecondaryTextPadding
169154
stackView.animator(isAnimating).spacing = appliedConfiguration.contentToTextPadding
170155
stackView.animator(isAnimating).orientation = appliedConfiguration.contentPosition.orientation
171156
stackView.animator(isAnimating).alignment = appliedConfiguration.contentAlignment
@@ -210,22 +195,6 @@ open class NSItemContentView: NSView, NSContentView, EditingContentView {
210195
}
211196

212197
func updateLayoutGuides() {
213-
if !appliedConfiguration.hasText, let guide = textLayoutGuide {
214-
removeLayoutGuide(guide)
215-
textLayoutGuide = nil
216-
} else if appliedConfiguration.hasText, textLayoutGuide == nil {
217-
textLayoutGuide = NSLayoutGuide()
218-
addLayoutGuide(textLayoutGuide!)
219-
textLayoutGuide?.constraint(to: textField)
220-
}
221-
if !appliedConfiguration.hasSecondaryText, let guide = secondaryTextLayoutGuide {
222-
removeLayoutGuide(guide)
223-
secondaryTextLayoutGuide = nil
224-
} else if appliedConfiguration.hasSecondaryText, secondaryTextLayoutGuide == nil {
225-
secondaryTextLayoutGuide = NSLayoutGuide()
226-
addLayoutGuide(secondaryTextLayoutGuide!)
227-
secondaryTextLayoutGuide?.constraint(to: secondaryTextField)
228-
}
229198
if !appliedConfiguration.hasContent, let guide = contentLayoutGuide {
230199
removeLayoutGuide(guide)
231200
contentLayoutGuide = nil

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSListContentConfiguration/NSListContentConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ extension NSListContentConfiguration {
338338
configuration.textProperties.maximumNumberOfLines = 1
339339
configuration.secondaryTextProperties.font = .systemFont(style).weight(weight)
340340
configuration.secondaryTextProperties.maximumNumberOfLines = 0
341-
configuration.imageProperties.tintColor = color.primary
341+
configuration.imageProperties.tintColor = color.colors.first
342342
configuration.imageProperties.sizing = .firstTextHeight
343343
configuration.imageProperties.symbolConfiguration = .font(style, weight: weight).color(color)
344344
configuration.imageToTextPadding = 3.0

Sources/AdvancedCollectionTableView/Configuration/Configurations/NSListContentConfiguration/NSListContentView.swift

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ open class NSListContentView: NSView, NSContentView, EditingContentView {
5050

5151
If you apply a new configuration without primary text to the content view, the system removes this layout guide from the view and deactivates any constraints associated with it.
5252
*/
53-
public internal(set) var textLayoutGuide: NSLayoutGuide?
53+
public var textLayoutGuide: NSLayoutGuide? { textStackView.textField.layoutGuide }
5454

5555
/**
5656
A guide for positioning the secondary text in the content view.
@@ -59,7 +59,7 @@ open class NSListContentView: NSView, NSContentView, EditingContentView {
5959

6060
If you apply a new configuration without secondary text to the content view, the system removes this layout guide from the view and deactivates any constraints associated with it.
6161
*/
62-
public internal(set) var secondaryTextLayoutGuide: NSLayoutGuide?
62+
public var secondaryTextLayoutGuide: NSLayoutGuide? { textStackView.secondaryTextField.layoutGuide }
6363

6464
/**
6565
A guide for positioning the image in the content view.
@@ -85,18 +85,19 @@ open class NSListContentView: NSView, NSContentView, EditingContentView {
8585
}
8686
}
8787

88-
let textField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
89-
let secondaryTextField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
88+
//let textField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
89+
//let secondaryTextField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
90+
var textField: ListItemTextField { textStackView.textField }
91+
var secondaryTextField: ListItemTextField { textStackView.secondaryTextField }
92+
9093
lazy var imageView = ListImageView(properties: appliedConfiguration.imageProperties)
9194
var badgeView: BadgeView?
9295
var topAccesoryViews: [AccessoryView] = []
9396
var bottomAccesoryViews: [AccessoryView] = []
94-
lazy var textStackView = NSStackView(views: [textField, secondaryTextField]).orientation(.vertical).alignment(.leading)
97+
lazy var textStackView = TextStackView()
9598
lazy var imageTextStackView = NSStackView(views: [imageView, textStackView]).orientation(.horizontal).distribution(.fill)
9699
lazy var badgeStackView = NSStackView(views: [imageTextStackView]).orientation(.horizontal).distribution(.fill).alignment(.centerY)
97100
var stackViewConstraints: [NSLayoutConstraint] = []
98-
var _scaleTransform: Scale = .none
99-
var _rotation: Rotation = .zero
100101

101102
var tableCellView: NSTableCellView? {
102103
superview as? NSTableCellView
@@ -115,17 +116,12 @@ open class NSListContentView: NSView, NSContentView, EditingContentView {
115116

116117
toolTip = appliedConfiguration.toolTip
117118
imageView.verticalConstraint?.activate(false)
118-
119-
textField.isEnabled = appliedConfiguration.isEnabled
120-
textField.properties = appliedConfiguration.textProperties
121-
textField.updateText(appliedConfiguration.text, appliedConfiguration.attributedText, appliedConfiguration.placeholderText, appliedConfiguration.attributedPlaceholderText)
122-
secondaryTextField.isEnabled = appliedConfiguration.isEnabled
123-
secondaryTextField.properties = appliedConfiguration.secondaryTextProperties
124-
secondaryTextField.updateText(appliedConfiguration.secondaryText, appliedConfiguration.secondaryAttributedText, appliedConfiguration.secondaryPlaceholderText, appliedConfiguration.secondaryAttributedPlaceholderText)
119+
120+
textStackView.update(with: appliedConfiguration, for: self)
121+
125122
imageView.image = appliedConfiguration.image
126123
imageView.properties = appliedConfiguration.imageProperties
127124

128-
textStackView.animator(isAnimating).spacing = appliedConfiguration.textToSecondaryTextPadding
129125
imageTextStackView.animator(isAnimating).spacing = appliedConfiguration.imageToTextPadding
130126
imageTextStackView.animator(isAnimating).orientation = appliedConfiguration.imageProperties.position.orientation
131127
imageTextStackView.animator(isAnimating).alignment = appliedConfiguration.imageProperties.position.alignment
@@ -185,37 +181,14 @@ open class NSListContentView: NSView, NSContentView, EditingContentView {
185181

186182
updateAccesoryViews()
187183

188-
if appliedConfiguration.scaleTransform != _scaleTransform {
189-
anchorPoint = .center
190-
_scaleTransform = appliedConfiguration.scaleTransform
191-
animator(isAnimating).scale = _scaleTransform
192-
}
193-
if appliedConfiguration.rotation != _rotation {
194-
anchorPoint = .center
195-
_rotation = appliedConfiguration.rotation
196-
animator(isAnimating).rotation = _rotation
197-
}
184+
_scaleTransform = appliedConfiguration.scaleTransform
185+
_rotation = appliedConfiguration.rotation
186+
198187
animator(isAnimating).alphaValue = appliedConfiguration.alpha
199188
updateLayoutGuides()
200189
}
201190

202191
func updateLayoutGuides() {
203-
if !appliedConfiguration.hasText, let guide = textLayoutGuide {
204-
removeLayoutGuide(guide)
205-
textLayoutGuide = nil
206-
} else if appliedConfiguration.hasText, textLayoutGuide == nil {
207-
textLayoutGuide = NSLayoutGuide()
208-
addLayoutGuide(textLayoutGuide!)
209-
textLayoutGuide?.constraint(to: textField)
210-
}
211-
if !appliedConfiguration.hasSecondaryText, let guide = secondaryTextLayoutGuide {
212-
removeLayoutGuide(guide)
213-
secondaryTextLayoutGuide = nil
214-
} else if appliedConfiguration.hasSecondaryText, secondaryTextLayoutGuide == nil {
215-
secondaryTextLayoutGuide = NSLayoutGuide()
216-
addLayoutGuide(secondaryTextLayoutGuide!)
217-
secondaryTextLayoutGuide?.constraint(to: secondaryTextField)
218-
}
219192
if appliedConfiguration.image == nil, let guide = imageLayoutGuide {
220193
removeLayoutGuide(guide)
221194
imageLayoutGuide = nil

Sources/AdvancedCollectionTableView/Configuration/Configurations/Shared/ListItemTextField.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class ListItemTextField: NSTextField, NSTextFieldDelegate {
3535
}
3636
return firstSuperview(for: NSTableView.self)
3737
}
38+
39+
var layoutGuide: NSLayoutGuide?
40+
func updateLayoutGuide(for view: NSView) {
41+
if isHidden, let guide = layoutGuide {
42+
view.removeLayoutGuide(guide)
43+
layoutGuide = nil
44+
} else if isHidden, layoutGuide == nil {
45+
layoutGuide = NSLayoutGuide()
46+
view.addLayoutGuide(layoutGuide!)
47+
layoutGuide?.constraint(to: self)
48+
}
49+
}
3850

3951
func updateText(_ text: String?, _ attributedString: AttributedString?, _ placeholder: String? = nil, _ attributedPlaceholder: AttributedString? = nil) {
4052
let isAnimating = NSAnimationContext.hasActiveGrouping && NSAnimationContext.current.duration > 0.0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// TextStackView.swift
3+
//
4+
//
5+
// Created by Florian Zand on 02.03.25.
6+
//
7+
8+
import AppKit
9+
import FZUIKit
10+
11+
class TextStackView: NSStackView {
12+
let textField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
13+
let secondaryTextField = ListItemTextField.wrapping().truncatesLastVisibleLine(true)
14+
15+
func update(with properties: TextStackProperties, for view: NSView) {
16+
textField.isEnabled = properties.isEnabled
17+
textField.properties = properties.textProperties
18+
textField.updateText(properties.text, properties.attributedText, properties.placeholderText, properties.attributedPlaceholderText)
19+
textField.updateLayoutGuide(for: view)
20+
secondaryTextField.isEnabled = properties.isEnabled
21+
secondaryTextField.properties = properties.secondaryTextProperties
22+
secondaryTextField.updateText(properties.secondaryText, properties.secondaryAttributedText, properties.secondaryPlaceholderText, properties.secondaryAttributedPlaceholderText)
23+
secondaryTextField.updateLayoutGuide(for: view)
24+
spacing = properties.textToSecondaryTextPadding
25+
}
26+
27+
init() {
28+
super.init(frame: .zero)
29+
addArrangedSubview(textField)
30+
addArrangedSubview(secondaryTextField)
31+
orientation = .vertical
32+
alignment = .leading
33+
}
34+
35+
required init?(coder: NSCoder) {
36+
fatalError("init(coder:) has not been implemented")
37+
}
38+
}
39+
40+
extension NSListContentConfiguration: TextStackProperties { }
41+
extension NSItemContentConfiguration: TextStackProperties { }
42+
43+
protocol TextStackProperties {
44+
var text: String? { get }
45+
var attributedText: AttributedString? { get }
46+
var placeholderText: String? { get }
47+
var attributedPlaceholderText: AttributedString? { get }
48+
var secondaryText: String? { get }
49+
var secondaryAttributedText: AttributedString? { get }
50+
var secondaryPlaceholderText: String? { get }
51+
var secondaryAttributedPlaceholderText: AttributedString? { get }
52+
var textToSecondaryTextPadding: CGFloat { get }
53+
var textProperties: TextProperties { get }
54+
var secondaryTextProperties: TextProperties { get }
55+
var isEnabled: Bool { get }
56+
}
57+
58+
extension TextStackProperties {
59+
var isEnabled: Bool { true }
60+
}

Sources/AdvancedCollectionTableView/DiffableDataSource/NSCollectionView/CollectionViewDiffableDataSource+Delegate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import AppKit
99
import FZSwiftUtils
1010
import FZUIKit
11+
import UniformTypeIdentifiers
1112

1213
extension CollectionViewDiffableDataSource {
1314
class Delegate: NSObject, NSCollectionViewDelegate, NSCollectionViewPrefetching {
@@ -147,7 +148,7 @@ extension CollectionViewDiffableDataSource {
147148

148149

149150
// MARK: Dropping
150-
151+
151152
func collectionView(_ collectionView: NSCollectionView, validateDrop draggingInfo: NSDraggingInfo, proposedIndexPath: AutoreleasingUnsafeMutablePointer<NSIndexPath>, dropOperation proposedDropOperation: UnsafeMutablePointer<NSCollectionView.DropOperation>) -> NSDragOperation {
152153
droppingElements = []
153154
if draggingInfo.draggingSource as? NSCollectionView === dataSource.collectionView {

0 commit comments

Comments
 (0)