admin管理员组

文章数量:1391008

Consider a SwiftUI view that's using the .onDrop modifier:

struct Blah: View
{
    @State private var isDraggingActive: Bool

    var body: some View
    {
       ...
    }
    .onDrop(of: [.fileURL], isTargeted: $isDraggingActive.animation(.easeInOut(duration: 0.15)), perform: { providers in
            ...
        })
}

This lets our view nicely animate its state when a drag enters. Works great. But, if we need full control over validating the drag and use the delegate .onDrop method, instead, what is the right way to achieve the same animated updating of isDraggingActive?

struct Blah: View
{
    var dragDelegate = MyDragDelegate()
    @State private var isDraggingActive: Bool

    var body: some View
    {
       ...
    }
    .onDrop(of: [.fileURL], delegate: dragDelegate)   // How do we update the isDraggingActive state with animation here?
}

本文标签: swiftHow do you use SwiftUI39s onDrop( delegate) view modifier with animationStack Overflow