implement navigation

This commit is contained in:
Carlos Martinez
2020-02-02 14:59:33 -03:00
parent 14e9eff325
commit 6a2722177e
13 changed files with 105 additions and 43 deletions

View File

@@ -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."
)