anvil-ui / anvil

Minimal UI library for Android inspired by React
MIT License
1.45k stars 90 forks source link

Extending anvil #101

Open FunnyDevs opened 7 years ago

FunnyDevs commented 7 years ago

Is possibile a tutorial to extend Anvil with custom views (like Anko)???

zserge commented 7 years ago

@FunnyDevs it is possible to extend Anvil with custom views, although maybe not like with Anko.

  1. You can always build "components", self-contained ViewGroups (extended from RenderableView).
  2. You can always mounts custom views into existing renderables, like v(MyCustomView.class, () -> {...}).
  3. You can now create your own Anvil.ViewFactory implementations, register them, and then use them to build custom classes on demand (e.g. if you class constructor is now just View(Context), but something more complex, like using styles etc.

Starting with Anvil 0.5.0 (just released it today) you may set custom attributes as well, just do attr("myAttr", someValue) and that will call setMyAttr(someValue) on your view if fthe value has been changed since the last call. In the worst case that will use reflection, but you may also register your own Anvil.AttributeSetter to handle your custom attributes and speed up things.

FunnyDevs commented 7 years ago

i would like to do like Anko that maps custom function (like toast(), dialog()), but with custom view: customview() Must i do a custom Anvil.ViewFactory???

Is there a changelog of new release???

Thanks