Modern Apps git

← Modern-Apps.git

maps: fix the mic button crashing Layoutlib preview rendering

Commit
8f12de8b3dfef9787512c6b6e604940eb75be6f4
Author
vayun-mathur <[email protected]>
When
2026-08-21 15:56 UTC (3 months ago)
Parents
c008e32

Diff

maps/src/main/java/com/vayunmathur/maps/ui/VoiceSearchButton.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/ui/VoiceSearchButton.kt b/maps/src/main/java/com/vayunmathur/maps/ui/VoiceSearchButton.ktindex d80bbc3299..39036be5ca 100644--- a/maps/src/main/java/com/vayunmathur/maps/ui/VoiceSearchButton.kt+++ b/maps/src/main/java/com/vayunmathur/maps/ui/VoiceSearchButton.kt@@ -11,6 +11,7 @@ import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.platform.LocalInspectionMode import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.IconMic import com.vayunmathur.library.ui.rememberPermissionRequest@@ -30,8 +31,10 @@ import com.vayunmathur.library.ui.rememberPermissionRequest @Composable fun VoiceSearchButton(onResult: (String) -> Unit, modifier: Modifier = Modifier) {     val context = LocalContext.current-    // Hide the mic when the device has no recognition service to bind.-    if (!SpeechRecognizer.isRecognitionAvailable(context)) return+    // Hide the mic when the device has no recognition service to bind. Layoutlib has none+    // and `isRecognitionAvailable` throws there rather than returning false, so the+    // short-circuit has to come first for previews to render.+    if (LocalInspectionMode.current || !SpeechRecognizer.isRecognitionAvailable(context)) return      val recognizer = remember { SpeechRecognizer.createSpeechRecognizer(context) }     DisposableEffect(recognizer) {