Why is there a "plus" icon at the top right corner of my view?

Viewed 825

I'm trying to implement the drag and drop feature to my LazyHGridview. When I try to drop the view on another view, a "plus" icon within a green circle is displayed at the top right corner of the view.

enter image description here

struct TestView: View {
var d: GridData
  @Binding var list: [GridData]
  @State private var dragOver = false
   
  var body: some View {
    VStack {
      Text(String(d.id))
        .font(.headline)
        .foregroundColor(.white)
    }
    .frame(width: 160, height: 240)
    .background(colorPalette[d.id])
    .onDrag {
      let item = NSItemProvider(object: String(d.id) as NSString)
      item.suggestedName = String(d.id)
      return item
    }
    .onDrop(of: [UTType.text], isTargeted: $dragOver) { providers in
       
      return true
    }
    .border(Color(UIColor.label), width: dragOver ? 8 : 0)
  }
}
}
2 Answers

It is managed by DropProposal drop operation and by default (if you do not provide explicit drop delegate) is .copy as documented, which adds '+' sign. By this you inform user that something will be duplicated.

/// Tells the delegate that a validated drop moved inside the modified view.
///
/// Use this method to return a drop proposal containing the operation the
/// delegate intends to perform at the drop ``DropInfo/location``. The
/// default implementation of this method returns `nil`, which tells the
/// drop to use the last valid returned value or else
/// ``DropOperation/copy``.
public func dropUpdated(info: DropInfo) -> DropProposal?

if you want to manage it explicitly then provide DropDelegate with implemented drop update as in below demo

func dropUpdated(info: DropInfo) -> DropProposal?
   // By this you inform user that something will be just relocated
   return DropProposal(operation: .move)
}

That is the normal user interface indicating that, at the point where your finger is at the moment, it is okay to drop the view you are dragging.

Related