Hi all,
When dragging a .clipped() view, the floating rendering of the view being dragged has a ghost version of the view prior to clipping. It appears as if the non-clipped view is used to make a shadow, but otherwise only the clipped view is shown.
What I’d like is for the floating view to look like the original one, maybe with some scaling and shadow. Does anyone know how to achieve this?
Here’s an example of the behavior. It makes a 300x300 ‘plus’ shape from two rectangles and then crops it down to the center square where the rectangles overlap. When dragging, a shadow in shape of a plus appears:
swift
import SwiftUI
import PlaygroundSupport
struct DragMe: View {
var body: some View {
ZStack {
Rectangle().frame(width: 300, height: 100)
Rectangle().frame(width: 100, height: 300)
}
.foregroundColor(.green)
.frame(width: 100, height: 100)
.clipped()
.onDrag { NSItemProvider() }
}
}
PlaygroundPage.current.setLiveView(DragMe())
Thanks!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Is there a good way to obtain a binding to the associated value of an enum? For now I'm using custom Bindings like this:
enum Row {
case text(_ body: String)
// ...
}
struct StuffView: View {
@State var stuff: [Row] = [.text("foo"), .text("bar")]
var body: some View {
List {
ForEach(stuff.indices) { idx in
switch stuff[idx] {
case .text(let body):
HStack {
// want: TextField("Row \(idx)", text: $body)
//		or TextField("Row \(idx)", text: $stuff[idx].body)
TextField(
"Row \(idx)",
text: Binding(
get: { body },
set: { stuff[idx] = .text($0) }
)
)
Spacer()
Text(body)
}
}
}
}
}
}
However, this seems overly complicated. Also, in the above example, if there are updates to the TextFields triggered by autocorrect, they're not reflected in the accompanying Text, so I suspect that this usage of bindings is not idiomatic.