SplashScreen animation.
This commit is contained in:
parent
fa2af6dd90
commit
9cde3f6404
7 changed files with 181 additions and 50 deletions
|
|
@ -1,55 +1,121 @@
|
|||
package com.pixelized.biblib.ui.composable.screen
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.animation.*
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.pixelized.biblib.BuildConfig
|
||||
import com.pixelized.biblib.R
|
||||
import com.pixelized.biblib.ui.theme.BibLibTheme
|
||||
import com.pixelized.biblib.ui.viewmodel.initialisation.IInitialisation
|
||||
import com.pixelized.biblib.ui.viewmodel.initialisation.InitialisationViewModel
|
||||
import com.pixelized.biblib.ui.viewmodel.navigation.INavigation
|
||||
import com.pixelized.biblib.ui.viewmodel.navigation.NavigationViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SplashScreenComposablePreview() {
|
||||
BibLibTheme {
|
||||
SplashScreenComposable(INavigation.Mock())
|
||||
SplashScreenComposable(IInitialisation.Mock(), INavigation.Mock())
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
fun SplashScreenComposable(
|
||||
initialisation: IInitialisation = viewModel<InitialisationViewModel>(),
|
||||
navigation: INavigation = viewModel<NavigationViewModel>()
|
||||
) {
|
||||
val duration = 1000
|
||||
val typography = MaterialTheme.typography
|
||||
initialisation.LoadApplication {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.width(240.dp)
|
||||
.align(Alignment.Center)
|
||||
) {
|
||||
AnimatedVisibility(
|
||||
visible = it != IInitialisation.State.Finished,
|
||||
initiallyVisible = false,
|
||||
enter = fadeIn(animationSpec = tween(duration))
|
||||
+ slideInVertically(
|
||||
initialOffsetY = { height -> -height },
|
||||
animationSpec = tween(duration)
|
||||
),
|
||||
exit = fadeOut(animationSpec = tween(duration))
|
||||
+ slideOutVertically(
|
||||
targetOffsetY = { height -> -height },
|
||||
animationSpec = tween(duration)
|
||||
),
|
||||
) {
|
||||
Text(
|
||||
style = typography.h4,
|
||||
text = "Welcome to"
|
||||
)
|
||||
}
|
||||
AnimatedVisibility(
|
||||
modifier = Modifier.align(Alignment.End),
|
||||
visible = it != IInitialisation.State.Finished,
|
||||
initiallyVisible = false,
|
||||
enter = fadeIn(animationSpec = tween(duration))
|
||||
+ slideInVertically(
|
||||
initialOffsetY = { height -> height },
|
||||
animationSpec = tween(duration)
|
||||
),
|
||||
exit = fadeOut(animationSpec = tween(duration))
|
||||
+ slideOutVertically(
|
||||
targetOffsetY = { height -> height },
|
||||
animationSpec = tween(duration)
|
||||
),
|
||||
) {
|
||||
Text(
|
||||
style = typography.h4,
|
||||
text = stringResource(id = R.string.app_name)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
style = typography.h4,
|
||||
text = "Welcome to BibLib"
|
||||
)
|
||||
}
|
||||
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
LaunchedEffect(key1 = "loading", block = {
|
||||
coroutineScope.launch {
|
||||
delay(1000)
|
||||
navigation.navigateTo(INavigation.Screen.LoginScreen)
|
||||
AnimatedVisibility(
|
||||
modifier = Modifier.align(Alignment.BottomEnd),
|
||||
visible = it != IInitialisation.State.Finished,
|
||||
enter = fadeIn(animationSpec = tween(duration)),
|
||||
exit = fadeOut(animationSpec = tween(duration)),
|
||||
) {
|
||||
Text(
|
||||
style = typography.caption,
|
||||
text = stringResource(
|
||||
R.string.app_version,
|
||||
BuildConfig.BUILD_TYPE.toUpperCase(Locale.getDefault()),
|
||||
BuildConfig.VERSION_NAME,
|
||||
BuildConfig.VERSION_CODE
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (it == IInitialisation.State.Finished) {
|
||||
LaunchedEffect(key1 = "navigateTo(INavigation.Screen.LoginScreen)") {
|
||||
delay(1000)
|
||||
navigation.navigateTo(INavigation.Screen.LoginScreen)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue