New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is it abandoned due to reactnative? #1
Comments
Hi, It's not really abandoned at all! I just had a long business trip recently Still, the project is mostly usable in its current state, and I don't see So the core of Anvil (android virtual layout) is now done. I even started Regards,
|
Thanks for the fast reply. I'm glad you are still on it! My question is how to effectively style components? it seems you treat both layout and style the same thing. is there any performance consideration over the decision? thanks, |
Hi and sorry for a very late reply. Yes, I use the same hierarchy for both views and their attributes only because it resembles XML. v(MyLayout.class,
size(FILL, WRAP),
visibility(someFlag ? View.VISIBLE : View.GONE),
v(MyView.class,
size(FILL, WRAP),
text("Some text")); and: v(MyLayout.class)
.size(FILL, WRAP)
.visibility(someFlag ? View.VISIBLE : View.GONE)
.children(v(MyView.class)
.size(FILL, WRAP)
.text("Some text")); The second variant is harder to extend (all the methods should be pre-defined in the v() result object, while in the first variant you can easily use your own node generator methods. So I use the variadic arguments in the v() function, but I check the types, so that child views can be declared for the ViewGroups only (this is checked at compilation time due to some strict typing hacks). |
Now, answering your question how to style views. If your views share the same attributes you can use: public AttrNode myStyle() {
return attrs(size(FILL, WRAP).margin(dip(10), 0), backgroundColor(0xffff0000), gravity(CENTER));
}
public ViewNode view() {
return v(SomeLayout.class,
v(SomeView.class,
buttonStyle(),
text("Foo"),
v(SomeView.class,
buttonStyle(),
text("Bar"));
} |
What I like a lot is that all view attributes are evaluated in runtime, so basically you can write your own class Same about dimensions, e.g. size(parentWidth * 0.8, WRAP) to stretch view horizontally to 80% of the parent. Or if you need square views - you should be able to make your own AttrNode generator that will check measured size of a view and change the layout params of a view to make it look square, e.g: public static AttrNode squareStyle() {
return new SimpleAttrNode(null) {
public void apply(View v) {
// Modify view size here
}
};
} |
Thank you very much for the detailed explanation. The AttrNode generator approach is neat! |
Btw, this iOS library by Facebook seems to be close to the spirit of Anvil (not a big surprise, since Anvil is inspired by Mithril, which is inspired by React) - http://componentkit.org/docs/philosophy.html Probably Anvil could borrow some ideas from there |
exactly. I'm reading the componentkit doc and feel the same: CKComponentViewConfiguration is identical to ViewNode. |
Here is a crazy idea: replace function name |
Ha, I was actually considering the So I came to a short method name, like in similar JS frameworks. Mithril uses |
I feel Anvil is good but not "sexy" enough. it's the reason I suggest to use generate functions like this: public static ViewGroup ViewGroup(INode<? super T> ...args){
return v(ViewGroup.class, args);
}
// and so on with other layout, views then in usage the code could look like: SomeLayout(
SomeView(style, text),
AnotherLayout(
Button(),
Text()
)
); how do you think? |
I like this more that I personally use a lot of custom views and layouts, so there will never be "sugar" functions for those anyway. But for people using standard views and layouts that could be helpful. So in minimal implementation you still do |
I'm closing this, but I opened some new issues that I'm about to fix soon. Feel free to discuss those. |
react native has been announced over a month. I don't think it'll be ready any time soon. besides, a pure java implementation will still have its space due to performance concerns over js-java bridge.
The text was updated successfully, but these errors were encountered: