Skip to content
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

Closed
wangii opened this issue Feb 28, 2015 · 13 comments
Closed

is it abandoned due to reactnative? #1

wangii opened this issue Feb 28, 2015 · 13 comments
Labels

Comments

@wangii
Copy link

wangii commented Feb 28, 2015

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.

@zserge
Copy link
Collaborator

zserge commented Feb 28, 2015

Hi,

It's not really abandoned at all! I just had a long business trip recently
and still have no time to write any code for this project.

Still, the project is mostly usable in its current state, and I don't see
react native to be a replacement for it due to the reasons you mentioned.
Also I don't think android developers will be happy to switch immediately
to js from java and leave all their favorite tools behind.

So the core of Anvil (android virtual layout) is now done. I even started
using it in a couple of real life projects. But if you have any ideas of
how to improve it - feel free to suggest or implement them.

Regards,
Serge
On Feb 28, 2015 8:51 PM, "wangii" notifications@github.com wrote:

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.


Reply to this email directly or view it on GitHub
#1.

@wangii
Copy link
Author

wangii commented Feb 28, 2015

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,
Linan

@zserge
Copy link
Collaborator

zserge commented Mar 24, 2015

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.
I was considering two versions of syntax:

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).

@zserge
Copy link
Collaborator

zserge commented Mar 24, 2015

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"));
}

@zserge
Copy link
Collaborator

zserge commented Mar 24, 2015

What I like a lot is that all view attributes are evaluated in runtime, so basically you can write your own class Colors with some color constants and calculate derived colors for your views, e.g backgroundColor(darken(Colors.PRIMARY_COLOR, 0.2f)) will set background to the primary "accent" color of your color scheme, but 20% darker.

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: v(Button.class, squareStyle(), text("Click me")), like:

public static AttrNode squareStyle() {
    return new SimpleAttrNode(null) {
      public void apply(View v) {
        // Modify view size here
      }
    };
}

@wangii
Copy link
Author

wangii commented Mar 24, 2015

Thank you very much for the detailed explanation. The AttrNode generator approach is neat!

@zserge
Copy link
Collaborator

zserge commented Mar 25, 2015

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

@wangii
Copy link
Author

wangii commented Mar 25, 2015

exactly. I'm reading the componentkit doc and feel the same: CKComponentViewConfiguration is identical to ViewNode.

@wangii
Copy link
Author

wangii commented Mar 26, 2015

Here is a crazy idea: replace function name v with $.

@wangii wangii closed this as completed Mar 26, 2015
@wangii wangii reopened this Mar 26, 2015
@zserge
Copy link
Collaborator

zserge commented Mar 26, 2015

Ha, I was actually considering the $ function name, since both $ and _ seem to be allowed by Java grammar. It could give a more jQuerish look to the code. However, they are strongly discouraged (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/variables.html) since they correlate with inner class separator, e.g. Foo$Bar.class.

So I came to a short method name, like in similar JS frameworks. Mithril uses m, Mercury uses h, Anvil uses v for "view", or for a "virtual view".

@wangii
Copy link
Author

wangii commented Mar 26, 2015

I feel Anvil is good but not "sexy" enough. it's the reason I suggest to use $ as function name. here is another crazy idea to spice it up:

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?

@zserge
Copy link
Collaborator

zserge commented Mar 26, 2015

I like this more that $. Still, I believe that "core" Anvil should be just v() function for layouts.
There may exist another module (also, part of Anvil) with helpers (like Props.java, generated from android.jar), that would export static methods with the sugar you suggest.

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 v(SomeLayout.class, ...), but importing that sugar module, say, Views.java you can write someLayout(...). Similar syntax extension exists in Mithril, too, without changing the core syntax.

@zserge zserge closed this as completed Mar 27, 2015
@zserge
Copy link
Collaborator

zserge commented Mar 27, 2015

I'm closing this, but I opened some new issues that I'm about to fix soon. Feel free to discuss those.
And if you have a suggestion about Anvil - don't hesitate to start a new issue with 'enhancement' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants