Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions apps/ios/Plotwist/Plotwist/Views/Home/ProfileCollectionGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ struct ProfileCollectionGrid: View {
onTapItem(item)
}
.onDrag {
draggingItem = item
withAnimation(.easeInOut(duration: 0.2)) {
draggingItem = item
}
return NSItemProvider(object: item.id as NSString)
}
.opacity(removingItemIds.contains(item.id) ? 0 : 1)
Expand All @@ -108,6 +110,10 @@ struct ProfileCollectionGrid: View {
}
.padding(.horizontal, 24)
.padding(.top, 16)
.onDrop(of: [.text], delegate: GridFallbackDropDelegate(
draggingItem: $draggingItem,
onReorder: onReorder
))
}

// MARK: - Context Menu
Expand Down Expand Up @@ -161,7 +167,28 @@ struct CollectionReorderDelegate: DropDelegate {
}

func performDrop(info: DropInfo) -> Bool {
draggingItem = nil
withAnimation(.easeInOut(duration: 0.2)) {
draggingItem = nil
}
onReorder()
return true
}

func dropUpdated(info: DropInfo) -> DropProposal? {
DropProposal(operation: .move)
}
}

// MARK: - Grid Fallback Drop Delegate
/// Catches drops that land between grid items (in the grid area but not on a specific item)
struct GridFallbackDropDelegate: DropDelegate {
@Binding var draggingItem: UserItemSummary?
var onReorder: () -> Void

func performDrop(info: DropInfo) -> Bool {
withAnimation(.easeInOut(duration: 0.2)) {
draggingItem = nil
}
onReorder()
return true
}
Expand Down
11 changes: 10 additions & 1 deletion apps/ios/Plotwist/Plotwist/Views/Home/ProfileTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

import SwiftUI
import UniformTypeIdentifiers

// MARK: - Profile Tab View
struct ProfileTabView: View {
Expand Down Expand Up @@ -57,6 +58,15 @@ struct ProfileTabView: View {
errorView
}
}
.onDrop(of: [.text], isTargeted: nil) { _ in
if draggingItem != nil {
withAnimation(.easeInOut(duration: 0.2)) {
draggingItem = nil
}
saveCollectionOrder()
}
return true
}
.onAppear {
if !hasAppeared {
hasAppeared = true
Expand Down Expand Up @@ -107,7 +117,6 @@ struct ProfileTabView: View {
)
}
.toolbar(draggingItem != nil ? .hidden : .visible, for: .tabBar)
.animation(.easeInOut(duration: 0.2), value: draggingItem != nil)
}
}

Expand Down
Loading