Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions Reply/app/src/main/java/com/example/reply/ui/ReplyListContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.windowInsetsBottomHeight
Expand All @@ -35,11 +34,18 @@ import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.ExtendedFloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.LargeFloatingActionButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
Expand Down Expand Up @@ -113,20 +119,17 @@ fun ReplyInboxScreen(
)
// When we have bottom navigation we show FAB at the bottom end.
if (navigationType == ReplyNavigationType.BOTTOM_NAVIGATION) {
LargeFloatingActionButton(
ExtendedFloatingActionButton (
text = { Text(text = stringResource(id = R.string.compose)) },
icon = { Icon(Icons.Default.Edit, stringResource(id = R.string.compose)) },
onClick = { /*TODO*/ },
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp),
containerColor = MaterialTheme.colorScheme.tertiaryContainer,
contentColor = MaterialTheme.colorScheme.onTertiaryContainer
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = stringResource(id = R.string.compose),
modifier = Modifier.size(28.dp)
)
}
contentColor = MaterialTheme.colorScheme.onTertiaryContainer,
expanded = emailLazyListState.isScrollingUp()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for an extension here, you can replace this with

Suggested change
expanded = emailLazyListState.isScrollingUp()
expanded = emailLazyListState.lastScrolledBackward ||
!emailLazyListState.canScrollBackward

Copy link
Contributor Author

@jamilxt jamilxt Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I really appreciate it. It's been exciting to try Android development again after 4 years! I've updated as per suggestion.

)
}
}
}
Expand Down Expand Up @@ -231,3 +234,24 @@ fun ReplyEmailDetail(
}
}
}

/**
* Returns whether the lazy list is currently scrolling up.
*/
@Composable
private fun LazyListState.isScrollingUp(): Boolean {
var previousIndex by remember(this) { mutableIntStateOf(firstVisibleItemIndex) }
var previousScrollOffset by remember(this) { mutableIntStateOf(firstVisibleItemScrollOffset) }
return remember(this) {
derivedStateOf {
if (previousIndex != firstVisibleItemIndex) {
previousIndex > firstVisibleItemIndex
} else {
previousScrollOffset >= firstVisibleItemScrollOffset
}.also {
previousIndex = firstVisibleItemIndex
previousScrollOffset = firstVisibleItemScrollOffset
}
}
}.value
}
Loading