Hi @nicklockwood !
Layout is really great at creating completely custom and dynamically server-side created GUIs.
However, I would like to alter the GUI appearance at runtime, based on a server-side implementation.
To do so, in my ViewController which hosts a mounted LayoutNode, I created a method that will be called after receiving a message from the network:
func setViewValue(tag: Int, valueName: String, newValue: String) {
guard let baseView = self.view else {
return
}
if let v = baseView.viewWithTag(tag) {
try? v.setValue(newValue, forExpression:valueName)
}
}
This already works flawlessly for String properties, like "title".
However, I would like to set any property type just as Layout does in XML.
I don't need to handle complicated expressions, just be able to specify a UIColor, false/true, geometry or number values...
It seems to me that the steps would be:
search in the layoutNode "expressionTypes" dictionary for the right type
create a LayoutExpression object with the expression name, value, type, and the layoutNode
evaluate() the expression
call setValueForExpression() with the result of the evaluation
However, many of these methods or even entire structs (LayoutExpression) are declared internal.
Is there a ready-made method for doing this? Am I missing something?
Or a major rework would be needed to do this? If yes, can you point me in the right direction? I can come back with a pull request once I have this finished.
Thanks!
This was easier than I thought.
I'm a swift newbie, so my code could be surely improved, but here's the pull request about the new method on UIView+Layout: #186
Hi @nicklockwood ! Layout is really great at creating completely custom and dynamically server-side created GUIs.
However, I would like to alter the GUI appearance at runtime, based on a server-side implementation. To do so, in my ViewController which hosts a mounted LayoutNode, I created a method that will be called after receiving a message from the network:
This already works flawlessly for String properties, like "title". However, I would like to set any property type just as Layout does in XML. I don't need to handle complicated expressions, just be able to specify a UIColor, false/true, geometry or number values...
It seems to me that the steps would be:
However, many of these methods or even entire structs (LayoutExpression) are declared internal. Is there a ready-made method for doing this? Am I missing something? Or a major rework would be needed to do this? If yes, can you point me in the right direction? I can come back with a pull request once I have this finished. Thanks!