SwiftUI's List onDrag preview is failing to update with View State changes on macOS

Originator:jonathan.hume
Number:rdar://FB9790379 Date Originated:
Status:Open Resolved:
Product: Product Version:
Classification: Reproducible:
 
Problem Overview
==============

List’s onDrag modifier provides the opportunity to provide a  preview View that is shown to the user while dragging operations are underway.

On macOS,  this preview is rendering correctly the first time it is displayed. However, the preview is not then picking up any subsequent View State changes, instead it continues to render the original (and now out of step with State) preview.

Steps to reproduce
==================

MBP 15”, 2018, 2.6GHz i7 room heater
MacOS 12.0.1
Xcode 13.1 (13A1030d)

1. In Xcode create default app targeting iOS iPad and macOS.
2. Replace default ContentView with code show below.
3. Build and run on any supported iPad simulator.
4. Then in the running application on iPad, drag any of the rows for the:
    1. First time and note time shown in dragging preview.
    2. Second time and note time shown in dragging preview is _different_ to that shown in first drag (4.1)
5. Build and run on macOS.
6. The in the running application on macOS, drag any of the rows for the: 
    1. First time and note time shown in dragging preview.
    2. Second time and note time shown in dragging preview is _the same_ to that shown in first drag (6.1)
    3. Repeat ad infinitum, and note time shown in dragging preview is _the same_ to that shown in first drag (6.1) i.e. it never gets updated regardless of changes to the View’s date State.

Expected behaviour
=================

Expected the onDrag preview on macOS to update with date state changes as it does for iOS/iPadOS.

What happened
=============

On macOS the List’s onDrag preview is created correctly the first time only. Thereafter it does not pick updates to the parent view’s State.


Code
====

import SwiftUI

struct ContentView: View {
    var body: some View {
        List(band.indices, id: \.self) { idx in
            HStack {
                Text("\(idx), \(band[idx]), @ ") + Text(date, formatter: dateFormatter)
            }
            .onDrag(
                { NSItemProvider(object: NSString(string: String(idx))) },
                preview: {
                    HStack {
                        Text("\(idx), \(band[idx]), @ ") + Text(date, formatter: dateFormatter)
                    }

                    .fixedSize()
                    .padding()
                    .background(Color.accentColor.opacity(0.5))
                })
        }

        .onAppear {
            _ = updateTimer
        }
    }

    let band: Array<String> = ["John", "Paul", "Ringo", "George"]

    @State var selected: Set<Int> = []
    @State var date: Date = Date()

    let dateFormatter: DateFormatter = {
        let d = DateFormatter()
        d.dateStyle = .none
        d.timeStyle = .medium
        return d
    }()

    var updateTimer: Timer {
        Timer.scheduledTimer(
            withTimeInterval: 1,
            repeats: true,
            block: { _ in
                self.date = Date()
            }
        )
    }
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!