[AndroidX] Introducing koin-androidx-fragment with Koin fragmentFactory
See original GitHub issueHi All,
the 2.1.0-alpha-3
contains a new package: koin-androidx-fragment
This will allow to inject your Fragment
with Koin 👍
How to use that?
- setup your
KoinFragmentFactory
at start withfragmentFactory()
:
startKoin {
androidLogger(Level.DEBUG)
androidContext(this@MainApplication)
// setup a KoinFragmentFactory instance
fragmentFactory()
modules(...)
}
- Use constructor for you
Fragment
class:
class MyFragment(val myService: MyService) : Fragment()
- Declare it in Koin (factory or scoped instance):
val appModule = module {
factory { MyFragment(get()) }
}
- Setup the factory from your activity & just use it:
Setup the Koin factory from your activity:
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Koin Fragment Factory
setupKoinFragmentFactory()
super.onCreate(savedInstanceState)
//...
}
}
Get your Fragment:
supportFragmentManager.beginTransaction()
.replace(R.id.mvvm_frame, MyFragment::class.java, null, null)
.commit()
For more details (like using it with scope): https://doc.insert-koin.io/#/koin-android/fragment-factory
The package should be available soon 🎉
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Benefit from AndroidX FragmentFactory with Koin
Implementing custom FragmentFactory powered by Koin. Brief look on a new Android API FragmentFactory and look how we can use it and achieve ......
Read more >Fragment Factory - Koin
Since AndroidX has released androidx.fragment packages family to extend features ... Since 2.1.0-alpha-3 version, has been introduce the FragmentFactory ...
Read more >Koin Fragmentfactory Fails To Handle Activity Recreation
To declare a Fragment instance just declare it as a fragment in your Koin module and use constructor injection.Given a Fragment class: Copy.class...
Read more >AndroidX FragmentFactory and Android Fragments - Medium
Fragments provide core Android app functionality. With the introduction of AndroidX in Android Jetpack, fragments got an overhaul and under the covers, ...
Read more >CHANGELOG.md · Gitee 极速下载/koin - Gitee.com
koin-androidx-fragment. [FIXED] Add fallback for instantiate function in FragmentFactory - https://github.com/InsertKoinIO/koin/pull/742. koin-test.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
nothing, manifest is buggy in alpha-3. Check alpha-4 soon this week for a fix 👍
Amazing work!
For some reason, the package contains
org.koin.androidx.viewmodel.BuildConfig
.This results in the following error when adding both
koin-androidx-fragment
andkoin-androidx-viewmodel
as dependencies:Am I doing anything wrong?