Skip to content

Commit

Permalink
Merge pull request #718 from LachlanMcKee/global-plugins
Browse files Browse the repository at this point in the history
Introduced global plugins, added GlobalNodeLifecycleAware
  • Loading branch information
LachlanMcKee authored Nov 18, 2024
2 parents 7911ad9 + 65bd959 commit 04c13c7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_1.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ jobs:
./gradlew connectedCheck
- name: Upload failed instrumentation artifacts
if: failure()
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: instrumentation-failures
path: |
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

## Pending changes

## 1.5.1

- [#705](https://github.com/bumble-tech/appyx/pull/705)**Fixed**: ChildAware extension functions now allow Any type as a parameter
- [#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
- [#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.

<div style="text-align: center"><small>18 Nov 2024</small></div>

---

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.caching=true
org.gradle.parallel=true
android.useAndroidX=true
kotlin.code.style=official
library.version=1.5.0
library.version=1.5.1
6 changes: 6 additions & 0 deletions libraries/core/src/main/kotlin/com/bumble/appyx/Appyx.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.bumble.appyx

import com.bumble.appyx.core.children.ChildEntry
import com.bumble.appyx.core.plugin.Plugin

object Appyx {

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

/**
* Plugins that are applied to all Nodes.
*/
var globalPlugins: List<Plugin> = emptyList()

fun reportException(exception: Exception) {
val handler = exceptionHandler
if (handler != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.bumble.appyx.core.modality.AncestryInfo
import com.bumble.appyx.core.modality.BuildContext
import com.bumble.appyx.core.plugin.BackPressHandler
import com.bumble.appyx.core.plugin.Destroyable
import com.bumble.appyx.core.plugin.GlobalNodeLifecycleAware
import com.bumble.appyx.core.plugin.NodeLifecycleAware
import com.bumble.appyx.core.plugin.NodeReadyObserver
import com.bumble.appyx.core.plugin.Plugin
Expand Down Expand Up @@ -57,7 +58,7 @@ open class Node @VisibleForTesting internal constructor(
@Suppress("LeakingThis") // Implemented in the same way as in androidx.Fragment
private val nodeLifecycle = NodeLifecycleImpl(this)

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

val ancestryInfo: AncestryInfo =
buildContext.ancestryInfo
Expand Down Expand Up @@ -115,6 +116,7 @@ open class Node @VisibleForTesting internal constructor(
updateLifecycleState(Lifecycle.State.CREATED)
plugins<NodeReadyObserver<Node>>().forEach { it.init(this) }
plugins<NodeLifecycleAware>().forEach { it.onCreate(lifecycle) }
plugins<GlobalNodeLifecycleAware>().forEach { it.onCreate(this, lifecycle) }
}

@Composable
Expand Down Expand Up @@ -179,6 +181,7 @@ open class Node @VisibleForTesting internal constructor(
retainedInstanceStore.clearStore(id)
}
plugins<Destroyable>().forEach { it.destroy() }
plugins<GlobalNodeLifecycleAware>().forEach { it.onDestroy(this) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ interface NodeLifecycleAware : Plugin {
fun onCreate(lifecycle: Lifecycle) {}
}

interface GlobalNodeLifecycleAware : Plugin {
fun onCreate(node: Node, lifecycle: Lifecycle) {}
fun onDestroy(node: Node) {}
}

interface UpNavigationHandler : Plugin {
fun handleUpNavigation(): Boolean = false
}
Expand Down

0 comments on commit 04c13c7

Please sign in to comment.