-
Notifications
You must be signed in to change notification settings - Fork 72
Provided and Custom LifecycleAware Components
Ryan Moelter edited this page Jul 21, 2021
·
4 revisions
Welcome to Magellan! We're working hard on an update; this is the work-in-progress documentation for that update. For the old documentation, see our old wiki page, Magellan 1.x Home. If you have questions/comments/suggestions for the new documentation, please submit an issue and we'll explain ourselves better.
Don’t see something you would want? Feel free to create an issue!
-
ShownScope
: ACoroutineScope
that is valid betweenshow()
andhide()
. Included by default inStep
. -
CreatedScope
: ACoroutineScope
that is valid betweencreate()
anddestroy()
.
-
DialogComponent
: ALifecycleAware
object for showing and hiding dialogs. It will ensure a dialog is shown while the parent isShown
orResumed
until the dialog is explicitly hidden. -
Navigator
: AView
-based navigator with a simple backstack. Handles transitions and the lifecycle of childNavigable
s. Useful for mostJourney
s.- If you want to use a custom
Navigator
implementation in a Journey of yours, create your ownLifecycleAwareComponent
that navigates how you want and attach it to aStep
of yours. A more in depth guide will come soon, feel free to create an issue to get it prioritized higher.
- If you want to use a custom
-
ComposeNavigator
(coming soon): Same asNavigator
above, but for Jetpack Compose. -
LifecycleLimiter
andLifecycleRegistry
: The components used byLifecycleAwareComponent
to keep track of its children. You probably don't want to use these directly.
-
RxDisposer
: An RxJava 2 composite disposable that is disposed inhide()
. -
RxUnsubscriber
: An RxJava 1 composite subscription that is unsubscribed inhide()
.
Writing a custom component is easy! Just extend either LifecycleAwareComponent
if you want the ability to have child LifecycleAware
objects, or simply LifecycleAware
if that's not necessary. Most of the time, you want to use LifecycleAwareComponent
so it's easy to add children when necessary.
class MyExampleComponent : LifecycleAwareComponent() {
val shownScope by lifecycle(ShownScope())
override fun onShow(context: Context) {
// Do some set up...
shownScope.launch { ... }
}
override fun onHide(context: Context) {
// Do some tear down...
}
}
class MyExampleComponent : LifecycleAware {
override fun show(context: Context) {
// Do some set up...
}
override fun hide(context: Context) {
// Do some tear down...
}
}
-
by lifecycle(…)
: Property delegate that attaches the givenLifecycleAware
component to this lifecycle immediately. Can be avar
to allow for overriding components in tests. -
by lateinitLifecycle<T>()
: Property delegate that acts like alateinit var
. -
by lifecycleWithContext { context -> … }
: Property delegate that creates aLifecycleAware
object using the provided lambda duringshow()
, and removes the reference duringhide()
. Useful forView
s and otherContext
-dependent objects. Strong guarantee to use anActivity
context. -
LifecycleOwner.attachToLifecycle(…)
: The method that all these property delegates use under the hood. Most of the time, you want to use one of the delegates, but for the times you don't, you can use this.
Made with 💚 by the Wealthfront Android Team.