Skip to content

Commit

Permalink
Merge branch 'dev' into 'main'
Browse files Browse the repository at this point in the history
Change the FAB entry/exit transition to align with the M3 guidelines
  • Loading branch information
nsh07 committed Oct 2, 2024
2 parents 965791a + 3d6ba85 commit 77b7cce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "org.nsh07.wikireader"
minSdk = 26
targetSdk = 35
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
38 changes: 13 additions & 25 deletions app/src/main/java/org/nsh07/wikireader/ui/AppHomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.animation.shrinkVertically
Expand All @@ -28,12 +30,11 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
Expand All @@ -45,26 +46,8 @@ import coil.ImageLoader
import coil.compose.SubcomposeAsyncImage
import coil.decode.SvgDecoder
import coil.request.ImageRequest
import org.nsh07.wikireader.R
import kotlinx.coroutines.launch

@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
}
import org.nsh07.wikireader.R

@Composable
fun AppHomeScreen(
Expand All @@ -78,8 +61,11 @@ fun AppHomeScreen(
val coroutineScope = rememberCoroutineScope()

val index by remember { derivedStateOf { listState.firstVisibleItemIndex } }
val offset by remember { derivedStateOf { listState.firstVisibleItemScrollOffset } }
val extendedFab = (listState.isScrollingUp() && offset > 1024)
val extendedFab by remember {
derivedStateOf {
listState.lastScrolledBackward || !listState.canScrollForward
}
}

Box(modifier = modifier) {
AnimatedVisibility(
Expand Down Expand Up @@ -183,8 +169,10 @@ fun AppHomeScreen(

AnimatedVisibility(
index > 1,
enter = scaleIn(),
exit = scaleOut(),
enter = scaleIn(transformOrigin = TransformOrigin(1f, 1f)) +
fadeIn(),
exit = scaleOut(transformOrigin = TransformOrigin(1f, 1f)) +
fadeOut(),
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(16.dp)
Expand Down

0 comments on commit 77b7cce

Please sign in to comment.