glassBackgroundEffect not appearing in onDrag visionOS

When doing an onDrag the image shown does not include the glassBackgroundEffect for the item in the drag on visionOS.


struct GlassDragView: View {
    @State private var items: [String] = ["Item 1", "Item 2"]

    var body: some View {
        VStack {
            ForEach(items, id: \.self) { item in
                ZStack {
                    RoundedRectangle(cornerRadius: 8)
                        .foregroundColor(.clear)
                        .frame(width: 200, height: 100)
                    Text(item)
                        .padding()
                        .background(.gray)
                        .cornerRadius(8)
                }
                .onDrag {
                    return NSItemProvider(object: item as NSString)
                }
                .glassBackgroundEffect()
             }
        }
        .frame(width: 600, height: 400)
        .background(.gray)
    }
}

How can the glassBackgroundEffect be used in a way that appears in onDrag?

Answered by kregholgerson in 789864022

Figured it out. Switched to a List instead of VStack and glass effect appears on drag.

struct GlassDragView: View {
    @State private var items: [String] = ["Item 1", "Item 2"]

    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                ZStack {
                    RoundedRectangle(cornerRadius: 8)
                        .foregroundColor(.clear)
                        .frame(width: 200, height: 100)
                    Text(item)
                        .padding()
                        .background(.gray)
                        .cornerRadius(8)
                }
                .onDrag {
                    return NSItemProvider(object: item as NSString)
                }
             }
        }
        .frame(width: 600, height: 400)
        .background(.gray)
    }
}
Accepted Answer

Figured it out. Switched to a List instead of VStack and glass effect appears on drag.

struct GlassDragView: View {
    @State private var items: [String] = ["Item 1", "Item 2"]

    var body: some View {
        List {
            ForEach(items, id: \.self) { item in
                ZStack {
                    RoundedRectangle(cornerRadius: 8)
                        .foregroundColor(.clear)
                        .frame(width: 200, height: 100)
                    Text(item)
                        .padding()
                        .background(.gray)
                        .cornerRadius(8)
                }
                .onDrag {
                    return NSItemProvider(object: item as NSString)
                }
             }
        }
        .frame(width: 600, height: 400)
        .background(.gray)
    }
}
glassBackgroundEffect not appearing in onDrag visionOS
 
 
Q