Cicerone
Cicerone copied to clipboard
v5 to v6+ migration guide
Cicerone migration to Kotlin in v6.0 changed the project structure seriously, so code that worked for v5 in many cases can't be formally migrated to v6+, and moreover, sometimes even the proper approach to migration is unclear. It would be nice to have some guide or recommendations on suggested migration strategy.
Personally, I have a v5-based project that was written before me and that I now have to support and improve, and this issue really got me stuck. Any help would be appreciated.
Here are some existing patterns I have trouble migrating:
class MyScreen : SupportAppScreen() {
override fun getFragment(): Fragment { // New API requires factory
return MyFragment()
}
}
class MyNavigator(val activity: FragmentActivity, containerId: Int)
: SupportAppNavigator(activity, containerId) {
override fun setupFragmentTransaction(
command: Command, // Argument missing in v6.0
currentFragment: Fragment?,
nextFragment: Fragment?,
fragmentTransaction: FragmentTransaction
) {
...
}
I've found the following solution that seems to work for my case, though I'm not sure if it's fully correct:
class MyScreen : FragmentScreen {
override fun createFragment(factory: FragmentFactory): Fragment {
return MyFragment()
}
}
class MyNavigator(activity: FragmentActivity, containerId: Int)
: AppNavigator(activity, containerId) {
private lateinit var command: Command
override fun applyCommand(command: Command) {
this.command = command
super.applyCommand(command)
}
override fun setupFragmentTransaction(screen: FragmentScreen, fragmentTransaction: FragmentTransaction, currentFragment: Fragment?, nextFragment: Fragment) {
... // Use this.command where command argument was used previously
}
}
@terrakok Excuse me, is it possible to return command to setupFragmentTransaction?