Skip to content

Commit 52b91b7

Browse files
committed
Add typealias to be used by feature modules
1 parent ab92cfb commit 52b91b7

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

app/src/main/java/com/example/nav3recipes/modular/CommonModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package com.example.nav3recipes.modular
22

33
import androidx.compose.runtime.mutableStateListOf
44
import androidx.compose.runtime.snapshots.SnapshotStateList
5+
import androidx.navigation3.runtime.EntryProviderBuilder
56
import dagger.Module
67
import dagger.Provides
78
import dagger.hilt.InstallIn
89
import dagger.hilt.components.SingletonComponent
910
import javax.inject.Inject
1011
import javax.inject.Singleton
1112

13+
14+
typealias EntryProviderInstaller = EntryProviderBuilder<Any>.() -> Unit
15+
1216
@Module
1317
@InstallIn(SingletonComponent::class)
1418
object CommonModule {

app/src/main/java/com/example/nav3recipes/modular/ConversationModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import androidx.compose.ui.unit.dp
2828
import androidx.navigation3.runtime.EntryProviderBuilder
2929
import androidx.navigation3.runtime.entry
3030
import androidx.compose.ui.graphics.Color
31+
import androidx.navigation3.runtime.EntryProvider
3132
import com.example.nav3recipes.ui.theme.colors
3233
import dagger.Module
3334
import dagger.Provides
@@ -50,7 +51,7 @@ object ConversationModule {
5051

5152
@IntoSet
5253
@Provides
53-
fun provideEntryProviderBuilder(backStack: SnapshotStateList<Any>): EntryProviderBuilder<Any>.() -> Unit =
54+
fun provideEntryProviderInstaller(backStack: SnapshotStateList<Any>): EntryProviderInstaller =
5455
{
5556
entry<ConversationList> {
5657
ConversationListScreen(

app/src/main/java/com/example/nav3recipes/modular/ModularActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import javax.inject.Inject
2121
* Features (Conversation and Profile) are split into two modules:
2222
* - api: defines the public facing routes for this feature
2323
* - impl: defines the entryProviders for this feature, these are injected into the app's main activity
24-
* The common module defines how the back stack should be created.
24+
* The common module defines:
25+
* - how the back stack should be created
26+
* - a type that should be used by feature modules to inject entryProviders into the app's main activity
2527
* The app module creates the back stack by supplying a start destination and provides this back stack to the rest of the app module (i.e. MainActivity) and the feature modules.
2628
*/
2729
@AndroidEntryPoint
@@ -31,7 +33,7 @@ class ModularActivity : ComponentActivity() {
3133
lateinit var backStack: SnapshotStateList<Any>
3234

3335
@Inject
34-
lateinit var entryProviderBuilders: Set<@JvmSuppressWildcards EntryProviderBuilder<Any>.() -> Unit>
36+
lateinit var entryProviderBuilders: Set<@JvmSuppressWildcards EntryProviderInstaller>
3537

3638
override fun onCreate(savedInstanceState: Bundle?) {
3739
super.onCreate(savedInstanceState)

app/src/main/java/com/example/nav3recipes/modular/ProfileModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object ProfileModule {
3232

3333
@IntoSet
3434
@Provides
35-
fun provideEntryProviderBuilder( backStack: SnapshotStateList<Any>) : EntryProviderBuilder<Any>.() -> Unit = {
35+
fun provideEntryProviderInstaller(backStack: SnapshotStateList<Any>) : EntryProviderInstaller = {
3636
entry<Profile>{
3737
ProfileScreen()
3838
}

0 commit comments

Comments
 (0)