Skip to content

Commit c6f8f95

Browse files
committed
Change from SingletonComponent to ActivityRetainedComponent
1 parent 52b91b7 commit c6f8f95

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.example.nav3recipes.modular
22

3-
import androidx.compose.runtime.mutableStateListOf
43
import androidx.compose.runtime.snapshots.SnapshotStateList
54
import dagger.Module
65
import dagger.Provides
76
import dagger.hilt.InstallIn
8-
import dagger.hilt.components.SingletonComponent
9-
import javax.inject.Inject
7+
import dagger.hilt.android.components.ActivityRetainedComponent
8+
import dagger.hilt.android.scopes.ActivityRetainedScoped
109
import javax.inject.Singleton
1110

1211
@Module
13-
@InstallIn(SingletonComponent::class)
12+
@InstallIn(ActivityRetainedComponent::class)
1413
object AppModule {
1514

1615
@Provides
17-
@Singleton
16+
@ActivityRetainedScoped
1817
fun provideBackStack(backStackFactory: BackStackFactory) : SnapshotStateList<Any> =
1918
backStackFactory.create(startDestination = ConversationList)
2019

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import androidx.navigation3.runtime.EntryProviderBuilder
66
import dagger.Module
77
import dagger.Provides
88
import dagger.hilt.InstallIn
9-
import dagger.hilt.components.SingletonComponent
9+
import dagger.hilt.android.components.ActivityRetainedComponent
10+
import dagger.hilt.android.scopes.ActivityRetainedScoped
1011
import javax.inject.Inject
11-
import javax.inject.Singleton
1212

1313

1414
typealias EntryProviderInstaller = EntryProviderBuilder<Any>.() -> Unit
1515

1616
@Module
17-
@InstallIn(SingletonComponent::class)
17+
@InstallIn(ActivityRetainedComponent::class)
1818
object CommonModule {
1919
@Provides
20-
@Singleton
20+
@ActivityRetainedScoped
2121
fun provideBackStackFactory() : BackStackFactory = BackStackFactory()
2222
}
2323

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,30 @@ import androidx.compose.foundation.background
44
import androidx.compose.foundation.clickable
55
import androidx.compose.foundation.layout.Arrangement
66
import androidx.compose.foundation.layout.Column
7-
import androidx.compose.foundation.layout.PaddingValues
8-
import androidx.compose.foundation.layout.Row
97
import androidx.compose.foundation.layout.Spacer
108
import androidx.compose.foundation.layout.fillMaxSize
119
import androidx.compose.foundation.layout.fillMaxWidth
1210
import androidx.compose.foundation.layout.height
1311
import androidx.compose.foundation.layout.padding
1412
import androidx.compose.foundation.lazy.LazyColumn
15-
import androidx.compose.foundation.shape.RoundedCornerShape
13+
import androidx.compose.material3.Button
1614
import androidx.compose.material3.ListItem
1715
import androidx.compose.material3.ListItemDefaults
1816
import androidx.compose.material3.MaterialTheme
19-
import androidx.compose.material3.Button
20-
import androidx.compose.material3.Button
2117
import androidx.compose.material3.Text
2218
import androidx.compose.runtime.Composable
2319
import androidx.compose.runtime.snapshots.SnapshotStateList
2420
import androidx.compose.ui.Alignment
2521
import androidx.compose.ui.Modifier
26-
import androidx.compose.ui.draw.clip
22+
import androidx.compose.ui.graphics.Color
2723
import androidx.compose.ui.unit.dp
28-
import androidx.navigation3.runtime.EntryProviderBuilder
2924
import androidx.navigation3.runtime.entry
30-
import androidx.compose.ui.graphics.Color
31-
import androidx.navigation3.runtime.EntryProvider
3225
import com.example.nav3recipes.ui.theme.colors
3326
import dagger.Module
3427
import dagger.Provides
3528
import dagger.hilt.InstallIn
36-
import dagger.hilt.components.SingletonComponent
29+
import dagger.hilt.android.components.ActivityRetainedComponent
3730
import dagger.multibindings.IntoSet
38-
import com.example.nav3recipes.modular.Profile
3931

4032
// API
4133
object ConversationList
@@ -46,7 +38,7 @@ data class ConversationDetail(val id: Int) {
4638

4739
// IMPL
4840
@Module
49-
@InstallIn(SingletonComponent::class)
41+
@InstallIn(ActivityRetainedComponent::class)
5042
object ConversationModule {
5143

5244
@IntoSet

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
package com.example.nav3recipes.modular
22

3+
import androidx.compose.foundation.background
34
import androidx.compose.foundation.layout.Arrangement
45
import androidx.compose.foundation.layout.Column
56
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.material3.MaterialTheme
69
import androidx.compose.material3.Text
710
import androidx.compose.runtime.Composable
811
import androidx.compose.runtime.snapshots.SnapshotStateList
912
import androidx.compose.ui.Alignment
1013
import androidx.compose.ui.Modifier
11-
import androidx.navigation3.runtime.EntryProviderBuilder
12-
import androidx.navigation3.runtime.entry
13-
import androidx.compose.foundation.background
14-
import androidx.compose.ui.graphics.Color
15-
import com.example.nav3recipes.ui.theme.colors
16-
import androidx.compose.foundation.layout.padding
17-
import androidx.compose.material3.MaterialTheme
1814
import androidx.compose.ui.unit.dp
15+
import androidx.navigation3.runtime.entry
1916
import dagger.Module
2017
import dagger.Provides
2118
import dagger.hilt.InstallIn
22-
import dagger.hilt.components.SingletonComponent
19+
import dagger.hilt.android.components.ActivityRetainedComponent
2320
import dagger.multibindings.IntoSet
2421

2522
// API
2623
object Profile
2724

2825
// IMPLEMENTATION
2926
@Module
30-
@InstallIn(SingletonComponent::class)
27+
@InstallIn(ActivityRetainedComponent::class)
3128
object ProfileModule {
3229

3330
@IntoSet

0 commit comments

Comments
 (0)