📘

Jetpack Compose - Button を押したら 戻る

2022/07/16に公開

きっと以下のどれかでは?

val navController = rememberNavController()
Button(
  onClick = { navController.popBackStack() }
) {
  Text("back")
}

Divider()

Button(
  onClick = { navController.navigateUp() }
) {
  Text("back")
}

Divider()

val dispatcher = LocalOnBackPressedDispatcherOwner.current?.onBackPressedDispatcher
Button(
  onClick = { dispatcher?.onBackPressed() }
) {
  Text("back")
}

Divider()

val activity = LocalContext.current as Activity
Button(
  onClick = { activity.finish() }
) {
  Text("close")
}

言葉じりと構造よって違うようなので。

👉 Jetpack Compose 二度押しを避けるボタン

Discussion