Skip to content

Commit 8af88fd

Browse files
authored
Merge pull request #53 from Nexters/fix/newintent-deeplink
포그라운드 상태에서 딥링크 호출 시 이동되지 않는 이슈를 수정합니다.
2 parents 394aa40 + 80616e4 commit 8af88fd

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

feature/main/src/main/java/com/plottwist/feature/main/MainActivity.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import android.os.Bundle
55
import androidx.activity.ComponentActivity
66
import androidx.activity.compose.setContent
77
import androidx.activity.enableEdgeToEdge
8+
import androidx.compose.runtime.CompositionLocalProvider
9+
import androidx.compose.runtime.compositionLocalOf
810
import androidx.core.net.toUri
911
import com.plottwist.feature.main.ui.theme.TukTheme
1012
import dagger.hilt.android.AndroidEntryPoint
@@ -21,9 +23,14 @@ class MainActivity : ComponentActivity() {
2123

2224
private fun setComposeContent() {
2325
setContent {
24-
TukTheme {
25-
TukApp()
26+
CompositionLocalProvider(
27+
LocalActivity provides this
28+
) {
29+
TukTheme {
30+
TukApp()
31+
}
2632
}
33+
2734
}
2835
}
2936

@@ -40,12 +47,12 @@ class MainActivity : ComponentActivity() {
4047
)
4148
}
4249

43-
override fun onNewIntent(intent: Intent) {
44-
super.onNewIntent(intent)
45-
handleDeepLink(intent)
46-
}
4750

4851
companion object {
4952
const val NOTIFICATION_REQUEST_CODE = 0
5053
}
5154
}
55+
56+
val LocalActivity = compositionLocalOf<ComponentActivity> {
57+
error("CompositionLocal LocalActivity not present")
58+
}

feature/main/src/main/java/com/plottwist/feature/main/TukApp.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.plottwist.feature.main
22

33
import androidx.compose.foundation.layout.fillMaxSize
44
import androidx.compose.foundation.layout.navigationBarsPadding
5-
import androidx.compose.foundation.layout.padding
6-
import androidx.compose.material3.Scaffold
75
import androidx.compose.material3.Surface
86
import androidx.compose.runtime.Composable
97
import androidx.compose.ui.Modifier

feature/main/src/main/java/com/plottwist/feature/main/ui/component/TukNavHost.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.plottwist.feature.main.ui.component
22

3+
import android.content.Intent
34
import androidx.compose.runtime.Composable
5+
import androidx.compose.runtime.DisposableEffect
46
import androidx.compose.ui.Modifier
7+
import androidx.core.util.Consumer
58
import androidx.navigation.NavHostController
69
import androidx.navigation.compose.NavHost
710
import androidx.navigation.compose.rememberNavController
811
import androidx.navigation.navOptions
12+
import com.plottwist.core.ui.navigation.Route
913
import com.plottwist.create_gathering.navigation.createGatheringNavGraph
1014
import com.plottwist.create_gathering.navigation.navigateToCreateGathering
11-
import com.plottwist.core.ui.navigation.Route
1215
import com.plottwist.feature.gathering_detail.navigation.gatheringDetailAlarmSettingNavGraph
1316
import com.plottwist.feature.gathering_detail.navigation.gatheringDetailNavGraph
1417
import com.plottwist.feature.gathering_detail.navigation.navigateToGatheringDetail
@@ -17,6 +20,7 @@ import com.plottwist.feature.home.navigation.homeNavGraph
1720
import com.plottwist.feature.home.navigation.navigateToHome
1821
import com.plottwist.feature.login.navigation.loginNavGraph
1922
import com.plottwist.feature.login.navigation.navigateToLogin
23+
import com.plottwist.feature.main.LocalActivity
2024
import com.plottwist.feature.mypage.navigation.editNameNavGraph
2125
import com.plottwist.feature.mypage.navigation.myPageNavGraph
2226
import com.plottwist.feature.mypage.navigation.navigateToEditName
@@ -47,6 +51,19 @@ fun TukNavHost(
4751
modifier: Modifier = Modifier,
4852
navController: NavHostController = rememberNavController()
4953
) {
54+
val activity = LocalActivity.current
55+
56+
DisposableEffect(activity, navController) {
57+
val onNewIntentConsumer = Consumer<Intent> {
58+
navController.handleDeepLink(it)
59+
}
60+
61+
activity.addOnNewIntentListener(onNewIntentConsumer)
62+
63+
onDispose { activity.removeOnNewIntentListener(onNewIntentConsumer) }
64+
}
65+
66+
5067
NavHost(
5168
modifier = modifier,
5269
navController = navController,

0 commit comments

Comments
 (0)