I’m now clone-coding this codelab project.
By the way, I have a problem with the global action
function of navigation.
CodeLab’s global action receives one argument,
I couldn’t pass arguments in the code I wrote.
The following error occurs:
Too many arguments for public open fun actionGlobalComposeFragment(): ComposeFragmentDirections.ActionGlobalComposeFragment defined in com.example.materialcomponentsmotioncodelab.ui.compose.ComposeFragmentDirections
fun navigateToHome(@StringRes titleRes: Int, mailbox: Mailbox) {
binding.bottomAppBarTitle.text = getString(titleRes)
// TODO: Set up MaterialFadeThrough transition as exit transition.
val directions = HomeFragmentDirections.actionGlobalHomeFragment(mailbox)
findNavController(R.id.nav_host_fragment).navigate(directions)
}
private fun navigateToCompose() {
// TODO: Set up MaterialElevationScale transition as exit and reenter transitions.
val directions = ComposeFragmentDirections.actionGlobalComposeFragment(currentEmailId)
findNavController(R.id.nav_host_fragment).navigate(directions)
}
private fun navigateToSearch() {
// TODO: Set up MaterialSharedAxis transition as exit and reenter transitions.
val directions = SearchFragmentDirections.actionGlobalSearchFragment()
findNavController(R.id.nav_host_fragment).navigate(directions)
}
nav_graph
only has a different package name, but everything else is the same.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_graph"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.example.materialcomponentsmotioncodelab.ui.home.HomeFragment"
android:label="HomeFragment">
<argument
android:name="mailbox"
app:argType="com.materialstudies.reply.ui.home.Mailbox"
android:defaultValue="INBOX" />
<action
android:id="@+id/action_homeFragment_to_emailFragment"
app:destination="@id/emailFragment" />
</fragment>
<fragment
android:id="@+id/emailFragment"
android:name="com.example.materialcomponentsmotioncodelab.ui.email.EmailFragment"
android:label="EmailFragment">
<argument
android:name="emailId"
app:argType="long" />
</fragment>
<fragment
android:id="@+id/composeFragment"
android:name="com.example.materialcomponentsmotioncodelab.ui.compose.ComposeFragment"
android:label="ComposeFragment">
<argument
android:name="replyToEmailId"
app:argType="long"
android:defaultValue="-1L"/>
</fragment>
<fragment
android:id="@+id/searchFragment"
android:name="com.example.materialcomponentsmotioncodelab.ui.search.SearchFragment"
android:label="SearchFragment" />
<action
android:id="@+id/action_global_homeFragment"
app:destination="@+id/homeFragment"
app:launchSingleTop="true"
app:popUpTo="@+id/navigation_graph"
app:popUpToInclusive="true"/>
<action
android:id="@+id/action_global_composeFragment"
app:destination="@+id/composeFragment" />
<action
android:id="@+id/action_global_searchFragment"
app:destination="@+id/searchFragment" />
</navigation>
What am I missing?