I stuffed it full of things, but can't get to the ones past the screen. Been watching youtube videos, asking chatGpt, etc, and can't figure it out. New to coding; sorry if this is an inefficient mess:
@Composable
fun HomeScreen(
navigateToWordEntry: () -> Unit,
navigateToWordUpdate: (Int) -> Unit,
navigateToGame: () -> Unit,
modifier: Modifier = Modifier,
viewModel: DictionaryViewModel = viewModel(factory = AppViewModelProvider.Factory)
) {
val dictionaryUiState by viewModel.dictionaryUiState.collectAsState()
val scrollBehavior = TopAppBarDefaults.enterAlwaysScrollBehavior()
Scaffold(
modifier = modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
VokabTopAppBar(navigateToGame=navigateToGame)
},
floatingActionButton = {
FloatingActionButton(
onClick = navigateToWordEntry,
shape = MaterialTheme.shapes.medium,
modifier = Modifier.padding(dimensionResource(id = R.dimen.padding_large))
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = stringResource(R.string.item_entry_title)
)
}
},
) { innerPadding ->
Column(
modifier = Modifier
.padding(innerPadding)
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection)
) {
HomeBody(
wordList = dictionaryUiState.wordList,
onWordClick = navigateToWordUpdate,
modifier = Modifier
.padding(innerPadding)
.fillMaxSize()
)
}
}
}
@Composable
private fun HomeBody(
wordList: List<Word>, onWordClick: (Int) -> Unit, modifier: Modifier = Modifier
)
{
if (wordList.isEmpty())
{
Text(
text = stringResource(R.string.no_item_description),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge
)
}
else
{
DictionaryList(
wordList = wordList,
onWordClick = { onWordClick(it.id) },
modifier = Modifier.padding(horizontal = dimensionResource(id = R.dimen.padding_small))
)
}
}
@Composable
private fun DictionaryList(
wordList: List<Word>, onWordClick: (Word) -> Unit, modifier: Modifier = Modifier
) {
LazyColumn(modifier = modifier, userScrollEnabled = true) {
items(items = wordList, key = { it.id }) { word ->
DictionaryWord(word = word,
modifier = Modifier
.padding(dimensionResource(id = R.dimen.padding_small))
.clickable { onWordClick(word) })
}
}
}
@Composable
private fun DictionaryWord(word: Word, modifier: Modifier = Modifier) {
OutlinedCard(
modifier = modifier,
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
) {
Column(
modifier = Modifier.padding(dimensionResource(id = R.dimen.padding_large)),
verticalArrangement = Arrangement.spacedBy(dimensionResource(id = R.dimen.padding_small))
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = word.name,
style = MaterialTheme.typography.titleLarge,
)
Text(
text = (word.freq.toString()),
style = MaterialTheme.typography.titleSmall
)
}
}
}
}
Tried adding and removing columns, every modifier I could find, etc. I don't need to retain the scroll state when I leave the screen.
That's all, but it says "it looks like your post is mostly code; please add some more details", so now I'm going to type a bunch of nothing, which you don't need to read, in hopes that it lets me post a question. Still not enough talk relative to code? What's the proper ratio? These hoops are ridiculous. Help. I need an adult. Is this what the "overflow" in stack overflow refers to? What's the deal here? Is this good for anybody? I need a politician to take the keyboard and fluff this up a bit. This feels exceedingly unnecessary. Shpedoinkle!
Solved: nestedScroll statement in the Scaffold AND the one in the Column were interfering with lazyList's scroll authority. Leaving this up in case any one else has that problem.