MusicVideoScreen 컴포저블을 만들고 MusicVIdeoPlayer와 VideoPlayerOverlay를 Box로 감쌌다.
@OptIn(UnstableApi::class)
@Composable
fun MusicVideoScreen(
pick: Pick,
modifier: Modifier,
onBackClick: () -> Unit,
videoPlayerViewModel: VideoPlayerViewModel = hiltViewModel()
) {
val isLoading by videoPlayerViewModel.isLoading.collectAsStateWithLifecycle()
BackHandler { onBackClick() }
Box(modifier = modifier.fillMaxSize()) {
MusicVideoPlayer(pick)
VideoPlayerOverlay(pick, onBackClick)
if (isLoading) {
CircularProgressIndicator(Modifier.align(Alignment.Center))
}
}
}
Preview 화면
이 방식으로 투명도를 조절하기 위해서는 Animatable
을 이용해야했다.
val alpha = remember **{** *Animatable*(1f) **}**
.pointerInput(Unit) {
detectTapGestures(
onTap = {
coroutineScope.launch {
// Fade In
alpha.animateTo(1.0f, animationSpec = tween(durationMillis = 300))
// 대기
delay(3_000L)
// Fade Out
alpha.animateTo(0f, animationSpec = tween(durationMillis = 300))
}
}
}
onTap 내부에 이벤트 발생 시 실행할 코드를 작성하면 된다.