Skip to content

Commit 5b66517

Browse files
Merge pull request #54 from UmairKhalid786/feature/correct_navigation_product_detail_and_player
Feature/correct navigation product detail and player
2 parents c22d6cf + 333a9ae commit 5b66517

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

app/src/main/java/com/techlads/composetv/features/details/ProductDetailsScreen.kt

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.techlads.composetv.features.details
22

33
import androidx.activity.compose.BackHandler
4+
import androidx.compose.animation.core.animateDpAsState
45
import androidx.compose.foundation.Image
56
import androidx.compose.foundation.background
67
import androidx.compose.foundation.layout.*
78
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.LaunchedEffect
10+
import androidx.compose.runtime.mutableStateOf
11+
import androidx.compose.runtime.remember
812
import androidx.compose.ui.Alignment
913
import androidx.compose.ui.Modifier
1014
import androidx.compose.ui.layout.ContentScale
@@ -21,8 +25,11 @@ import androidx.tv.material3.Text
2125
import com.techlads.composetv.R
2226
import com.techlads.composetv.theme.AppTheme
2327
import com.techlads.composetv.theme.Material3Theme
24-
import com.techlads.composetv.widgets.BorderedFocusableItem
2528
import com.techlads.composetv.widgets.Button
29+
import com.techlads.composetv.widgets.ThumbnailImageCard
30+
import kotlinx.coroutines.delay
31+
32+
const val ANIMATION_DELAY = 600L
2633

2734
@Composable
2835
fun ProductDetailsScreen(onBackPressed: () -> Unit) {
@@ -34,6 +41,17 @@ private fun ProductDetailsContent(onBackPressed: () -> Unit) {
3441

3542
BackHandler(onBack = onBackPressed)
3643

44+
val isLoaded = remember {
45+
mutableStateOf(false)
46+
}
47+
48+
val animatedPortraitSize = animateDpAsState(targetValue = if (isLoaded.value) 150.dp else 1.dp)
49+
50+
LaunchedEffect(key1 = Unit) {
51+
delay(ANIMATION_DELAY)
52+
isLoaded.value = true
53+
}
54+
3755
Box {
3856
SearchIcon(
3957
modifier = Modifier
@@ -60,11 +78,13 @@ private fun ProductDetailsContent(onBackPressed: () -> Unit) {
6078
}
6179

6280
ThumbnailImageCard(
63-
modifier = Modifier
81+
Modifier
6482
.align(Alignment.CenterStart)
65-
.padding(start = 30.dp),
66-
parent = 1, child = 1
67-
)
83+
.padding(start = 30.dp)
84+
.width(animatedPortraitSize.value)
85+
) {
86+
Text(text = "1x1")
87+
}
6888
}
6989
}
7090

@@ -207,20 +227,6 @@ fun Rating(rating: String) {
207227
}
208228
}
209229

210-
@Composable
211-
fun ThumbnailImageCard(modifier: Modifier, parent: Int, child: Int) {
212-
BorderedFocusableItem(
213-
onClick = { },
214-
modifier = modifier
215-
.padding(8.dp)
216-
.size(width = 150.dp, height = 200.dp)
217-
) {
218-
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
219-
Text(text = "Item $parent x $child", textAlign = TextAlign.Center)
220-
}
221-
}
222-
}
223-
224230
@Preview(device = Devices.TV_1080p)
225231
@Composable
226232
fun DetailsScreenPrev() {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
@file:OptIn(ExperimentalTvMaterial3Api::class)
2+
3+
package com.techlads.composetv.widgets
4+
5+
import androidx.compose.foundation.background
6+
import androidx.compose.foundation.layout.Box
7+
import androidx.compose.foundation.layout.BoxScope
8+
import androidx.compose.foundation.layout.aspectRatio
9+
import androidx.compose.foundation.layout.width
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Alignment
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.tooling.preview.Preview
14+
import androidx.compose.ui.unit.dp
15+
import androidx.tv.material3.ExperimentalTvMaterial3Api
16+
import androidx.tv.material3.MaterialTheme
17+
import androidx.tv.material3.Text
18+
import com.techlads.composetv.theme.Material3Theme
19+
20+
@Composable
21+
fun ThumbnailImageCard(
22+
modifier: Modifier = Modifier,
23+
content: @Composable (BoxScope.() -> Unit)
24+
) {
25+
Box(modifier = modifier
26+
.background(
27+
color = MaterialTheme.colorScheme.surface,
28+
shape = MaterialTheme.shapes.small
29+
).aspectRatio(0.6f), contentAlignment = Alignment.Center) {
30+
content()
31+
}
32+
}
33+
34+
@Preview
35+
@Composable
36+
fun ThumbnailImageCardPreview() {
37+
Material3Theme {
38+
ThumbnailImageCard(
39+
Modifier
40+
.width(150.dp)
41+
.background(
42+
color = MaterialTheme.colorScheme.onSurface,
43+
shape = MaterialTheme.shapes.small
44+
)
45+
) {
46+
Text(text = "1x1")
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)