compose 에서 화면 간 데이터 전달

갓김치·2025년 1월 8일
0

Android

목록 보기
4/5

네비게이션

composable(
	route = "${AppRoute.Settings.Policy.AgreedPolicy.AgreedTerms.route}?policy={policy}&isLatest={isLatest}",
	arguments = listOf(
    	navArgument("policy") { type = NavType.StringType},
        navArgument("isLatest") { type = NavType.BoolType }
    )
) { backStackEntry ->
	PolicyScreen(navBackStackEntry = backStackEntry)
}

스크린

MenuListItem(
	appRoute = policy.type.toAppRoute(),
	navController = navController,
	onClick = {
		val json = Uri.encode(Gson().toJson(policy))
 		navController.navigate("${policy.type.toAppRoute().route}?policy=$json&isLatest=false") {
 			popUpTo(AppRoute.Settings.Policy.AgreedPolicy.Main.route) { 
            	inclusive = false  // Keep the main route in the stack
			}
			launchSingleTop = true  // Avoid multiple instances of the same destination
		}
	}
)
  • uri encode 해서 넘길 수 있다.
  • 이때 TopAppBar 가 쿼리 파라미터 없는 기본 루트만 인식해서 처리해줌
  • TopAppBar back button 누르면 제 화면에서 기본 루트로 넘어가서 launchSingleTop = true 추가함
profile
갈 길이 멀다

0개의 댓글