mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 08:17:04 +05:30
android: commonize shared animation code
This commit is contained in:
parent
f8e7043a42
commit
f03a55543e
3 changed files with 32 additions and 37 deletions
|
@ -2,11 +2,6 @@ package dev.msfjarvis.claw.android.ui.decorations
|
|||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
|
@ -15,7 +10,8 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import dev.msfjarvis.claw.android.R
|
||||
import dev.msfjarvis.claw.android.ui.AnimationDuration
|
||||
import dev.msfjarvis.claw.android.ui.slideInAnimation
|
||||
import dev.msfjarvis.claw.android.ui.slideOutAnimation
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
|
@ -28,18 +24,8 @@ fun ClawFab(
|
|||
val coroutineScope = rememberCoroutineScope()
|
||||
AnimatedVisibility(
|
||||
visible = isFabVisible,
|
||||
enter =
|
||||
slideInVertically(
|
||||
// Enters by sliding up from offset 0 to fullHeight.
|
||||
initialOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = LinearOutSlowInEasing),
|
||||
),
|
||||
exit =
|
||||
slideOutVertically(
|
||||
// Exits by sliding up from offset 0 to -fullHeight.
|
||||
targetOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = FastOutLinearInEasing),
|
||||
),
|
||||
enter = slideInAnimation(),
|
||||
exit = slideOutAnimation(),
|
||||
modifier = modifier,
|
||||
) {
|
||||
FloatingActionButton(onClick = { coroutineScope.launch { listState.animateScrollToItem(0) } }) {
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package dev.msfjarvis.claw.android.ui.decorations
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
|
@ -14,8 +9,9 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.navigation.NavController
|
||||
import dev.msfjarvis.claw.android.ui.AnimationDuration
|
||||
import dev.msfjarvis.claw.android.ui.navigation.Destinations
|
||||
import dev.msfjarvis.claw.android.ui.slideInAnimation
|
||||
import dev.msfjarvis.claw.android.ui.slideOutAnimation
|
||||
|
||||
@Composable
|
||||
fun ClawNavigationBar(
|
||||
|
@ -26,18 +22,8 @@ fun ClawNavigationBar(
|
|||
) {
|
||||
AnimatedVisibility(
|
||||
visible = isVisible,
|
||||
enter =
|
||||
slideInVertically(
|
||||
// Enters by sliding up from offset 0 to fullHeight.
|
||||
initialOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = LinearOutSlowInEasing),
|
||||
),
|
||||
exit =
|
||||
slideOutVertically(
|
||||
// Exits by sliding up from offset 0 to -fullHeight.
|
||||
targetOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = FastOutLinearInEasing),
|
||||
),
|
||||
enter = slideInAnimation(),
|
||||
exit = slideOutAnimation(),
|
||||
modifier = Modifier,
|
||||
) {
|
||||
NavigationBar(modifier = modifier) {
|
||||
|
|
|
@ -2,6 +2,13 @@ package dev.msfjarvis.claw.android.ui
|
|||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.material3.LocalAbsoluteTonalElevation
|
||||
|
@ -27,7 +34,23 @@ import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
|||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import kotlin.math.ln
|
||||
|
||||
const val AnimationDuration = 100
|
||||
private const val AnimationDuration = 100
|
||||
|
||||
fun slideInAnimation(): EnterTransition {
|
||||
return slideInVertically(
|
||||
// Enters by sliding up from offset 0 to fullHeight.
|
||||
initialOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = LinearOutSlowInEasing),
|
||||
)
|
||||
}
|
||||
|
||||
fun slideOutAnimation(): ExitTransition {
|
||||
return slideOutVertically(
|
||||
// Exits by sliding up from offset 0 to -fullHeight.
|
||||
targetOffsetY = { fullHeight -> fullHeight },
|
||||
animationSpec = tween(durationMillis = AnimationDuration, easing = FastOutLinearInEasing),
|
||||
)
|
||||
}
|
||||
|
||||
// The destination needs to be tracked like this rather than used directly since
|
||||
// `NavController#currentDestination` is not a Composable state.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue