Skip to content

Commit bb1991f

Browse files
committed
More log about Node lifecycle. Will help to track user navigation.
1 parent 21f9093 commit bb1991f

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

appnav/src/main/kotlin/io/element/android/appnav/NotLoggedInFlowNode.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import android.os.Parcelable
2020
import androidx.compose.runtime.Composable
2121
import androidx.compose.ui.Modifier
2222
import com.bumble.appyx.core.composable.Children
23-
import com.bumble.appyx.core.lifecycle.subscribe
2423
import com.bumble.appyx.core.modality.BuildContext
2524
import com.bumble.appyx.core.node.Node
2625
import com.bumble.appyx.core.plugin.Plugin
@@ -35,7 +34,6 @@ import io.element.android.libraries.architecture.BackstackNode
3534
import io.element.android.libraries.architecture.animation.rememberDefaultTransitionHandler
3635
import io.element.android.libraries.di.AppScope
3736
import kotlinx.parcelize.Parcelize
38-
import timber.log.Timber
3937

4038
@ContributesNode(AppScope::class)
4139
class NotLoggedInFlowNode @AssistedInject constructor(
@@ -51,13 +49,6 @@ class NotLoggedInFlowNode @AssistedInject constructor(
5149
buildContext = buildContext,
5250
plugins = plugins,
5351
) {
54-
init {
55-
lifecycle.subscribe(
56-
onCreate = { Timber.v("OnCreate") },
57-
onDestroy = { Timber.v("OnDestroy") }
58-
)
59-
}
60-
6152
sealed interface NavTarget : Parcelable {
6253
@Parcelize
6354
object OnBoarding : NavTarget

libraries/architecture/src/main/kotlin/io/element/android/libraries/architecture/BackstackNode.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package io.element.android.libraries.architecture
1919
import androidx.compose.runtime.Stable
2020
import com.bumble.appyx.core.children.ChildEntry
2121
import com.bumble.appyx.core.modality.BuildContext
22+
import com.bumble.appyx.core.node.Node
2223
import com.bumble.appyx.core.node.ParentNode
2324
import com.bumble.appyx.core.plugin.Plugin
2425
import com.bumble.appyx.navmodel.backstack.BackStack
@@ -39,4 +40,15 @@ abstract class BackstackNode<NavTarget : Any>(
3940
buildContext = buildContext,
4041
plugins = plugins,
4142
childKeepMode = childKeepMode,
42-
)
43+
) {
44+
override fun onBuilt() {
45+
super.onBuilt()
46+
lifecycle.logLifecycle(this::class.java.simpleName)
47+
whenChildAttached<Node> { _, child ->
48+
// BackstackNode will be logged by their parent.
49+
if (child !is BackstackNode<*>) {
50+
child.lifecycle.logLifecycle(child::class.java.simpleName)
51+
}
52+
}
53+
}
54+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2023 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.element.android.libraries.architecture
18+
19+
import androidx.lifecycle.Lifecycle
20+
import com.bumble.appyx.core.lifecycle.subscribe
21+
import timber.log.Timber
22+
23+
fun Lifecycle.logLifecycle(name: String) {
24+
subscribe(
25+
onCreate = { Timber.tag("Lifecycle").d("onCreate $name") },
26+
onPause = { Timber.tag("Lifecycle").d("onPause $name") },
27+
onResume = { Timber.tag("Lifecycle").d("onResume $name") },
28+
onDestroy = { Timber.tag("Lifecycle").d("onDestroy $name") },
29+
)
30+
}

0 commit comments

Comments
 (0)