diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarKeyboard.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarKeyboard.kt index 6139770..e0a984c 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarKeyboard.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarKeyboard.kt @@ -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) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/CarPreviewScreen.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/CarPreviewScreen.kt index c6871bc..1f6d1c1 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/CarPreviewScreen.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/CarPreviewScreen.kt @@ -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() } } diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/GearslipApp.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/GearslipApp.kt index 78e894f..f31fb5f 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/GearslipApp.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/ui/GearslipApp.kt @@ -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() } }