-
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.
Browse files
Browse the repository at this point in the history
[Feature/#66] splash 로띠
- Loading branch information
Showing
17 changed files
with
156 additions
and
39 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
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
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
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
84 changes: 84 additions & 0 deletions
84
feature/main-compose/src/main/java/com/teamwable/main_compose/splash/SplashScreen.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,84 @@ | ||
package com.teamwable.main_compose.splash | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.LocalLifecycleOwner | ||
import androidx.lifecycle.flowWithLifecycle | ||
import com.airbnb.lottie.LottieComposition | ||
import com.airbnb.lottie.compose.LottieAnimation | ||
import com.airbnb.lottie.compose.LottieCompositionSpec | ||
import com.airbnb.lottie.compose.LottieConstants | ||
import com.airbnb.lottie.compose.animateLottieCompositionAsState | ||
import com.airbnb.lottie.compose.rememberLottieComposition | ||
import com.teamwable.designsystem.theme.WableTheme | ||
import com.teamwable.main_compose.R | ||
import com.teamwable.main_compose.splash.model.SplashSideEffect | ||
import kotlinx.coroutines.delay | ||
|
||
@Composable | ||
fun SplashRoute( | ||
viewModel: SplashViewModel = hiltViewModel(), | ||
navigateToHome: () -> Unit, | ||
navigateToLogIn: () -> Unit, | ||
) { | ||
val lifecycleOwner = LocalLifecycleOwner.current | ||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.wable_splash)) | ||
val progress by animateLottieCompositionAsState( | ||
composition = composition, | ||
iterations = LottieConstants.IterateForever, | ||
) | ||
|
||
LaunchedEffect(Unit) { | ||
delay(2000) | ||
viewModel.observeAutoLogin() | ||
} | ||
|
||
LaunchedEffect(lifecycleOwner) { | ||
viewModel.sideEffect.flowWithLifecycle(lifecycleOwner.lifecycle) | ||
.collect { sideEffect -> | ||
when (sideEffect) { | ||
is SplashSideEffect.NavigateToHome -> navigateToHome() | ||
is SplashSideEffect.NavigateToLogin -> navigateToLogIn() | ||
} | ||
} | ||
} | ||
|
||
WableSplashScreen( | ||
composition = composition, | ||
progress = progress, | ||
) | ||
} | ||
|
||
@Composable | ||
fun WableSplashScreen( | ||
composition: LottieComposition?, | ||
progress: Float, | ||
) { | ||
Box( | ||
modifier = Modifier.fillMaxSize(), | ||
) { | ||
LottieAnimation( | ||
composition = composition, | ||
progress = { progress }, | ||
modifier = Modifier.align(Alignment.Center), | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview() { | ||
WableTheme { | ||
WableSplashScreen( | ||
composition = rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.wable_splash)).value, | ||
progress = 1.0f, | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
feature/main-compose/src/main/java/com/teamwable/main_compose/splash/SplashViewModel.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,30 @@ | ||
package com.teamwable.main_compose.splash | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.teamwable.data.repository.UserInfoRepository | ||
import com.teamwable.main_compose.splash.model.SplashSideEffect | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.SharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val userInfoRepository: UserInfoRepository, | ||
) : ViewModel() { | ||
private val _sideEffect = MutableSharedFlow<SplashSideEffect>() | ||
val sideEffect: SharedFlow<SplashSideEffect> = _sideEffect.asSharedFlow() | ||
|
||
fun observeAutoLogin() { | ||
viewModelScope.launch { | ||
userInfoRepository.getAutoLogin().collectLatest { isAutoLogin -> | ||
if (isAutoLogin) _sideEffect.emit(SplashSideEffect.NavigateToHome) | ||
else _sideEffect.emit(SplashSideEffect.NavigateToLogin) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...re/main-compose/src/main/java/com/teamwable/main_compose/splash/model/SplashSideEffect.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,7 @@ | ||
package com.teamwable.main_compose.splash.model | ||
|
||
sealed interface SplashSideEffect { | ||
data object NavigateToHome : SplashSideEffect | ||
|
||
data object NavigateToLogin : SplashSideEffect | ||
} |
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
Oops, something went wrong.