Post

Replies

Boosts

Views

Activity

How to disable the ability to collapse the SwiftUI Inspector?
I'm using the new SwiftUI Inspector API. Is it possible to disable the ability to collapse the inspector (when dragging the mouse cursor on the ionspector splitter)? Also, as a workaround, when the inspector is collapsed, I didn't find how I could expand the inspector programmatically? import SwiftUI struct SampleContentView: View { @State var inspectorPresented = true var body: some View { NavigationStack() { Text("Main View") .inspector(isPresented: $inspectorPresented, content: { Text("Inspector") .inspectorColumnWidth(200) }) } } }
1
0
843
Jul ’23
How to set the holding priority with NavigationSplitView
My question concerns a macOS SwiftUI app. I would like to have a split view with 2 horizontal panes without sidebar: content on the left and inspector on the right. The inspector should act like the inspector panel on the right side side of the Xcode's window: when the window is resized, the inspector keeps it's current width and the user can resize the inspector using the split divider. Using macOS Monterey SDK, I tried to achieve this with HSplitView but the problem is that the left/right panels are both resized when the window is resized. struct ContentView: View { var body: some View { HSplitView { Rectangle().fill(.red) Rectangle().fill(.yellow) } } } Using Ventura SDK, I just tried the new view NavigationSplitView. I'm using .constant(.doubleColumn) to hide the sidebar but the problem is the same as HSplitView, the left/right panel are both resized when the window is resized. struct ContentView: View { var body: some View { NavigationSplitView(columnVisibility: .constant(.doubleColumn)) { Text("not used") } content: { Rectangle().fill(.red) } detail: { Rectangle().fill(.yellow) } } } When using NSSplitViewController with AppKit, the holdingPriority (https://developer.apple.com/documentation/appkit/nssplitviewitem/1388887-holdingpriority?language=objc) allows to manage this case: The view with the lowest priority is the first to gain additional width if the split view grows or shrinks. Is it possible to achieve this with SwiftUI?
2
1
1.7k
Jun ’22
What are the best practices for managing custom properties with cells configurations?
I'm not sure if I need to store any variable used in updateConfiguration(using:) in the custom key value store of UICellConfigurationState. I'm skeptical because some of these variables do not semantically represent a "state". If I look at the sample WWDC sample code for custom cells configurations, all the variables used in updateConfiguration(using:) method are stored in the custom key value store of UICellConfigurationState. In fact, in this sample code, it's the whole model that it's stored in a state custom key. It seems weird because the base properties of UICellConfigurationState are real "state" properties: like selected, highlighted. In the same way, for the cells provided by UIKit, non state properties are stored in the configuration. For example, UIListContentConfiguration.imageProperties.tintColor, UIListContentConfiguration.imageToTextPadding. For a custom cell, we could imagine to subclass UIListContentConfiguration but it's not possible because it's a struct. Imagine you have a custom UICollectionViewListCell with a custom checkmark view. Associated to this checkmark, you have: checkmarkTintColor: an “appearance” property to set the tint color of the checkmark. checkmarkChecked: a ”state” property associated to the checkmark state. What is the good practice? Storing them the state key value store like this? var checkmarkChecked: Bool = false { 		didSet { 				guard oldValue != checked else { 						return 				} 				setNeedsUpdateConfiguration() 		} } 		 var checkmarkTintColor: UIColor? = nil { 		didSet { 				guard oldValue != checkmarkTintColor else { 						return 				} 				setNeedsUpdateConfiguration() 		} } var configuration: UIListContentConfiguration? { 		didSet { 				guard oldValue != configuration else { 						return 				} 				setNeedsUpdateConfiguration() 		} } override var configurationState: UICellConfigurationState { 		var state = super.configurationState 		state.checkmarkChecked = checkmarkChecked 		state.checkmarkTintColor = checkmarkTintColor 		return state } override func updateConfiguration(using state: UICellConfigurationState) { 		... 		checkmarkImageView.image = state.checked ? UIImage(systemName: "checkmark.circle.fill") : UIImage(systemName: "circle") 		checkmarkImageView.tintColor = checkmarkTintColor }
5
0
5.1k
Aug ’20