Post

Replies

Boosts

Views

Activity

Drag and Drop using SwiftUI
Overview I am bit confused regarding drag and drop on SwiftUI I think there are 2 approaches but I am stuck with both approaches WWDC22 When using the new draggable, dropDestination, Transferable API, only single items are draggable. Multiple items in a list are not draggable. I have filed a feedback FB10128110 WWDC21 I have faced a couple of issues for drag and drop introduced in WWDC21 (onDrag, onDrop, itemIdentifier), the Feedback ids are FB9854301, FB9854569, FB9855245, FB9855532, FB9855567, FB9855575. It contains sample projects, would really appreciate if someone could have a look it. Note: All feedbacks include a sample project with detail steps and some even have screenshots and videos Questions: If my approach is wrong or if I am missing something? Unfortunately I didn't manage to get a SwiftUI lab session (got cancelled), so please help me with these issues.
4
1
3.1k
Jun ’22
How to drag multiple items in a list
I have a list containing multiple cells. How to drag the selected items? struct FolderDetail: View { let folder: Folder? @ObservedObject var dataStore: DataStore @State private var selectedCarIDs = Set<Int>() var body: some View { if let folder { List(dataStore.cars[folder.id] ?? [], selection: $selectedCarIDs) { car in Text(car.name) .tag(car.id) .draggable(car.name) } } else { Text("no folder selected") } } }
2
1
1.8k
Jun ’22
@SceneStorage on iPad potrait doesn't show the correct screen
Overview On the iPad Portrait mode using @SceneStorage doesn't show the detail screen, instead it shows the place holder screen. Tapping on the back button then shows the restored detail screen Steps to Reproduce Run on iPad potrait Select the Car "bbb" See the Car Detail with the car name "bbb" Enter background Repeat steps 1 and 2 Actual Behaviour: Notice the car name is not displayed, it shows the "No car selected" text, tapping on the back button then shows the CarDetail screen with the name "bbb" Expected Behaviour:  The shows the CarDetail screen should show with the name "bbb" immediately instead of showing the place holder screen Note: It works fine on iPhone potrait and iPad landscape Problem is on iPad potrait and iPhone 13 Pro max landscape Code: ContentView struct ContentView: View {     var body: some View {         NavigationView {             CarList()             Text("No car selected")                 .font(.largeTitle)         }     } } CarList struct CarList: View { let cars = [Car(id: 1, name: "aaa"), Car(id: 2, name: "bbb"), Car(id: 3, name: "ccc")] @SceneStorage("selectedCarID") private var selectedCarID: Int? var body: some View { List { ForEach(cars) { car in NavigationLink(tag: car.id, selection: $selectedCarID) { CarDetail(name: car.name) } label: { Text(car.name) } } } } } CarDetail struct CarDetail: View { let name: String var body: some View { ZStack { Color.brown Text(name) .font(.largeTitle) } } } Car struct Car: Identifiable {     var id: Int     var name: String } GIF
0
0
540
May ’22