I need to generate style based on provided string.
For example "color:red;fontsize:12"
to parse and apply to Text element
const ss = StyleSheet.create({
someStyle: {
color:'red',
fontSize: 12,
}
});
What I could find is that only values can be dynamic, not properties.
let a = 'red';
let b = 12;
const ss = StyleSheet.create({
someStyle: {
color: a,
fontSize: b,
}
});
Something like this could be great if there is any option.
const ss = StyleSheet.create();
let someStyle = ss.addChild("someStyle");
someStyle.addChild("color", "red");
someStyle.addChild("fontsize", "12");
Thank you.
2
Answers
Found solution.
Simple example:
More complex:
So key is that inside [ ] can be property name.
and now can add as many key-value pairs as needed.
Thank you!
you can do similiar to my component