-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include SplashScreenController, new Composables and Extensions
- Loading branch information
Showing
11 changed files
with
434 additions
and
19 deletions.
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
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
152 changes: 152 additions & 0 deletions
152
...e/src/main/java/com/jeluchu/jchucomponentscompose/ui/animations/SplashScreenController.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,152 @@ | ||
package com.jeluchu.jchucomponentscompose.ui.animations | ||
|
||
import android.animation.AnimatorSet | ||
import android.animation.ObjectAnimator | ||
import android.annotation.SuppressLint | ||
import android.graphics.Path | ||
import android.view.View | ||
import android.view.animation.AnticipateInterpolator | ||
import androidx.core.animation.doOnEnd | ||
import androidx.core.splashscreen.SplashScreen | ||
|
||
/** | ||
* | ||
* Author: @Jeluchu | ||
* | ||
* This class allows you to quickly and easily | ||
* implement a Splash Screen with the new Jetpack API | ||
* | ||
* @param splashScreen you must pass by parameter Activity.installSplashScreen() from [SplashScreen] | ||
* @param defaultExitDuration you will be able to spend a certain amount of time | ||
* for the duration of the animation. By default it is set to 300 | ||
* | ||
*/ | ||
|
||
@SuppressLint("CustomSplashScreen") | ||
class SplashScreenController( | ||
private val splashScreen: SplashScreen, | ||
private val defaultExitDuration: Long = 300, | ||
) { | ||
|
||
fun customizeSplashScreenExit(keys: List<SplashAnimations>, onExitExtraActions: () -> Unit = {}) = | ||
splashScreen.setOnExitAnimationListener { splashScreenViewProvider -> | ||
val onExit = { | ||
splashScreenViewProvider.remove() | ||
onExitExtraActions() | ||
} | ||
showSplashExitAnimator(splashScreenViewProvider.view, keys, onExit) | ||
showSplashIconExitAnimator(splashScreenViewProvider.iconView, onExit) | ||
} | ||
|
||
private fun showSplashExitAnimator( | ||
splashScreenView: View, | ||
keys: List<SplashAnimations>, | ||
onExit: () -> Unit = {}) { | ||
|
||
AnimatorSet().run { | ||
duration = defaultExitDuration | ||
interpolator = AnticipateInterpolator() | ||
splashScreenView.apply { | ||
playTogether(getAnimation(keys, splashScreenView).toList()) | ||
} | ||
doOnEnd { onExit() } | ||
start() | ||
} | ||
|
||
} | ||
|
||
private fun showSplashIconExitAnimator(iconView: View, onExit: () -> Unit = {}) { | ||
|
||
val alphaOut = ObjectAnimator.ofFloat( | ||
iconView, | ||
View.ALPHA, | ||
1f, | ||
0f | ||
) | ||
|
||
val scaleOut = ObjectAnimator.ofFloat( | ||
iconView, | ||
View.SCALE_X, | ||
View.SCALE_Y, | ||
Path().apply { | ||
moveTo(1.0f, 1.0f) | ||
lineTo(0.3f, 0.3f) | ||
} | ||
) | ||
|
||
val slideUp = ObjectAnimator.ofFloat( | ||
iconView, | ||
View.TRANSLATION_Y, | ||
0f, | ||
-(iconView.height).toFloat() * 2.25f | ||
) | ||
|
||
AnimatorSet().run { | ||
interpolator = AnticipateInterpolator() | ||
duration = defaultExitDuration | ||
|
||
playTogether(alphaOut, scaleOut, slideUp) | ||
doOnEnd { onExit() } | ||
start() | ||
} | ||
|
||
} | ||
|
||
private fun getAnimation(keys: List<SplashAnimations>, splashScreenView: View): MutableList<ObjectAnimator> { | ||
|
||
val listAnimations: MutableList<ObjectAnimator> = mutableListOf() | ||
|
||
for (key in keys) { | ||
val animation = when(key) { | ||
SplashAnimations.SlideUp -> ObjectAnimator.ofFloat( | ||
splashScreenView, | ||
View.TRANSLATION_Y, | ||
0f, | ||
-splashScreenView.height.toFloat() | ||
) | ||
SplashAnimations.SlideLeft -> ObjectAnimator.ofFloat( | ||
splashScreenView, | ||
View.TRANSLATION_X, | ||
0f, | ||
-splashScreenView.width.toFloat() | ||
) | ||
SplashAnimations.ScaleXOut -> ObjectAnimator.ofFloat( | ||
splashScreenView, | ||
View.SCALE_X, | ||
1.0f, | ||
0f | ||
) | ||
SplashAnimations.AlphaOut -> ObjectAnimator.ofFloat( | ||
splashScreenView, | ||
View.ALPHA, | ||
1f, | ||
0f | ||
) | ||
SplashAnimations.ScaleOut -> ObjectAnimator.ofFloat( | ||
splashScreenView, | ||
View.SCALE_X, | ||
View.SCALE_Y, | ||
Path().apply { | ||
moveTo(1.0f, 1.0f) | ||
lineTo(0f, 0f) | ||
} | ||
) | ||
} | ||
|
||
listAnimations.add(animation) | ||
|
||
} | ||
|
||
return listAnimations | ||
|
||
} | ||
|
||
} | ||
|
||
enum class SplashAnimations { | ||
SlideUp, | ||
SlideLeft, | ||
ScaleXOut, | ||
AlphaOut, | ||
ScaleOut | ||
} |
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
100 changes: 100 additions & 0 deletions
100
...componentscompose/src/main/java/com/jeluchu/jchucomponentscompose/ui/chips/InterestTag.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,100 @@ | ||
package com.jeluchu.jchucomponentscompose.ui.chips | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.* | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.Shape | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.jeluchu.jchucomponentscompose.ui.theme.green200 | ||
import com.jeluchu.jchucomponentscompose.ui.theme.green700 | ||
import com.jeluchu.jchucomponentscompose.ui.theme.typography | ||
|
||
/** | ||
* | ||
* Author: @Jeluchu | ||
* | ||
* This component is similar to the Chips, | ||
* in which you can display a text or a text and an icon | ||
* | ||
* @sample ChipTagViewPreview | ||
* | ||
* @param modifier modifier that will be used to change the color, size... | ||
* @param title text to be displayed on the chip | ||
* @param colors color of the text and background | ||
* @param shape type of shape desired for this chip | ||
* @param style style of text to be displayed | ||
* @param navigateToScreen action to be performed after pressing | ||
* | ||
*/ | ||
|
||
@Composable | ||
fun InterestTag( | ||
modifier: Modifier = Modifier, | ||
title: String, | ||
colors: TagColors = TagDefaults.tagColors(), | ||
shape: Shape = RoundedCornerShape(4.dp), | ||
style: TextStyle = typography.body2.copy(fontWeight = FontWeight.Bold), | ||
navigateToScreen: () -> Unit = {} | ||
) { | ||
val tagModifier = modifier | ||
.padding(4.dp) | ||
.clickable(onClick = navigateToScreen) | ||
.clip(shape = shape) | ||
.background(colors.backgroundColor(enabled = true).value) | ||
.padding(horizontal = 8.dp, vertical = 4.dp) | ||
Text( | ||
text = title, | ||
color = colors.contentColor(enabled = true).value, | ||
modifier = tagModifier, | ||
style = style | ||
) | ||
} | ||
|
||
@Stable | ||
interface TagColors { | ||
@Composable | ||
fun backgroundColor(enabled: Boolean): State<Color> | ||
|
||
@Composable | ||
fun contentColor(enabled: Boolean): State<Color> | ||
} | ||
|
||
@Immutable | ||
private class DefaultTagColors( | ||
private val backgroundColor: Color, | ||
private val contentColor: Color | ||
) : TagColors { | ||
@Composable | ||
override fun backgroundColor(enabled: Boolean): State<Color> { | ||
return rememberUpdatedState(newValue = backgroundColor) | ||
} | ||
|
||
@Composable | ||
override fun contentColor(enabled: Boolean): State<Color> { | ||
return rememberUpdatedState(newValue = contentColor) | ||
} | ||
} | ||
|
||
object TagDefaults { | ||
@Composable | ||
fun tagColors( | ||
backgroundColor: Color = green200.copy(alpha = .2f), | ||
contentColor: Color = green700 | ||
): TagColors = DefaultTagColors(backgroundColor = backgroundColor, contentColor = contentColor) | ||
} | ||
|
||
|
||
@Preview | ||
@Composable | ||
fun InterestTagPreview() { | ||
InterestTag(title = "Name") | ||
} |
Oops, something went wrong.