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.javaCREATE, 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).
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:
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).