It appears that SwiftUI now prevents Buttons from being dragged. This used to work in Xcode 15.4 and Xcode 16 beta 1-2.
Basically, if the draggable view modifier is associated with a Button, it can no longer be dragged. I have several uses cases where sometimes I want to have an entity behave as a button, but also be draggable.
Example shows case where a Button is draggable. There’s also a simple VStack that is draggable. The VStack works, the button does not.
import Foundation
import CoreTransferable
import UniformTypeIdentifiers
extension UTType {
static let entityReference: UTType = UTType(exportedAs: "com.mycompany.MyApp.entity-reference")
}
struct EntityReference: Codable, Transferable {
let identifier: String
static var transferRepresentation: some TransferRepresentation {
CodableRepresentation(contentType: .entityReference)
}
}
struct ContentView: View {
var body: some View {
VStack {
Button {
print("Button pressed")
} label: {
VStack {
Text("I'm a button. Try to drag me.")
.font(.title)
}
.border(.black)
.padding()
}
.draggable(EntityReference(identifier: "some-id"))
VStack {
Text("NOT a button. Try to drag me too.")
.font(.title)
}
.border(.black)
.padding()
.draggable(EntityReference(identifier: "some-id"))
VStack {
Text("Drop area")
.font(.title)
}
.border(.black)
.padding()
.dropDestination(for: EntityReference.self) { droppedEntityReferences, location in
print("Dropped something here!")
return true
}
}
}
}
#Preview {
ContentView()
}
I presume that I can maybe work around this by not using Buttons, but this is not really great for accessibility without adding more custom traits.
Submitted bug report: FB14518001
Post
Replies
Boosts
Views
Activity
I'm trying to convert my project to use Swift 6 with Complete Concurrency in Xcode 16 beta 1.
The project uses TipKit, but I'm getting compile errors when trying to use the TipKit Parameters feature. Here is an example of the type of error I'm seeing (Note that this code from https://developer.apple.com/documentation/tipkit/highlightingappfeatureswithtipkit):
struct ParameterRuleTip: Tip {
// Define the app state you want to track.
@Parameter
static var isLoggedIn: Bool = false
Static property '$isLoggedIn' is not concurrency-safe because it is non-isolated global shared mutable state.
Is there a new pattern for supporting TipKit Parameters in Swift 6 with Complete Concurrency enabled? There is no obvious suggestion for how to fix this.
The latest WWDC 2024 TipKit doesn't appear to have any solution(s).
For some reason, ToolbarItems are not visible in this code. This worked in Xcode 13. Not sure whether I'm doing something wrong or not? Note that if isFlowDetermined is initialized to true, then the "Cancel" button does appear. Any guidance appreciated.
import SwiftUI
struct ContentView: View {
@State private var isFlowDetermined = false
var body: some View {
NavigationView {
//NestedView()
if self.isFlowDetermined {
NestedView()
} else {
ProgressView()
.task {
await self.determineFlow()
}
}
}
}
private func determineFlow() async {
self.isFlowDetermined = true
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct NestedView: View {
var body: some View {
ScrollView {
Text("Is there a Cancel button?")
}
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.toolbar {
#if !os(macOS)
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
print("got here")
}
}
#endif
}
}
}