@@ -3,7 +3,11 @@ package org.michaelbel.movies.ui.compose.movie
3
3
import androidx.compose.animation.AnimatedVisibility
4
4
import androidx.compose.animation.fadeIn
5
5
import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.layout.Box
7
+ import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.fillMaxSize
6
9
import androidx.compose.foundation.layout.fillMaxWidth
10
+ import androidx.compose.foundation.layout.height
7
11
import androidx.compose.foundation.layout.padding
8
12
import androidx.compose.material3.MaterialTheme
9
13
import androidx.compose.material3.Text
@@ -12,13 +16,12 @@ import androidx.compose.runtime.getValue
12
16
import androidx.compose.runtime.mutableStateOf
13
17
import androidx.compose.runtime.remember
14
18
import androidx.compose.runtime.setValue
19
+ import androidx.compose.ui.Alignment
15
20
import androidx.compose.ui.Modifier
16
21
import androidx.compose.ui.draw.clip
17
22
import androidx.compose.ui.layout.ContentScale
18
23
import androidx.compose.ui.text.style.TextOverflow
19
24
import androidx.compose.ui.unit.dp
20
- import androidx.constraintlayout.compose.ConstraintLayout
21
- import androidx.constraintlayout.compose.Dimension
22
25
import coil3.compose.AsyncImage
23
26
import coil3.compose.LocalPlatformContext
24
27
import coil3.request.ImageRequest
@@ -42,64 +45,50 @@ internal fun MovieRow(
42
45
) {
43
46
var isNoImageVisible by remember { mutableStateOf(false ) }
44
47
45
- ConstraintLayout (
48
+ Column (
46
49
modifier = modifier
47
50
) {
48
- val (image, noImageText, text) = createRefs()
49
-
50
- AsyncImage (
51
- model = ImageRequest .Builder (LocalPlatformContext .current)
52
- .data(movie.backdropPath.formatBackdropImage)
53
- .crossfade(true )
54
- .build(),
55
- contentDescription = MoviesContentDescriptionCommon .None ,
56
- modifier = Modifier .constrainAs(image) {
57
- width = Dimension .fillToConstraints
58
- height = Dimension .value(220 .dp)
59
- start.linkTo(parent.start)
60
- top.linkTo(parent.top)
61
- end.linkTo(parent.end)
62
- bottom.linkTo(text.top)
63
- },
64
- onState = { state ->
65
- isNoImageVisible = state.isErrorOrEmpty
66
- },
67
- contentScale = ContentScale .Crop
68
- )
69
-
70
- AnimatedVisibility (
71
- visible = isNoImageVisible,
72
- modifier = Modifier .constrainAs(noImageText) {
73
- width = Dimension .wrapContent
74
- height = Dimension .wrapContent
75
- start.linkTo(parent.start)
76
- top.linkTo(parent.top)
77
- end.linkTo(parent.end)
78
- bottom.linkTo(text.top)
79
- },
80
- enter = fadeIn()
51
+ Box (
52
+ modifier = Modifier
53
+ .fillMaxWidth()
54
+ .height(220 .dp)
81
55
) {
82
- Text (
83
- text = stringResource(MoviesStrings .no_image),
84
- style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.secondary)
56
+ AsyncImage (
57
+ model = ImageRequest .Builder (LocalPlatformContext .current)
58
+ .data(movie.backdropPath.formatBackdropImage)
59
+ .crossfade(true )
60
+ .build(),
61
+ contentDescription = MoviesContentDescriptionCommon .None ,
62
+ modifier = Modifier .fillMaxSize(),
63
+ onState = { state ->
64
+ isNoImageVisible = state.isErrorOrEmpty
65
+ },
66
+ contentScale = ContentScale .Crop
85
67
)
68
+
69
+ this @Column.AnimatedVisibility (
70
+ visible = isNoImageVisible,
71
+ enter = fadeIn(),
72
+ modifier = Modifier .align(Alignment .Center )
73
+ ) {
74
+ Text (
75
+ text = stringResource(MoviesStrings .no_image),
76
+ style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.secondary)
77
+ )
78
+ }
86
79
}
87
80
88
81
Text (
89
82
text = movie.title,
90
- modifier = Modifier .constrainAs(text) {
91
- width = Dimension .fillToConstraints
92
- height = Dimension .wrapContent
93
- start.linkTo(parent.start, 16 .dp)
94
- top.linkTo(image.bottom, 16 .dp)
95
- end.linkTo(parent.end, 16 .dp)
96
- bottom.linkTo(parent.bottom, 16 .dp)
97
- },
83
+ modifier = Modifier
84
+ .fillMaxWidth()
85
+ .padding(16 .dp),
98
86
maxLines = maxLines,
99
87
overflow = TextOverflow .Ellipsis ,
100
88
style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.onPrimaryContainer)
101
89
)
102
90
}
91
+
103
92
}
104
93
105
94
@Preview
0 commit comments