mirror of
https://github.com/Shabinder/SpotiFlyer.git
synced 2024-11-22 09:04:32 +01:00
Splash and App Startup Improv in Android
This commit is contained in:
parent
dbaaa0816f
commit
7725bc8602
@ -117,7 +117,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
Box {
|
Box {
|
||||||
SpotiFlyerRootContent(
|
SpotiFlyerRootContent(
|
||||||
this@MainActivity.rootComponent,
|
this@MainActivity.rootComponent,
|
||||||
Modifier.statusBarsPadding().navigationBarsPadding()
|
Modifier.statusBarsPadding().navigationBarsPadding(),
|
||||||
|
showSplash = false // We already show System-Native Splash
|
||||||
)
|
)
|
||||||
Spacer(
|
Spacer(
|
||||||
Modifier
|
Modifier
|
||||||
|
@ -64,28 +64,32 @@ import com.shabinder.common.uikit.screens.splash.SplashState
|
|||||||
import com.shabinder.common.uikit.utils.verticalGradientScrim
|
import com.shabinder.common.uikit.utils.verticalGradientScrim
|
||||||
|
|
||||||
// To Not Show Splash Again After Configuration Change in Android
|
// To Not Show Splash Again After Configuration Change in Android
|
||||||
private var isSplashShown = SplashState.Shown
|
private var isSplashShown = SplashState.Show
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SpotiFlyerRootContent(component: SpotiFlyerRoot, modifier: Modifier = Modifier): SpotiFlyerRoot {
|
fun SpotiFlyerRootContent(
|
||||||
|
component: SpotiFlyerRoot,
|
||||||
val transitionState = remember { MutableTransitionState(SplashState.Shown) }
|
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 transition = updateTransition(transitionState, label = "transition")
|
||||||
|
|
||||||
val splashAlpha by transition.animateFloat(
|
val splashAlpha by transition.animateFloat(
|
||||||
transitionSpec = { tween(durationMillis = 100) }, label = "Splash-Alpha"
|
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(
|
val contentAlpha by transition.animateFloat(
|
||||||
transitionSpec = { tween(durationMillis = 300) }, label = "Content-Alpha"
|
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(
|
val contentTopPadding by transition.animateDp(
|
||||||
transitionSpec = { spring(stiffness = StiffnessLow) }, label = "Content-Padding"
|
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 {
|
Box {
|
||||||
@ -111,7 +115,12 @@ fun SpotiFlyerRootContent(component: SpotiFlyerRoot, modifier: Modifier = Modifi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@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)
|
val appBarColor = MaterialTheme.colors.surface.copy(alpha = 0.65f)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ import com.shabinder.common.uikit.configurations.colorPrimary
|
|||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
private const val SplashWaitTime: Long = 2000
|
private const val SplashWaitTime: Long = 2000
|
||||||
enum class SplashState { Shown, Completed }
|
enum class SplashState { Show, Completed }
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Splash(modifier: Modifier = Modifier, onTimeout: () -> Unit) {
|
fun Splash(modifier: Modifier = Modifier, onTimeout: () -> Unit) {
|
||||||
@ -50,6 +50,7 @@ fun Splash(modifier: Modifier = Modifier, onTimeout: () -> Unit) {
|
|||||||
delay(SplashWaitTime)
|
delay(SplashWaitTime)
|
||||||
currentOnTimeout()
|
currentOnTimeout()
|
||||||
}
|
}
|
||||||
|
|
||||||
Image(SpotiFlyerLogo(), Strings.spotiflyerLogo(),modifier = Modifier.fillMaxSize())
|
Image(SpotiFlyerLogo(), Strings.spotiflyerLogo(),modifier = Modifier.fillMaxSize())
|
||||||
MadeInIndia(Modifier.align(Alignment.BottomCenter))
|
MadeInIndia(Modifier.align(Alignment.BottomCenter))
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,16 @@
|
|||||||
|
|
||||||
package com.shabinder.common.uikit.utils
|
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.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.composed
|
import androidx.compose.ui.composed
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
import androidx.compose.ui.draw.drawBehind
|
import androidx.compose.ui.draw.drawBehind
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@ -63,8 +67,7 @@ fun Modifier.verticalGradientScrim(
|
|||||||
listOf(color.copy(alpha = 0f), color)
|
listOf(color.copy(alpha = 0f), color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var height by remember { mutableStateOf(fixedHeight ?: 1f) }
|
||||||
var height by remember { mutableStateOf(fixedHeight ?: 0f) }
|
|
||||||
val brush = remember(color, numStops, startYPercentage, endYPercentage, height) {
|
val brush = remember(color, numStops, startYPercentage, endYPercentage, height) {
|
||||||
Brush.verticalGradient(
|
Brush.verticalGradient(
|
||||||
colors = colors,
|
colors = colors,
|
||||||
@ -75,7 +78,6 @@ fun Modifier.verticalGradientScrim(
|
|||||||
|
|
||||||
drawBehind {
|
drawBehind {
|
||||||
height = fixedHeight ?: size.height
|
height = fixedHeight ?: size.height
|
||||||
// log("Height",size.height.toString())
|
|
||||||
drawRect(brush = brush)
|
drawRect(brush = brush)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user