Skip to content

Commit 2df4805

Browse files
committed
Introduced global plugins, added GlobalNodeLifecycleAware and expose view
1 parent 9a00ba8 commit 2df4805

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
1414
org.gradle.caching=true
1515
org.gradle.parallel=true
1616

17-
VERSION_NAME=0.40.2
17+
VERSION_NAME=0.40.3
1818

1919
android.useAndroidX=true
2020
android.defaults.buildfeatures.buildconfig=true

libraries/rib-base/src/main/java/com/badoo/ribs/core/Node.kt

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.badoo.ribs.core.modality.BuildContext
1818
import com.badoo.ribs.core.modality.BuildParams
1919
import com.badoo.ribs.core.plugin.AndroidLifecycleAware
2020
import com.badoo.ribs.core.plugin.BackPressHandler
21+
import com.badoo.ribs.core.plugin.GlobalNodeLifecycleAware
2122
import com.badoo.ribs.core.plugin.NodeAware
2223
import com.badoo.ribs.core.plugin.NodeLifecycleAware
2324
import com.badoo.ribs.core.plugin.Plugin
@@ -100,7 +101,7 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
100101
}
101102

102103
val plugins: List<Plugin> =
103-
buildContext.defaultPlugins(this) + plugins + if (this is Plugin) listOf(this) else emptyList()
104+
buildContext.defaultPlugins(this) + RIBs.globalPlugins + plugins + if (this is Plugin) listOf(this) else emptyList()
104105

105106
internal open val activationMode: ActivationMode =
106107
buildContext.activationMode
@@ -136,6 +137,7 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
136137

137138
internal fun onBuildFinished() {
138139
plugins.filterIsInstance<NodeLifecycleAware>().forEach { it.onBuild() }
140+
plugins.filterIsInstance<GlobalNodeLifecycleAware>().forEach { it.onBuild(this) }
139141
parent?.onChildBuilt(this)
140142
}
141143

@@ -148,6 +150,9 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
148150
plugins
149151
.filterIsInstance<NodeLifecycleAware>()
150152
.forEach { it.onCreate(lifecycleManager.ribLifecycle.lifecycle) }
153+
plugins
154+
.filterIsInstance<GlobalNodeLifecycleAware>()
155+
.forEach { it.onCreate(this, lifecycleManager.ribLifecycle.lifecycle) }
151156
lifecycleManager.onCreate()
152157
}
153158

@@ -218,6 +223,7 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
218223

219224
lifecycleManager.onDestroy()
220225
plugins.filterIsInstance<NodeLifecycleAware>().forEach { it.onDestroy() }
226+
plugins.filterIsInstance<GlobalNodeLifecycleAware>().forEach { it.onDestroy(this) }
221227
if (!isRecreating) {
222228
retainedInstanceStore.removeAll(identifier)
223229
}
@@ -247,6 +253,7 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
247253

248254
internal fun onAttachFinished() {
249255
plugins.filterIsInstance<NodeLifecycleAware>().forEach { it.onAttach() }
256+
plugins.filterIsInstance<GlobalNodeLifecycleAware>().forEach { it.onAttach(this) }
250257
}
251258

252259
open fun onAttachChildNode(child: Node<*>) {
@@ -407,6 +414,8 @@ open class Node<V : RibView> @VisibleForTesting internal constructor(
407414
override val lifecycle: Lifecycle
408415
get() = lifecycleManager.lifecycle
409416

417+
fun getView() : V? = view
418+
410419
fun <P> plugins(pClass: Class<P>): List<P> =
411420
plugins.filterIsInstance(pClass)
412421

libraries/rib-base/src/main/java/com/badoo/ribs/core/plugin/Plugin.kt

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ interface NodeLifecycleAware : Plugin {
3030
fun onDestroy() {}
3131
}
3232

33+
interface GlobalNodeLifecycleAware : Plugin {
34+
fun onBuild(node: Node<*>) {}
35+
36+
fun onCreate(node: Node<*>, nodeLifecycle: Lifecycle) {}
37+
38+
fun onAttach(node: Node<*>) {}
39+
40+
fun onDestroy(node: Node<*>) {}
41+
}
42+
3343
interface ViewAware<V : RibView> : Plugin {
3444
fun onViewCreated(view: V, viewLifecycle: Lifecycle) {}
3545
}

libraries/rib-base/src/main/java/com/badoo/ribs/util/RIBs.kt

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.badoo.ribs.util
33
import android.util.Log
44
import androidx.annotation.VisibleForTesting
55
import com.badoo.ribs.android.requestcode.RequestCodeBasedEventStream
6+
import com.badoo.ribs.core.plugin.Plugin
67

78
object RIBs {
89

@@ -28,6 +29,11 @@ object RIBs {
2829
}
2930
}
3031

32+
/**
33+
* Plugins that are applied to all Nodes.
34+
*/
35+
var globalPlugins: List<Plugin> = emptyList()
36+
3137
@VisibleForTesting
3238
fun clearErrorHandler() {
3339
_errorHandler = null

0 commit comments

Comments
 (0)