car preview: type with the phone's keyboard instead of drawing the car's

This commit is contained in:
Seb3thehacker committed 2026-10-22 03:10:34 -07:00
1 parent 068288a0e7
commit a26605c0ab
3 files changed
+17 -6

No files matched your search

@@ -44,6 +44,12 @@ object CarKeyboardVisibility {
val state = mutableStateOf(false)
}
/**
* True for the car UI the phone's own car preview draws. The phone is in hand there, so a
* [CarKeyboard] draws nothing and the phone's keyboard does the typing instead (see [PhoneTyping]).
*/
val LocalCarPreview = compositionLocalOf { false }
/**
* A keyboard the host draws itself.
*
@@ -73,10 +79,11 @@ fun CarKeyboard(
) {
var symbols by remember { mutableStateOf(false) }
var shifted by remember { mutableStateOf(false) }
val preview = LocalCarPreview.current
DisposableEffect(Unit) {
CarKeyboardVisibility.state.value = true
onDispose { CarKeyboardVisibility.state.value = false }
DisposableEffect(preview) {
if (!preview) CarKeyboardVisibility.state.value = true
onDispose { if (!preview) CarKeyboardVisibility.state.value = false }
}
// The same field on the phone, for typing on its own keyboard: see [PhoneTyping].
@@ -88,6 +95,7 @@ fun CarKeyboard(
}
DisposableEffect(phoneField) { onDispose { PhoneTyping.close(phoneField) } }
LaunchedEffect(text) { PhoneTyping.carText(phoneField, text) }
if (preview) return
val rows = if (symbols) SYMBOL_ROWS else LETTER_ROWS
val keyHeight = keyHeight(LocalConfiguration.current.screenHeightDp)
@@ -76,7 +76,9 @@ fun CarPreviewScreen(onBack: () -> Unit) {
// No surface yet: the SurfaceView below hands its own over once it exists, and the
// display draws straight into it. Copying each frame into a Bitmap instead cost two
// full-size allocations per frame on the main thread, and taps lagged with the size.
projector.start(null, width, height, density, name = "gearslip-preview") { CarUi() }
projector.start(null, width, height, density, name = "gearslip-preview") {
androidx.compose.runtime.CompositionLocalProvider(app.seb3thehacker.gearslip.car.LocalCarPreview provides true) { CarUi() }
}
onDispose { projector.stop() }
}
@@ -148,8 +148,9 @@ fun GearslipApp(onDisconnect: () -> Unit, onRequestCallScreening: () -> Unit) {
)
}
}
// A car keyboard is open: offer the phone's own, for a passenger.
if (screen != Screen.CAR_PREVIEW) PhoneTypingBar()
// A car keyboard is open: offer the phone's own, for a passenger. In the car preview it is
// the only keyboard, since the preview draws none of its own.
PhoneTypingBar()
}
}