mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 10:56:54 -04:00
implement navigation
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
|
||||
fun AppCompatActivity.findNavHostFragment(@IdRes id: Int) =
|
||||
supportFragmentManager.findFragmentById(id) as NavHostFragment
|
||||
|
||||
fun Fragment.findNavHostFragment(@IdRes id: Int) =
|
||||
childFragmentManager.findFragmentById(id) as NavHostFragment
|
||||
|
||||
fun Fragment.findNavController(@IdRes id: Int) =
|
||||
androidx.navigation.Navigation.findNavController(view?.findViewById(id) ?: viewNotFound(id, this))
|
||||
|
||||
private fun viewNotFound(@IdRes id: Int, fragment: Fragment): Nothing = throw IllegalStateException(
|
||||
"View ID $id at '${fragment::class.java.simpleName}' not found."
|
||||
)
|
||||
Reference in New Issue
Block a user