From f2b1a7c868a35f8e8ec83b90eef10e54d9c76ada Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Fri, 22 Jul 2022 15:33:28 -0700 Subject: [PATCH] Update SystemUiController samples --- .../DialogSystemBarsColorSample.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DialogSystemBarsColorSample.kt b/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DialogSystemBarsColorSample.kt index ab2710bd2..f627b8a8b 100644 --- a/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DialogSystemBarsColorSample.kt +++ b/sample/src/main/java/com/google/accompanist/sample/systemuicontroller/DialogSystemBarsColorSample.kt @@ -17,7 +17,7 @@ package com.google.accompanist.sample.systemuicontroller import android.os.Bundle -import android.view.ViewGroup +import android.view.WindowManager import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.Image @@ -32,12 +32,15 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.systemBarsPadding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material.Button import androidx.compose.material.Checkbox import androidx.compose.material.MaterialTheme import androidx.compose.material.Text +import androidx.compose.material.TextField import androidx.compose.material.TopAppBar import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -47,6 +50,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.luminance @@ -55,6 +59,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog import androidx.compose.ui.window.DialogWindowProvider @@ -86,9 +91,11 @@ class DialogSystemBarsColorSample : ComponentActivity() { val dialogWindowProvider = LocalView.current.parent as DialogWindowProvider // Setup the dialog to go edge-to-edge SideEffect { - window.setLayout( - ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.MATCH_PARENT + // Use SOFT_INPUT_ADJUST_RESIZE for API compatibility with IME insets + // See https://issuetracker.google.com/issues/176400965 + @Suppress("DEPRECATION") + dialogWindowProvider.window.setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE ) WindowCompat.setDecorFitsSystemWindows( dialogWindowProvider.window, @@ -171,7 +178,7 @@ private fun Sample(parentSystemUiController: SystemUiController) { Column( Modifier .fillMaxSize() - .systemBarsPadding() + .safeDrawingPadding() ) { TopAppBar( title = { Text(stringResource(R.string.system_ui_controller_title_color_dialog)) }, @@ -179,10 +186,13 @@ private fun Sample(parentSystemUiController: SystemUiController) { elevation = 0.dp, ) Spacer(modifier = Modifier.weight(1f)) + var text by remember { mutableStateOf(TextFieldValue("Test for IME support")) } + TextField(value = text, onValueChange = { text = it }) Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier .fillMaxWidth() + .verticalScroll(rememberScrollState()) .background(MaterialTheme.colors.surface.copy(alpha = 0.5f)) .padding(vertical = 16.dp), ) {