Wear UI: intercept system back so Messages/Conversation/Accounts pop within app
Add BackHandler in WearApp: back from thread: -> messages, messages/accounts -> dialer. At the root dialer route the handler is disabled so back finishes the Activity normally. Fixes back-from-Messages dropping to the clock face.
This commit is contained in:
@ -8,6 +8,7 @@ import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.*
|
||||
@ -189,6 +190,17 @@ class MainActivity : ComponentActivity() {
|
||||
fun WearApp(activity: MainActivity) {
|
||||
// Show the in-call screen whenever there is an active or incoming call.
|
||||
val hasCall by remember { derivedStateOf { CallState.calls.isNotEmpty() } }
|
||||
// Intercept the system back gesture so navigation stays inside the app
|
||||
// (Messages/Conversation/Accounts screens pop to their parent instead of
|
||||
// finishing the Activity and dropping to the clock face). At the root
|
||||
// "dialer" route the handler is disabled, so back behaves normally.
|
||||
BackHandler(enabled = activity.route.value != "dialer") {
|
||||
activity.route.value = when {
|
||||
activity.route.value.startsWith("thread:") -> "messages"
|
||||
activity.route.value == "messages" || activity.route.value == "accounts" -> "dialer"
|
||||
else -> "dialer"
|
||||
}
|
||||
}
|
||||
MaterialTheme {
|
||||
Scaffold(timeText = { TimeText() }) {
|
||||
when {
|
||||
|
||||
Reference in New Issue
Block a user