View Descriptions contain all the information needed to create an instance of a native UIView. Importantly, view descriptions do not contain instances of a view. They only contain the data necessary to instantiate or update a view.
UILabel.describe { config in
config[\.text] = "Hello, world"
config[\.textColor] = .orange
}
// Or...
ViewDescription(UILabel.self) { config in
config[\.text] = "Hello, world"
config[\.textColor] = .orange
}
In both cases, the last argument is a closure responsible for configuring the view type. The argument passed into the closure is a value of the type ViewDescription.Configuration
extension ViewDescription {
public struct Configuration<View: UIView> {}
}
UITableView.describe { config in
config.builder = {
UITableView(frame: .zero, style: .plain)
}
}
UIView.describe { config in
config[\.backgroundColor] = .magenta
}
UIView.describe { config in
config.apply { view in
view.layer.masksToBounds = true
}
}
private class MyCustomView: UIView {
let mySubview = UIView()
}
MyCustomView.describe { config in
config.contentView = { myCustomView in
myCustomView.mySubview
}
}
UIView.describe { config in
config.layoutTransition = .specific(AnimationAttributes())
config.appearingTransition = .scale
config.disappearingTransition = .fade
}