Skip to content

Commit

Permalink
Expose the ability to set a max lifecycle state for a navigator host'…
Browse files Browse the repository at this point in the history
…s topmost fragment.
  • Loading branch information
jayohms committed Jan 9, 2025
1 parent 4bed53e commit eaeba02
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentOnAttachListener
import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import dev.hotwire.core.config.Hotwire
Expand Down Expand Up @@ -50,6 +51,18 @@ open class NavigatorHost : NavHostFragment(), FragmentOnAttachListener {
return isAdded && !isDetached && childFragmentManager.primaryNavigationFragment != null
}

/**
*
*/
fun setMaxLifecycle(state: Lifecycle.State) {
val currentFragment = childFragmentManager.primaryNavigationFragment ?: return

childFragmentManager
.beginTransaction()
.setMaxLifecycle(currentFragment, state)
.commit()
}

internal fun initControllerGraph() {
navController.apply {
graph = NavigatorGraphBuilder(
Expand Down

0 comments on commit eaeba02

Please sign in to comment.