-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add achivement click animation #1235 #1265
Open
Aniokrait
wants to merge
14
commits into
DroidKaigi:main
Choose a base branch
from
Aniokrait:add-achivement-click-animation_#1235
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
737f67b
added animation when achievement images are clicked
Aniokrait 885a662
add clickable condition
Aniokrait 5265e35
terminate animation when onDispose
Aniokrait 131d8a7
Rename component
Aniokrait 598402d
Merge branch 'main' into add-achivement-click-animation_#1235
Aniokrait 80cd664
Rename achievement states
Aniokrait 91d88e3
Rename functions along convention
Aniokrait 813b64f
Add screenshot tests
Aniokrait 1b38dfa
Merge branch 'main' into add-achivement-click-animation_#1235
Aniokrait b61e6f6
Merge branch 'main' into add-achivement-click-animation_#1235
Aniokrait 78b1e2d
Merge branch 'main' into add-achivement-click-animation_#1235
Aniokrait 69d3235
add LottieTestRule
Aniokrait fcfd005
change reset logic
Aniokrait 220c85d
evacuate executor
Aniokrait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import io.github.droidkaigi.confsched2023.ui.handleErrorAndRetry | |
import kotlinx.collections.immutable.PersistentSet | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.persistentSetOf | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.SharingStarted | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.stateIn | ||
|
@@ -120,13 +121,17 @@ class AchievementsScreenViewModel @Inject constructor( | |
) | ||
} | ||
|
||
private val clickedAchievement = MutableStateFlow<AchievementAnimationState>(AchievementAnimationState.NotAnimating) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change this name as we change the state? 🙇 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for overlooking. I renamed clickedAchievement to achievementAnimationState. |
||
|
||
val uiState = buildUiState( | ||
achievementAnimationListState, | ||
isInitialDialogDisplayFlow, | ||
) { achievementListUiState, isDisplayedInitialDialog -> | ||
clickedAchievement, | ||
) { achievementListUiState, isDisplayedInitialDialog, clickedAchievement -> | ||
AchievementsScreenUiState( | ||
achievementListUiState = achievementListUiState, | ||
isShowInitialDialog = isDisplayedInitialDialog?.not() ?: false, | ||
clickedAchievement = clickedAchievement, | ||
) | ||
} | ||
|
||
|
@@ -141,4 +146,22 @@ class AchievementsScreenViewModel @Inject constructor( | |
achievementRepository.displayedInitialDialog() | ||
} | ||
} | ||
|
||
fun onClickAchievement(clickedAchievement: Achievement) { | ||
val animationRawId: Int = when (clickedAchievement) { | ||
Achievement.ArcticFox -> R.raw.achievement_a_lottie | ||
Achievement.Bumblebee -> R.raw.achievement_b_lottie | ||
Achievement.Chipmunk -> R.raw.achievement_c_lottie | ||
Achievement.Dolphin -> R.raw.achievement_d_lottie | ||
Achievement.ElectricEel -> R.raw.achievement_e_lottie | ||
} | ||
this.clickedAchievement.value = AchievementAnimationState.Animating( | ||
achievement = clickedAchievement, | ||
animationRawId = animationRawId, | ||
) | ||
} | ||
|
||
fun onFinishAnimation() { | ||
this.clickedAchievement.value = AchievementAnimationState.NotAnimating | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...o/github/droidkaigi/confsched2023/achievements/component/AchievementHighlightAnimation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.github.droidkaigi.confsched2023.achievements.component | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import com.airbnb.lottie.compose.LottieAnimation | ||
import com.airbnb.lottie.compose.LottieCompositionSpec.RawRes | ||
import com.airbnb.lottie.compose.animateLottieCompositionAsState | ||
import com.airbnb.lottie.compose.rememberLottieComposition | ||
|
||
@Composable | ||
fun AchievementHighlightAnimation( | ||
animationRawId: Int, | ||
onFinishAnimation: () -> Unit, | ||
) { | ||
val lottieComposition by rememberLottieComposition(RawRes(animationRawId)) | ||
val progress by animateLottieCompositionAsState( | ||
composition = lottieComposition, | ||
isPlaying = true, | ||
restartOnPlay = true, | ||
) | ||
if (progress == 1f) { | ||
onFinishAnimation() | ||
} | ||
LottieAnimation( | ||
composition = lottieComposition, | ||
progress = { progress }, | ||
) | ||
} |
20 changes: 19 additions & 1 deletion
20
...c/main/java/io/github/droidkaigi/confsched2023/achievements/component/AchievementImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
package io.github.droidkaigi.confsched2023.achievements.component | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.unit.dp | ||
import io.github.droidkaigi.confsched2023.model.Achievement | ||
import io.github.droidkaigi.confsched2023.model.AchievementAnimation | ||
|
||
@Composable | ||
fun AchievementImage( | ||
achievementAnimation: AchievementAnimation, | ||
modifier: Modifier = Modifier, | ||
showAnimation: (Achievement) -> Unit, | ||
) { | ||
val interactionSource = remember { MutableInteractionSource() } | ||
Image( | ||
painter = painterResource(id = achievementAnimation.getDrawableResId()), | ||
contentDescription = achievementAnimation.contentDescription, | ||
modifier = modifier | ||
.padding(horizontal = 21.dp), | ||
.padding(horizontal = 21.dp) | ||
.then( | ||
if (achievementAnimation.hasAchievement) { | ||
Modifier.clickable( | ||
interactionSource = interactionSource, | ||
indication = null, | ||
) { | ||
showAnimation(achievementAnimation.achievement) | ||
} | ||
} else { | ||
Modifier | ||
}, | ||
), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would like to promote the best practice that a StateHolder should be notified events.
So how about naming this
onAchivementClicked
and judge if we run a animation in ViewModel forshowAnimation
?And use "onAnimationFinished" as a name for
finishAnimation
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed showAnimation to onAchivementClick and finishAnimation to onAnimationFinish.