Closed Oyama-Oyama closed 2 weeks ago
Use this:
var text by remember { mutableStateOf("") }
TextField(text, { text = it }, Modifier.onPreviewKeyEvent {
if (it.key == Key.Enter) {
println("Enter")
true
} else {
false
}
})
This method has no effect when using NavController
Could you provide a snippet with NavController where it doesn't work?
val navController = rememberNavController()
SudokuTheme(appTheme = appTheme) {
NavHost(
navController = navController,
startDestination = "test",
modifier = Modifier.fillMaxSize(1.0f).onPreviewKeyEvent {
println("key::${it.key.keyCode}")
true
}
) {
}
}
onPreviewKeyEvent
triggers only if some element inside is focused.
See the snippet in https://github.com/JetBrains/compose-multiplatform/issues/4764 how to request a focus.
This is also the task for simplifying this case.
Functioning normally, thanks
Describe the problem Explain the performance issue you're experiencing, including the following details:
Affected platforms Select one of the platforms below:
If the problem is Android-only, report it in the Jetpack Compose tracker
Versions
Sample code If possible, provide a small piece of code that reproduces the problem. If the code snippet is too large to paste here, please link to a Gist, a GitHub repo, or any other public code repository.
Reproduction steps Please provide a detailed step-by-step guide on how to reproduce the issue you are experiencing.
Video If you're reporting slow app work or missing frames, please provide a video of the problem.
Profiling data Please provide any relevant profiling data that might be helpful. This could include information like FPS, memory usage, CPU time, or any other data that could provide insight into the performance issue.
Additional information Provide any other details that you think might be helpful for us to understand the problem. This could include things like the system configuration, external factors, etc.