LayoutKit
LayoutKit copied to clipboard
Make the designated initializers with a viewClass argument public
Hi there,
Is there any reason why the initializers, containing the viewClass argument, are marked internal? It would be extremely useful if they were exposed as public.
Reason: Let's say for example you want to define a SizeLayout<UITextField> and you want to determine what UITextField.Type you want to use at runtime, the current public initializers for SizeLayout prevents you from doing so.
func createSizeLayout<T: UITextField>(type: T.Type) -> SizeLayout<T> {
.... logic for creation here ...
}
let textFieldLayout = createSizeLayout(type: YourCustomTextField.self) // this inferred as SizeLayout<UITextField>
// if you follow the initialization steps, the used initializer in BaseLayout is:
public init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, config: ((V) -> Void)?) {
self.alignment = alignment
self.flexibility = flexibility
self.viewReuseId = viewReuseId
self.viewClass = V.self
self.config = config
}
// instead of:
init(alignment: Alignment, flexibility: Flexibility, viewReuseId: String? = nil, viewClass: V.Type, config: ((V) -> Void)?) {
self.alignment = alignment
self.flexibility = flexibility
self.viewReuseId = viewReuseId
self.viewClass = viewClass
self.config = config
}
Using the latter will still yield an inferred type of SizeLayout<UITextField>
BUT if you set breakpoints in the config
closure it will be a YourCustomTextField instance.