Oliver
03/06/2024, 8:19 AMOliver
03/06/2024, 8:19 AM@Composable
@Preview
fun App() {
MaterialTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background,
) {
Screen()
}
}
}
@Composable
private fun Screen() {
Scaffold(
topBar = { TopBar() },
bottomBar = { BottomBar() },
) { contentPadding ->
LazyColumn(
verticalArrangement = Arrangement.spacedBy(24.dp),
contentPadding = contentPadding,
modifier = Modifier.fillMaxWidth(),
) {
items((0 ..< 4).toList()) {
OutlinedTextField(
value = "placeholder $it",
onValueChange = {},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
minLines = 6,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
)
}
}
}
}
@Composable
private fun BottomBar() {
BottomAppBar(
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.8F),
) {
Text(
text = "Bottom bar",
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth(),
)
}
}
@Composable
@OptIn(ExperimentalMaterial3Api::class)
private fun TopBar() {
CenterAlignedTopAppBar(
title = { Text("Top bar") },
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.8F),
),
)
}
Oliver
03/06/2024, 8:20 AMimport androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
Oliver
03/06/2024, 8:33 AMBringIntoViewRequester
and provide the Rect
to it. However getting the exact rect values isn't very straightforward in my non-example case. I am not even entirely sure whether the rect is used the way I think it would be used.Stylianos Gakis
03/06/2024, 12:24 PMOliver
03/06/2024, 12:26 PMStylianos Gakis
03/06/2024, 12:27 PMOliver
03/06/2024, 12:27 PMStylianos Gakis
03/06/2024, 12:36 PMSean Proctor
03/06/2024, 11:53 PM.onFocusChanged {
if (it.isFocused) {
scrollToItem(index, -topBarHeightPx)
}
}
You'll need to check if the item is off the bottom or top of the list and set the offset appropriately. This is just an idea, totally untested.Alex Vanyo
03/07/2024, 12:24 AMSean Proctor
03/07/2024, 12:31 AMcontentPadding
? I imagine it as adding padding before the first item and after the last item.Stylianos Gakis
03/07/2024, 7:58 AMOliver
03/09/2024, 9:07 PMcontentPadding
should also represent the insets that obstruct the content. And due to the obstructions, the bring-into-view should take contentPadding
into account.Oliver
03/09/2024, 9:09 PM