Components can have their props come from regular Android style resources in a similar way to an Android View's AttributeSet constructor. It enables developers to define static prop values or prop defaults directly from style resources.
Style support can be implemented using the
@OnLoadStyle method in your component spec. The first argument is a ComponentContext which you can use to retrieve a TypedArray with the style resource values. The rest of the arguments should be Outputs matching the name and type of the props to which you want to set values.
For example, in order to implement style support for the two props of the MyComponentSpec above, you'd first define the styleable attributes as usual:
Then you can collect the values of these attributes in your
@OnLoadStyle method as follows:
With this, you'll be able to define
prop2 in a style:
And use it in
In which case,
prop1 would get the value from the