0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

BottomSheetDialogFragmentとDaggerFragmentを両方使う方法

Posted at

BottomSheetDialogFragment・DaggerFragmentともに、使うには継承する必要があります。
ただ、Kotlinは多重継承ができないため、一見すると両方同時に使えなさそうにみえます。

結論から言うと、DaggerFragmentのコードをベースに、BottomSheetDialogFragmentを継承することで両方同時に使用できます。

open class BaseBottomSheetDialogFragment : BottomSheetDialogFragment(), HasAndroidInjector {

    @Inject
    lateinit var androidInjector: DispatchingAndroidInjector<Any>

    override fun onAttach(context: Context) {
        super.onAttach(context)
        AndroidSupportInjection.inject(this)
    }

    override fun androidInjector(): AndroidInjector<Any> {
        return androidInjector
    }

}

参考:
https://github.com/google/dagger/blob/master/java/dagger/android/support/DaggerFragment.java
https://gist.github.com/baruckis/279ddf998d3aae6a6b9e8c30b51b0811

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?