Android. How to get instance of fragment using navigation component?

385 views Asked by At

I'm using MVVM and navigation component. Here is my code to navigate to another fragment:

NavHostFragment.findNavController(this).navigate((R.id.navigation_photo_detail)

But in my PhotoDetailFragment there are also methods that require getting an interface:

class PhotoDetailFragment: BaseViewModelFragment() {
// here some code...

fun setPhotoScaleStrategy(photoScaleStrategy: PhotoScaleStrategy) { // this is I need to call when navigate

}

}

In order to call these methods I must get a fragment instance. How can this be done using navigation component ?

Please help me.

P.S. PhotoScaleStrategy is the implementation of strategy pattern. I have several algorithms for image scaling. My fragment needs to receive a concrete implementation of the strategy through an interface. I want it to not know what specific scaling algorithm it uses, but just do the job

0

There are 0 answers