Skip to content

Commit 04c13c7

Browse files
authored
Merge pull request #718 from LachlanMcKee/global-plugins
Introduced global plugins, added GlobalNodeLifecycleAware
2 parents 7911ad9 + 65bd959 commit 04c13c7

File tree

6 files changed

+22
-3
lines changed

6 files changed

+22
-3
lines changed

.github/workflows/build_1.x.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
./gradlew connectedCheck
126126
- name: Upload failed instrumentation artifacts
127127
if: failure()
128-
uses: actions/upload-artifact@v2
128+
uses: actions/upload-artifact@v3
129129
with:
130130
name: instrumentation-failures
131131
path: |

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
## Pending changes
44

5+
## 1.5.1
6+
57
- [#705](https://github.com/bumble-tech/appyx/pull/705)**Fixed**: ChildAware extension functions now allow Any type as a parameter
68
- [#716](https://github.com/bumble-tech/appyx/pull/716)**Updated**: Kotlin (2.0.20), Compose Compiler (now implicit from Kotlin), Coroutines (1.9.0-RC.2), AGP (8.5.2), numerous Androidx libs
9+
- [#718](https://github.com/bumble-tech/appyx/pull/718)**Added**: Introduced global plugins for all nodes and added [GlobalNodeLifecycleAware] which is contains the node in the callback.
10+
11+
<div style="text-align: center"><small>18 Nov 2024</small></div>
712

813
---
914

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.caching=true
33
org.gradle.parallel=true
44
android.useAndroidX=true
55
kotlin.code.style=official
6-
library.version=1.5.0
6+
library.version=1.5.1

libraries/core/src/main/kotlin/com/bumble/appyx/Appyx.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package com.bumble.appyx
22

33
import com.bumble.appyx.core.children.ChildEntry
4+
import com.bumble.appyx.core.plugin.Plugin
45

56
object Appyx {
67

78
var exceptionHandler: ((Exception) -> Unit)? = null
89
var defaultChildKeepMode: ChildEntry.KeepMode = ChildEntry.KeepMode.KEEP
910

11+
/**
12+
* Plugins that are applied to all Nodes.
13+
*/
14+
var globalPlugins: List<Plugin> = emptyList()
15+
1016
fun reportException(exception: Exception) {
1117
val handler = exceptionHandler
1218
if (handler != null) {

libraries/core/src/main/kotlin/com/bumble/appyx/core/node/Node.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.bumble.appyx.core.modality.AncestryInfo
2727
import com.bumble.appyx.core.modality.BuildContext
2828
import com.bumble.appyx.core.plugin.BackPressHandler
2929
import com.bumble.appyx.core.plugin.Destroyable
30+
import com.bumble.appyx.core.plugin.GlobalNodeLifecycleAware
3031
import com.bumble.appyx.core.plugin.NodeLifecycleAware
3132
import com.bumble.appyx.core.plugin.NodeReadyObserver
3233
import com.bumble.appyx.core.plugin.Plugin
@@ -57,7 +58,7 @@ open class Node @VisibleForTesting internal constructor(
5758
@Suppress("LeakingThis") // Implemented in the same way as in androidx.Fragment
5859
private val nodeLifecycle = NodeLifecycleImpl(this)
5960

60-
val plugins: List<Plugin> = plugins + listOfNotNull(this as? Plugin)
61+
val plugins: List<Plugin> = plugins + Appyx.globalPlugins + listOfNotNull(this as? Plugin)
6162

6263
val ancestryInfo: AncestryInfo =
6364
buildContext.ancestryInfo
@@ -115,6 +116,7 @@ open class Node @VisibleForTesting internal constructor(
115116
updateLifecycleState(Lifecycle.State.CREATED)
116117
plugins<NodeReadyObserver<Node>>().forEach { it.init(this) }
117118
plugins<NodeLifecycleAware>().forEach { it.onCreate(lifecycle) }
119+
plugins<GlobalNodeLifecycleAware>().forEach { it.onCreate(this, lifecycle) }
118120
}
119121

120122
@Composable
@@ -179,6 +181,7 @@ open class Node @VisibleForTesting internal constructor(
179181
retainedInstanceStore.clearStore(id)
180182
}
181183
plugins<Destroyable>().forEach { it.destroy() }
184+
plugins<GlobalNodeLifecycleAware>().forEach { it.onDestroy(this) }
182185
}
183186
}
184187

libraries/core/src/main/kotlin/com/bumble/appyx/core/plugin/Plugins.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ interface NodeLifecycleAware : Plugin {
2323
fun onCreate(lifecycle: Lifecycle) {}
2424
}
2525

26+
interface GlobalNodeLifecycleAware : Plugin {
27+
fun onCreate(node: Node, lifecycle: Lifecycle) {}
28+
fun onDestroy(node: Node) {}
29+
}
30+
2631
interface UpNavigationHandler : Plugin {
2732
fun handleUpNavigation(): Boolean = false
2833
}

0 commit comments

Comments
 (0)