Skip to content

Commit 5fe6b83

Browse files
committed
fix: align portrait player controls
1 parent ba59f2b commit 5fe6b83

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

‎app/src/androidTest/java/dev/typetype/android/feature/player/components/PlayerControlsLayoutTest.kt‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.activity.ComponentActivity
55
import androidx.compose.foundation.layout.Box
66
import androidx.compose.foundation.layout.size
77
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.platform.testTag
89
import androidx.compose.ui.test.junit4.v2.createAndroidComposeRule
910
import androidx.compose.ui.test.onNodeWithTag
1011
import androidx.compose.ui.unit.dp
@@ -15,6 +16,7 @@ import androidx.media3.common.Tracks
1516
import androidx.media3.common.VideoSize
1617
import androidx.test.ext.junit.runners.AndroidJUnit4
1718
import java.lang.reflect.Proxy
19+
import org.junit.Assert.assertEquals
1820
import org.junit.Assert.assertTrue
1921
import org.junit.Rule
2022
import org.junit.Test
@@ -29,7 +31,11 @@ class PlayerControlsLayoutTest {
2931
fun portraitControlsDoNotOverlapInsideShortVideoViewport() {
3032
val player = controlsLayoutPlayer()
3133
composeRule.setContent {
32-
Box(Modifier.size(width = 360.dp, height = 202.dp)) {
34+
Box(
35+
Modifier
36+
.size(width = 360.dp, height = 202.dp)
37+
.testTag(PLAYER_CONTROLS_VIEWPORT_TAG),
38+
) {
3339
PlayerControls(
3440
player = player,
3541
title = "Portrait controls",
@@ -50,9 +56,14 @@ class PlayerControlsLayoutTest {
5056
val bottom = composeRule.onNodeWithTag(PLAYER_BOTTOM_CONTROLS_TAG, useUnmergedTree = true)
5157
.fetchSemanticsNode()
5258
.boundsInRoot
59+
val viewport = composeRule.onNodeWithTag(
60+
PLAYER_CONTROLS_VIEWPORT_TAG,
61+
useUnmergedTree = true,
62+
).fetchSemanticsNode().boundsInRoot
5363

5464
assertTrue("Top controls overlap center controls", top.bottom <= center.top)
5565
assertTrue("Center controls overlap bottom controls", center.bottom <= bottom.top)
66+
assertEquals("Portrait controls stop at the viewport bottom", viewport.bottom, bottom.bottom, 1f)
5667
}
5768
}
5869

‎app/src/main/java/dev/typetype/android/feature/player/components/PlayerControls.kt‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Row
88
import androidx.compose.foundation.layout.fillMaxWidth
99
import androidx.compose.foundation.layout.height
1010
import androidx.compose.foundation.layout.WindowInsets
11-
import androidx.compose.foundation.layout.navigationBars
1211
import androidx.compose.foundation.layout.padding
1312
import androidx.compose.foundation.layout.size
1413
import androidx.compose.foundation.layout.statusBars
@@ -108,13 +107,6 @@ fun PlayerControls(
108107
.align(Alignment.BottomCenter)
109108
.fillMaxWidth()
110109
.testTag(PLAYER_BOTTOM_CONTROLS_TAG)
111-
.then(
112-
if (isFullscreen) {
113-
Modifier
114-
} else {
115-
Modifier.windowInsetsPadding(WindowInsets.navigationBars)
116-
},
117-
)
118110
.padding(
119111
start = if (isFullscreen) 12.dp else 4.dp,
120112
end = if (isFullscreen) 8.dp else 4.dp,
@@ -185,7 +177,11 @@ private fun BottomBar(
185177
},
186178
)
187179
.padding(start = if (isFullscreen) 8.dp else 2.dp, end = 2.dp),
188-
verticalAlignment = Alignment.CenterVertically,
180+
verticalAlignment = if (isFullscreen) {
181+
Alignment.CenterVertically
182+
} else {
183+
Alignment.Bottom
184+
},
189185
) {
190186
PlayerTimeBar(
191187
player = player,
@@ -221,4 +217,5 @@ private fun BottomBar(
221217
internal const val PLAYER_TOP_CONTROLS_TAG = "player_top_controls"
222218
internal const val PLAYER_CENTER_CONTROLS_TAG = "player_center_controls"
223219
internal const val PLAYER_BOTTOM_CONTROLS_TAG = "player_bottom_controls"
220+
internal const val PLAYER_CONTROLS_VIEWPORT_TAG = "player_controls_viewport"
224221
private val COMPACT_CONTROLS_HEIGHT = 180.dp

‎app/src/main/java/dev/typetype/android/feature/player/components/PlayerSurfaceBox.kt‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import androidx.compose.animation.fadeOut
1010
import androidx.compose.foundation.layout.Box
1111
import androidx.compose.foundation.layout.fillMaxSize
1212
import androidx.compose.foundation.layout.fillMaxWidth
13-
import androidx.compose.foundation.layout.WindowInsets
14-
import androidx.compose.foundation.layout.navigationBars
1513
import androidx.compose.foundation.layout.padding
16-
import androidx.compose.foundation.layout.windowInsetsPadding
1714
import androidx.compose.material3.SnackbarHostState
1815
import androidx.compose.runtime.Composable
1916
import androidx.compose.runtime.derivedStateOf
@@ -301,9 +298,7 @@ internal fun PlayerSurfaceBox(
301298
if (isFullscreen) {
302299
Modifier.padding(start = 12.dp, end = 8.dp, bottom = 6.dp)
303300
} else {
304-
Modifier
305-
.windowInsetsPadding(WindowInsets.navigationBars)
306-
.padding(start = 4.dp, end = 4.dp)
301+
Modifier.padding(start = 4.dp, end = 4.dp)
307302
},
308303
),
309304
)

0 commit comments

Comments
 (0)