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

Renderable lifecycle #68

Open
zserge opened this issue May 6, 2016 · 4 comments
Open

Renderable lifecycle #68

zserge opened this issue May 6, 2016 · 4 comments

Comments

@zserge
Copy link
Collaborator

zserge commented May 6, 2016

Anvil allows writing components as lambdas or as RenderableViews. Some components may be stateful and may depent on the hosting Activity/Fragment/... lifecycle.

Currenclty, RenderableView has onAttachedToWindow and onDetachedFromWindow hooks, but they are not helpful for saving/restoring instance state, for handling pause/resume events etc.

How about adding a few functions to BaseDSL that would allow to register a listener to a certain type of lifecycle events, e.g:

linearLayout(() -> {
  onPause(() -> {
    // handle pause here
  });
  onResume(() -> {
    // handle resume here
  });
});

BaseDSL would keep a static list of weak references to all listeners, also Anvil would provide certain functions to emit lifecycle events, e.g. Anvil.pause(), Anvil.resume(), Anvil.save(), Anvil.restore().

I'm not sure which lifecycle events should be supports and about details of the implementation, but ideally it should support Activities, Fragments and Conductor controllers.

Other libraries provide either a full set of events (RxLifeCycle, Navi etc) - https://github.com/trello/navi/blob/master/navi/src/main/java/com/trello/navi/Event.java
CREATE, START, RESUME, PAUSE, STOP, DESTROY (Activity lifecycle), ATTACH, CREATE, CREATE_VIEW, START, RESUME, PAUSE, STOP, DESTROY_VIEW, DESTROY, DETACH (Fragment lifecycle) or a small subset of those (see: Conductor).

@graknol
Copy link

graknol commented May 6, 2016

+1

@wellguimaraes
Copy link

wellguimaraes commented Jul 1, 2016

React like events would be welcome (componentDidMount, componentWillMount, componentWillUpdate, componentDidUpdate)

@concernedrat
Copy link

+1 for React-like events

@amoikevin
Copy link

+1

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

No branches or pull requests

5 participants