Skip to content

Commit

Permalink
Use movable content to swap players
Browse files Browse the repository at this point in the history
  • Loading branch information
StaehliJ committed Mar 14, 2024
1 parent 3b16eca commit 416b524
Showing 1 changed file with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package ch.srgssr.pillarbox.demo.ui.showcases.misc
import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
Expand All @@ -16,6 +15,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.movableContentOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
Expand Down Expand Up @@ -67,43 +67,48 @@ fun MultiPlayerShowcase() {
playerTwo.pause()
}
}
val leftPlayer = if (swapLeftRight) playerTwo else playerOne
val rightPlayer = if (swapLeftRight) playerOne else playerTwo
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { swapLeftRight = !swapLeftRight }) {
Text(text = "Swap players")
}
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Row(modifier = Modifier.fillMaxWidth()) {
val playerOneView = remember {
movableContentOf {
PlayerView(
modifier = Modifier
.weight(1.0f)
.padding(MaterialTheme.paddings.mini),
player = leftPlayer,
player = playerOne,
)
}
}
val playerTwoView = remember {
movableContentOf {
PlayerView(
modifier = Modifier
.weight(1.0f)
.padding(MaterialTheme.paddings.mini),
player = rightPlayer
player = playerTwo,
)
}
}
val players = remember {
movableContentOf {
if (swapLeftRight) {
playerTwoView()
playerOneView()
} else {
playerOneView()
playerTwoView()
}
}
}
if (LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Row(modifier = Modifier.fillMaxWidth()) {
players()
}
} else {
Column(modifier = Modifier.fillMaxWidth()) {
PlayerView(
modifier = Modifier
.weight(1.0f)
.aspectRatio(AspectRatio)
.padding(MaterialTheme.paddings.mini),
player = leftPlayer
)
PlayerView(
modifier = Modifier
.weight(1.0f)
.aspectRatio(AspectRatio)
.padding(MaterialTheme.paddings.mini),
player = rightPlayer
)
players()
}
}
}
Expand Down

0 comments on commit 416b524

Please sign in to comment.