I have a view that gets dragged around the screen by updating its position. I'm having a hard time setting its initial position via an argument.
I'm trying to use the commented out var initialPosition argument.
struct FloatingView<Content:View>: View {
let content: Content
var hidden: Bool
var size: CGSize
// var initialPosition: CGPoint
@State private var location: CGPoint = CGPoint(x:65, y:100)
var simpleDrag: some Gesture {
DragGesture()
.onChanged { value in
self.location = value.location
}
}
var body: some View {
if hidden == false {
content
.foregroundColor(.pink)
// .frame(width: 100, height: 100)
.position(location)
.gesture(simpleDrag)
}
}
}