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

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

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

import de.halfbit.componental.lifecycle.Lifecycle

public interface BackNavigationOwner {
    public val backNavigation: BackNavigation

    public companion object {
        public fun create(lifecycle: Lifecycle): BackNavigationOwner =
            object : BackNavigationOwner {
                override val backNavigation: BackNavigation =
                    object : BackNavigation {
                        override fun register(onNavigateBack: OnNavigateBack) {
                            lifecycle.subscribe(
                                object : Lifecycle.Subscriber.Callbacks {
                                    override fun onResume() {
                                        BackNavigation.register(onNavigateBack)
                                    }

                                    override fun onPause() {
                                        BackNavigation.unregister(onNavigateBack)
                                    }
                                }
                            )
                        }
                    }
            }
    }
}

public fun BackNavigationOwner.onNavigateBack(onNavigateBack: OnNavigateBack) {
    backNavigation.register(onNavigateBack)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy