Post

Replies

Boosts

Views

Activity

Draggable Views with Child Drop Destination Elements not Draggable in iOS 18
I'm creating an app that has a number of draggable views, and each of these views themselves contain child dropDestination views. In iOS 17.x they are draggable as expected. However, in iOS 18 betas 1 & 2 a long press on these views does NOT pick them up (start the drag operation). I have not tested with macOS 15 betas but the issue may well exist there also. Is this a bug in iOS 18 betas 1 & 2 or does the implementation need to be updated somehow for iOS 18? Please see example code below: Views: import SwiftUI extension View { func dropTarget<T>(for payloadType: T.Type, withTitle title: String) -> some View where T: Transferable { modifier(DropTargetViewModifer<T>(title: title)) } } struct DropTargetViewModifer<T>: ViewModifier where T: Transferable { let title: String func body(content: Content) -> some View { content .dropDestination(for: T.self) { items, location in print("Item(s) dropped in \(title)") return true } isTargeted: { targted in if targted { print("\(title) targeted") } } } } struct InnerTestView: View { let title: String let borderColor: Color var body: some View { ZStack { Text(title) .padding() Rectangle() .stroke(borderColor) } .contentShape(Rectangle()) } } struct TestView: View { var body: some View { VStack(spacing: 0.0) { HStack(alignment: .top, spacing: 0.0) { InnerTestView(title: "Drop Zone 1", borderColor: .pink) .dropTarget(for: ItemType1.self, withTitle: "Drop Zone 1") InnerTestView(title: "Drop Zone 2", borderColor: .indigo) .dropTarget(for: ItemType2.self, withTitle: "Drop Zone 2") } InnerTestView(title: "Drop Zone 3", borderColor: .orange) .dropTarget(for: ItemType3.self, withTitle: "Drop Zone 3") } .contentShape(Rectangle()) .draggable(ItemType1(id: "Object 1")) } } struct ContentView: View { var body: some View { ScrollView { LazyVStack { TestView() TestView() InnerTestView(title: "Draggable 2", borderColor: .orange) .draggable(ItemType2(id: "Object 2")) InnerTestView(title: "Draggable 3", borderColor: .indigo) .draggable(ItemType3(id: "Object 3")) } .padding() } } } Transfer Representations: import UniformTypeIdentifiers import CoreTransferable extension UTType { static let itemType1 = UTType(exportedAs: "com.droptest.typeone") static let itemType2 = UTType(exportedAs: "com.droptest.typetwo") static let itemType3 = UTType(exportedAs: "com.droptest.typethree") } struct ItemType1: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType1) } } struct ItemType2: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType2) } } struct ItemType3: Codable, Transferable { var id: String public static var transferRepresentation: some TransferRepresentation { CodableRepresentation(contentType: .itemType3) } }
3
3
586
Jun ’24