UIViews are known to be layer backed, but not sure about SwiftUI View. Is there a concept of layer in SwiftUI which can be added as sublayer, animated, everything you could do with CALayer?
UIViews are known to be layer backed, but not sure about SwiftUI View. Is there a concept of layer in SwiftUI which can be added as sublayer, animated, everything you could do with CALayer?
In the "Building Custom Views with SwiftUI" talk, they demonstrated that Views and Drawing models/interfaces have essentially been combined under the hood in the framework. Therefore, a View has layer like attributes but built onto the View itself rather than a layer abstraction.
Source: https://developer.apple.com/videos/play/wwdc2019/237/
import SwiftUI
import AVFoundation
struct DrawingView: UIViewRepresentable {
private let view = UIView()
var layer: CALayer? {
view.layer
}
func makeUIView(context: Context) -> UIView {
view
}
func updateUIView(_ uiView: UIView, context: Context) { }
}
After checking the SwiftUI's all methods by jumping to defination of View like this:
In that file, i can see that all UIControls, all methods, which as developer we can access are listed there. Here, i found that there is no any layer like concept. But all the properties of layer - like cornerRadius, borderWidth, borderColor, shadow etc all are already defined there. So i think there are less probable chance of having such concept in SwiftUI.
Still not sure for my this answer.