Post

Replies

Boosts

Views

Activity

View as a Parameter / Variable in SwiftUI
Hi, all!Still trying to wrap my brain around SwiftUI and how different it is from UIKit stuff.I've created a View called DraggableView which runs a closure when it's being dragged. I made it so that this view could accept as a variable in its constructor any other generic view, and it would essentially put that view into a draggable container. I had to construct it like so:DraggableView: View { var containedView: Content ... }And it seems to work. The DraggableView gets a container view and displays it properly.In the drag closure, I want the DraggableView to be able to pass back the view it was constructed with (A duplicate view of its insides).I don't know if it's because of Opaque return types or something, but I'm really confused at passing views around in general. I can't just have it expect a UIView like I used to be able to and that kind of *****.My drag closure looks like so right now and I'm getting all kinds of errors. I don't even really know what AnyView is but can't find any good documentation on it. There also appears to be a difference depending on where it's used? As in SwiftUI.AnyView vs AnyView?var dragClosure: (DragGesture.Value, CGFloat, CGFloat, AnyView) -> ()What should I do? I'm super confused.Thanks so much.
8
0
22k
Sep ’19