Skip to content

Commit

Permalink
Update SystemUiController samples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Jul 22, 2022
1 parent f619020 commit f2b1a7c
Showing 1 changed file with 16 additions and 6 deletions.
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -171,18 +178,21 @@ private fun Sample(parentSystemUiController: SystemUiController) {
Column(
Modifier
.fillMaxSize()
.systemBarsPadding()
.safeDrawingPadding()
) {
TopAppBar(
title = { Text(stringResource(R.string.system_ui_controller_title_color_dialog)) },
backgroundColor = MaterialTheme.colors.surface.copy(alpha = 0.5f),
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),
) {
Expand Down

0 comments on commit f2b1a7c

Please sign in to comment.