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.
let description = UILabel.describe { config in
config[\.text] = "Hello, world"
config[\.textColor] = .orange
}
// Or...
let description = 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> {}
}
let description = UITableView.describe { config in
config.builder = { UITableView(frame: .zero, style: .plain) }
}
let description = UIView.describe { config in
config[\.backgroundColor] = .magenta
}
let description = UIView.describe { config in
config.apply { view in
view.layer.masksToBounds = true
}
}
let description = MyCustomView.describe { config in
config.contentView = { $0.childContainerView }
}
let description = UIView.describe { config in
config.layoutTransition = .specific(AnimationAttributes())
config.appearingTransition = .scale
config.disappearingTransition = .fade
}