anvil icon indicating copy to clipboard operation
anvil copied to clipboard

Renderable lifecycle

Open zserge opened this issue 8 years ago • 4 comments

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

zserge avatar May 06 '16 02:05 zserge

+1

graknol avatar May 06 '16 07:05 graknol

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

wellguimaraes avatar Jul 01 '16 06:07 wellguimaraes

+1 for React-like events

concernedrat avatar Nov 08 '16 15:11 concernedrat

+1

amoikevin avatar Jan 20 '17 06:01 amoikevin