Skip to content

Commit

Permalink
fix(Player): fullscreen button recomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
urFate committed Sep 15, 2024
1 parent 110908f commit d05db7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.shirabox.app.ui.activity.player.presentation.controls

import android.app.Activity
import android.content.pm.ActivityInfo
import android.content.res.Configuration
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down Expand Up @@ -31,6 +32,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
Expand All @@ -52,7 +54,8 @@ internal fun PlayerBottomBar(
var currentValue by remember { mutableFloatStateOf(0F) }
var mutablePosition by remember { mutableLongStateOf(currentPosition) }

val animatedValue by animateFloatAsState(if (isValueChanging) currentValue else (currentPosition.toFloat() / duration.toFloat()),
val animatedValue by animateFloatAsState(
targetValue = if (isValueChanging) currentValue else (currentPosition.toFloat() / duration.toFloat()),
label = ""
)

Expand Down Expand Up @@ -129,31 +132,25 @@ internal fun PlayerBottomBar(
colors = colors
)

val localConf = LocalConfiguration.current
val activity = LocalContext.current as Activity

val isPortrait = when (activity.requestedOrientation) {
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT,
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT -> true

else -> false
}
val isLandscape = localConf.orientation == Configuration.ORIENTATION_LANDSCAPE

IconButton(
onClick = {
activity.requestedOrientation =
if (isPortrait) {
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
} else {
if (isLandscape) {
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
} else {
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}
}
) {
Icon(
imageVector = if (isPortrait) {
Icons.Rounded.Fullscreen
} else {
imageVector = if (isLandscape) {
Icons.Rounded.FullscreenExit
} else {
Icons.Rounded.Fullscreen
},
contentDescription = null,
tint = MaterialTheme.colorScheme.inverseOnSurface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ internal fun PlayerSkipButton(
) {
var percentage by remember { mutableIntStateOf(0) }
val orientation = LocalConfiguration.current.orientation
val isVerticalOrientation =
val isPortraitOrientation =
orientation == Configuration.ORIENTATION_PORTRAIT || orientation == Configuration.ORIENTATION_UNDEFINED
val contentAlignment = if (isVerticalOrientation) Alignment.CenterEnd else Alignment.BottomEnd
val contentAlignment = if (isPortraitOrientation) Alignment.CenterEnd else Alignment.BottomEnd

if (autoSkip) {
LaunchedEffect(isPlaying) {
Expand All @@ -58,7 +58,7 @@ internal fun PlayerSkipButton(
.padding(16.dp, 64.dp),
contentAlignment = contentAlignment
) {
val endPadding = if (isVerticalOrientation) 0.dp else 16.dp
val endPadding = if (isPortraitOrientation) 0.dp else 16.dp

OutlinedButton(
modifier = Modifier.padding(0.dp, 128.dp, endPadding, 0.dp),
Expand Down

0 comments on commit d05db7e

Please sign in to comment.