try to fix indicator animation
This commit is contained in:
parent
aa017fc8eb
commit
3dedd98b2a
|
@ -66,7 +66,7 @@ fun GestureUI(
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
FullscreenGestureUI(
|
FullscreenGestureUI(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
uiVissible = uiVissible,
|
uiVisible = uiVissible,
|
||||||
fastSeekSeconds = fastSeekSeconds,
|
fastSeekSeconds = fastSeekSeconds,
|
||||||
hideUi = hideUi,
|
hideUi = hideUi,
|
||||||
showUi = showUi,
|
showUi = showUi,
|
||||||
|
|
|
@ -22,7 +22,11 @@
|
||||||
package net.newpipe.newplayer.ui.videoplayer.gesture_ui
|
package net.newpipe.newplayer.ui.videoplayer.gesture_ui
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.animation.core.Spring
|
||||||
|
import androidx.compose.animation.core.spring
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
|
import androidx.compose.animation.fadeIn
|
||||||
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.animation.scaleIn
|
import androidx.compose.animation.scaleIn
|
||||||
import androidx.compose.animation.scaleOut
|
import androidx.compose.animation.scaleOut
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
|
@ -30,6 +34,7 @@ import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
import androidx.compose.foundation.layout.wrapContentSize
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
@ -52,7 +57,7 @@ private enum class IndicatorMode {
|
||||||
@Composable
|
@Composable
|
||||||
fun FullscreenGestureUI(
|
fun FullscreenGestureUI(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
uiVissible: Boolean,
|
uiVisible: Boolean,
|
||||||
fastSeekSeconds: Int,
|
fastSeekSeconds: Int,
|
||||||
volume: Float,
|
volume: Float,
|
||||||
brightnes: Float,
|
brightnes: Float,
|
||||||
|
@ -75,7 +80,7 @@ fun FullscreenGestureUI(
|
||||||
|
|
||||||
val defaultOnRegularTap = {
|
val defaultOnRegularTap = {
|
||||||
|
|
||||||
if (uiVissible) {
|
if (uiVisible) {
|
||||||
hideUi()
|
hideUi()
|
||||||
} else {
|
} else {
|
||||||
showUi()
|
showUi()
|
||||||
|
@ -167,20 +172,17 @@ fun FullscreenGestureUI(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AnimatedVisibility(
|
|
||||||
|
IndicatorAnimation(
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
visible = indicatorMode == IndicatorMode.VOLUME_INDICATOR_VISSIBLE,
|
visible = indicatorMode == IndicatorMode.VOLUME_INDICATOR_VISSIBLE,
|
||||||
enter = scaleIn(initialScale = 0.95f, animationSpec = tween(100)),
|
|
||||||
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))
|
|
||||||
) {
|
) {
|
||||||
VolumeCircle(volumeFraction = volume)
|
VolumeCircle(volumeFraction = volume)
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedVisibility(
|
IndicatorAnimation(
|
||||||
modifier = Modifier.align(Alignment.Center),
|
modifier = Modifier.align(Alignment.Center),
|
||||||
visible = indicatorMode == IndicatorMode.BRIGHTNESS_INDICATOR_VISSIBLE,
|
visible = indicatorMode == IndicatorMode.BRIGHTNESS_INDICATOR_VISSIBLE,
|
||||||
enter = scaleIn(initialScale = 0.95f, animationSpec = tween(100)),
|
|
||||||
exit = scaleOut(targetScale = 0.95f, animationSpec = tween(100))
|
|
||||||
) {
|
) {
|
||||||
VolumeCircle(
|
VolumeCircle(
|
||||||
volumeFraction = brightnes,
|
volumeFraction = brightnes,
|
||||||
|
@ -191,6 +193,41 @@ fun FullscreenGestureUI(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun IndicatorAnimation(modifier: Modifier, visible: Boolean, content: @Composable () -> Unit) {
|
||||||
|
AnimatedVisibility(
|
||||||
|
modifier = modifier,
|
||||||
|
visible = visible,
|
||||||
|
|
||||||
|
// This animation would be equivalent to the one in the old player,
|
||||||
|
// However with f*** compose it looks janky and not at all as smooth as it did.
|
||||||
|
// So we only do fade in.
|
||||||
|
/*
|
||||||
|
enter = scaleIn(
|
||||||
|
initialScale = 0.90f, animationSpec = spring(stiffness = Spring.StiffnessMedium)
|
||||||
|
) + fadeIn(animationSpec = spring(stiffness = Spring.StiffnessHigh)),
|
||||||
|
exit = scaleOut(
|
||||||
|
targetScale = 0.90f,
|
||||||
|
animationSpec = spring(stiffness = Spring.StiffnessLow)
|
||||||
|
) + fadeOut(animationSpec = spring(stiffness = Spring.StiffnessHigh)),
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
enter = scaleIn(
|
||||||
|
initialScale = 0.90f, animationSpec = spring(stiffness = Spring.StiffnessMedium)
|
||||||
|
),
|
||||||
|
exit = scaleOut(
|
||||||
|
targetScale = 0.90f,
|
||||||
|
animationSpec = spring(stiffness = Spring.StiffnessMedium)
|
||||||
|
),
|
||||||
|
*/
|
||||||
|
enter = fadeIn(animationSpec = spring(stiffness = Spring.StiffnessHigh)),
|
||||||
|
exit = fadeOut(animationSpec = spring(stiffness = Spring.StiffnessMedium))
|
||||||
|
) {
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Preview(device = "spec:width=1080px,height=600px,dpi=440,orientation=landscape")
|
@Preview(device = "spec:width=1080px,height=600px,dpi=440,orientation=landscape")
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -201,7 +238,7 @@ fun FullscreenGestureUIPreview() {
|
||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
hideUi = { },
|
hideUi = { },
|
||||||
showUi = { },
|
showUi = { },
|
||||||
uiVissible = false,
|
uiVisible = false,
|
||||||
fastSeekSeconds = 0,
|
fastSeekSeconds = 0,
|
||||||
volume = 0f,
|
volume = 0f,
|
||||||
brightnes = 0f,
|
brightnes = 0f,
|
||||||
|
@ -230,13 +267,17 @@ fun FullscreenGestureUIPreviewInteractive() {
|
||||||
mutableStateOf(0f)
|
mutableStateOf(0f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uiVisible by remember {
|
||||||
|
mutableStateOf(false)
|
||||||
|
}
|
||||||
|
|
||||||
VideoPlayerTheme {
|
VideoPlayerTheme {
|
||||||
Surface(modifier = Modifier.wrapContentSize(), color = Color.Gray) {
|
Surface(modifier = Modifier.wrapContentSize(), color = Color.Gray) {
|
||||||
FullscreenGestureUI(
|
FullscreenGestureUI(
|
||||||
modifier = Modifier,
|
modifier = Modifier,
|
||||||
hideUi = { },
|
hideUi = { uiVisible = false },
|
||||||
showUi = { },
|
showUi = { uiVisible = true },
|
||||||
uiVissible = false,
|
uiVisible = uiVisible,
|
||||||
fastSeekSeconds = seekSeconds,
|
fastSeekSeconds = seekSeconds,
|
||||||
volume = soundVolume,
|
volume = soundVolume,
|
||||||
brightnes = brightnesValue,
|
brightnes = brightnesValue,
|
||||||
|
@ -252,5 +293,9 @@ fun FullscreenGestureUIPreviewInteractive() {
|
||||||
soundVolume = (soundVolume + it).coerceIn(0f, 1f)
|
soundVolume = (soundVolume + it).coerceIn(0f, 1f)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AnimatedVisibility(uiVisible) {
|
||||||
|
Text("UI is Vissible")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue