Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5 to v6+ migration guide #170

Open
jolaf opened this issue Dec 16, 2021 · 2 comments
Open

v5 to v6+ migration guide #170

jolaf opened this issue Dec 16, 2021 · 2 comments

Comments

@jolaf
Copy link

jolaf commented Dec 16, 2021

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
    ) {
    ...
}
@jolaf
Copy link
Author

jolaf commented Jan 13, 2022

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
    }
}

@nikiJava
Copy link

nikiJava commented Nov 6, 2022

@terrakok Excuse me, is it possible to return command to setupFragmentTransaction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants