Splash and App Startup Improv in Android

This commit is contained in:
shabinder 2021-09-25 22:22:13 +05:30
parent dbaaa0816f
commit 7725bc8602
4 changed files with 26 additions and 13 deletions

View File

@ -117,7 +117,8 @@ class MainActivity : ComponentActivity() {
Box {
SpotiFlyerRootContent(
this@MainActivity.rootComponent,
Modifier.statusBarsPadding().navigationBarsPadding()
Modifier.statusBarsPadding().navigationBarsPadding(),
showSplash = false // We already show System-Native Splash
)
Spacer(
Modifier

View File

@ -64,28 +64,32 @@ import com.shabinder.common.uikit.screens.splash.SplashState
import com.shabinder.common.uikit.utils.verticalGradientScrim
// To Not Show Splash Again After Configuration Change in Android
private var isSplashShown = SplashState.Shown
private var isSplashShown = SplashState.Show
@Composable
fun SpotiFlyerRootContent(component: SpotiFlyerRoot, modifier: Modifier = Modifier): SpotiFlyerRoot {
val transitionState = remember { MutableTransitionState(SplashState.Shown) }
fun SpotiFlyerRootContent(
component: SpotiFlyerRoot,
modifier: Modifier = Modifier,
showSplash: Boolean = true
): SpotiFlyerRoot {
isSplashShown = if (showSplash) SplashState.Show else SplashState.Completed
val transitionState = remember { MutableTransitionState(isSplashShown) }
val transition = updateTransition(transitionState, label = "transition")
val splashAlpha by transition.animateFloat(
transitionSpec = { tween(durationMillis = 100) }, label = "Splash-Alpha"
) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 1f else 0f
if (it == SplashState.Show && isSplashShown == SplashState.Show) 1f else 0f
}
val contentAlpha by transition.animateFloat(
transitionSpec = { tween(durationMillis = 300) }, label = "Content-Alpha"
) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 0f else 1f
if (it == SplashState.Show && isSplashShown == SplashState.Show) 0f else 1f
}
val contentTopPadding by transition.animateDp(
transitionSpec = { spring(stiffness = StiffnessLow) }, label = "Content-Padding"
) {
if (it == SplashState.Shown && isSplashShown == SplashState.Shown) 100.dp else 0.dp
if (it == SplashState.Show && isSplashShown == SplashState.Show) 100.dp else 0.dp
}
Box {
@ -111,7 +115,12 @@ fun SpotiFlyerRootContent(component: SpotiFlyerRoot, modifier: Modifier = Modifi
}
@Composable
fun MainScreen(modifier: Modifier = Modifier, alpha: Float, topPadding: Dp = 0.dp, component: SpotiFlyerRoot) {
fun MainScreen(
modifier: Modifier = Modifier,
alpha: Float,
topPadding: Dp = 0.dp,
component: SpotiFlyerRoot
) {
val appBarColor = MaterialTheme.colors.surface.copy(alpha = 0.65f)

View File

@ -38,7 +38,7 @@ import com.shabinder.common.uikit.configurations.colorPrimary
import kotlinx.coroutines.delay
private const val SplashWaitTime: Long = 2000
enum class SplashState { Shown, Completed }
enum class SplashState { Show, Completed }
@Composable
fun Splash(modifier: Modifier = Modifier, onTimeout: () -> Unit) {
@ -50,6 +50,7 @@ fun Splash(modifier: Modifier = Modifier, onTimeout: () -> Unit) {
delay(SplashWaitTime)
currentOnTimeout()
}
Image(SpotiFlyerLogo(), Strings.spotiflyerLogo(),modifier = Modifier.fillMaxSize())
MadeInIndia(Modifier.align(Alignment.BottomCenter))
}

View File

@ -16,12 +16,16 @@
package com.shabinder.common.uikit.utils
import android.util.Log
import androidx.compose.animation.core.TweenSpec
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
@ -63,8 +67,7 @@ fun Modifier.verticalGradientScrim(
listOf(color.copy(alpha = 0f), color)
}
}
var height by remember { mutableStateOf(fixedHeight ?: 0f) }
var height by remember { mutableStateOf(fixedHeight ?: 1f) }
val brush = remember(color, numStops, startYPercentage, endYPercentage, height) {
Brush.verticalGradient(
colors = colors,
@ -75,7 +78,6 @@ fun Modifier.verticalGradientScrim(
drawBehind {
height = fixedHeight ?: size.height
// log("Height",size.height.toString())
drawRect(brush = brush)
}
}