Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
- implementing animation
  • Loading branch information
Francisco Barrios committed Dec 7, 2020
1 parent 7c6f987 commit b50d6ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
// Compose
implementation "androidx.ui:ui-tooling:$compose_version"
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.animation:animation:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.runtime:runtime:$compose_version"
implementation "androidx.compose.runtime:runtime-livedata:$compose_version"
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/fjbg/todo/ui/anim/Animation.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.fjbg.todo.ui.anim

import androidx.compose.animation.core.FloatPropKey
import androidx.compose.animation.core.TransitionDefinition
import androidx.compose.animation.core.keyframes
import androidx.compose.animation.core.transitionDefinition
import androidx.compose.animation.ColorPropKey
import androidx.compose.animation.core.*
import androidx.compose.foundation.layout.preferredSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand All @@ -13,6 +11,8 @@ import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieAnimationSpec
import com.airbnb.lottie.compose.rememberLottieAnimationState
import com.fjbg.todo.R
import com.fjbg.todo.ui.theme.almostWhite
import com.fjbg.todo.ui.theme.primaryDark

@Composable
fun showIntroAnimation() {
Expand All @@ -31,22 +31,25 @@ fun showIntroAnimation() {
}

val sizeState = FloatPropKey()
val colorState = ColorPropKey()

enum class FabState {
Idle, Exploded
Idle, Exploded, IdleColor, ExplodedColor
}

fun sizeTransitionDefinition(): TransitionDefinition<FabState> {
return transitionDefinition {
state(FabState.Idle) { this[sizeState] = 80f }
state(FabState.Exploded) { this[sizeState] = 4000f }
state(FabState.IdleColor) { this[colorState] = primaryDark }
state(FabState.ExplodedColor) { this[colorState] = almostWhite }

transition(fromState = FabState.Idle, toState = FabState.Exploded) {
sizeState using keyframes {
durationMillis = 700
durationMillis = 900
80f at 0
35f at 120
4000f at 700
35f at 150
4000f at 900
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/fjbg/todo/ui/common/Common.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.fjbg.todo.ui.anim.FabState
import com.fjbg.todo.ui.anim.sizeState
Expand Down Expand Up @@ -45,22 +44,26 @@ fun defaultContentView(
floatingActionButton = {
if (showBottomBar) {
val fabState = remember { mutableStateOf(FabState.Idle) }
FloatingActionButton(

val state = transition(
definition = sizeTransitionDefinition(),
initState = FabState.Idle,
toState = fabState.value
)

/* FloatingActionButton(
onClick = {
if (fabState.value == FabState.Idle) fabState.value =
FabState.Exploded else fabState.value = FabState.Idle
},
backgroundColor = primaryDark,
icon = { Icon(asset = Icons.Default.Add, tint = almostWhite) }
)
)*/

val state = transition(
definition = sizeTransitionDefinition(),
toState = fabState.value
)


Canvas(modifier = Modifier.preferredSize(80.dp)) {
drawCircle(Color.Red, state[sizeState])
drawCircle(almostWhite, state[sizeState])
}
}
},
Expand Down

0 comments on commit b50d6ef

Please sign in to comment.