Skip to content

Commit

Permalink
less view lifecycle events
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Jul 8, 2020
1 parent 6ece0c5 commit e7b9357
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ class ViewComponentClassBuilder(
"""
render(false)
startObservations()
viewTreeObserver.addOnGlobalLayoutListener {
if (lifecycleRegistry.currentState != Lifecycle.State.RESUMED)
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_RESUME)
}
""".trimIndent(),
ClassName("androidx.lifecycle", "Lifecycle")
""".trimIndent()
)
build()
}
Expand Down Expand Up @@ -176,13 +171,11 @@ class ViewComponentClassBuilder(
"""
super.onAttachedToWindow()
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_CREATE)
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_START)
if (isDetachedFromWindow) {
isDetachedFromWindow = false
startObservations()
}
""".trimIndent(),
ClassName("androidx.lifecycle", "Lifecycle"),
ClassName("androidx.lifecycle", "Lifecycle")
)
build()
Expand All @@ -194,14 +187,10 @@ class ViewComponentClassBuilder(
addCode(
"""
super.onDetachedFromWindow()
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_PAUSE)
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_STOP)
lifecycleRegistry.handleLifecycleEvent(%T.Event.ON_DESTROY)
viewModel.onCleared()
isDetachedFromWindow = true
""".trimIndent(),
ClassName("androidx.lifecycle", "Lifecycle"),
ClassName("androidx.lifecycle", "Lifecycle"),
ClassName("androidx.lifecycle", "Lifecycle")
)
build()
Expand Down

0 comments on commit e7b9357

Please sign in to comment.