All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.de.halfbit.componental.back.BackNavigation.kt Maven / Gradle / Ivy

/** Copyright 2024 Halfbit GmbH, Sergej Shafarenka */
package de.halfbit.componental.back

public interface BackNavigation {
    public fun register(onNavigateBack: OnNavigateBack)

    public companion object {
        private val callbacks: MutableList = mutableListOf()

        internal fun register(callback: OnNavigateBack) {
            callbacks += callback
        }

        internal fun unregister(callback: OnNavigateBack) {
            callbacks -= callback
        }

        /** To be called by the screen holding compose UI, e.g. by an activity on android. */
        public fun dispatchOnNavigateBack() {
            callbacks.toList().lastOrNull()?.onNavigateBack()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy