1
1
package org.michaelbel.movies.ui.compose.movie
2
2
3
- import androidx.compose.animation.AnimatedVisibility
4
- import androidx.compose.animation.fadeIn
5
3
import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.layout.Box
5
+ import androidx.compose.foundation.layout.Column
6
+ import androidx.compose.foundation.layout.fillMaxSize
6
7
import androidx.compose.foundation.layout.fillMaxWidth
8
+ import androidx.compose.foundation.layout.height
7
9
import androidx.compose.foundation.layout.padding
8
10
import androidx.compose.material3.MaterialTheme
9
11
import androidx.compose.material3.Text
@@ -12,13 +14,12 @@ import androidx.compose.runtime.getValue
12
14
import androidx.compose.runtime.mutableStateOf
13
15
import androidx.compose.runtime.remember
14
16
import androidx.compose.runtime.setValue
17
+ import androidx.compose.ui.Alignment
15
18
import androidx.compose.ui.Modifier
16
19
import androidx.compose.ui.draw.clip
17
20
import androidx.compose.ui.layout.ContentScale
18
21
import androidx.compose.ui.text.style.TextOverflow
19
22
import androidx.compose.ui.unit.dp
20
- import androidx.constraintlayout.compose.ConstraintLayout
21
- import androidx.constraintlayout.compose.Dimension
22
23
import coil3.compose.AsyncImage
23
24
import coil3.compose.LocalPlatformContext
24
25
import coil3.request.ImageRequest
@@ -42,59 +43,41 @@ internal fun MovieColumn(
42
43
) {
43
44
var isNoImageVisible by remember { mutableStateOf(false ) }
44
45
45
- ConstraintLayout (
46
- modifier = modifier
46
+ Column (
47
+ modifier = modifier.fillMaxWidth()
47
48
) {
48
- val (image, noImageText, text) = createRefs()
49
-
50
- AsyncImage (
51
- model = ImageRequest .Builder (LocalPlatformContext .current)
52
- .data(movie.posterPath.formatPosterImage)
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()
49
+ Box (
50
+ modifier = Modifier
51
+ .fillMaxWidth()
52
+ .height(220 .dp)
81
53
) {
82
- Text (
83
- text = stringResource(Res .string.no_image),
84
- style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.secondary)
54
+ AsyncImage (
55
+ model = ImageRequest .Builder (LocalPlatformContext .current)
56
+ .data(movie.posterPath.formatPosterImage)
57
+ .crossfade(true )
58
+ .build(),
59
+ contentDescription = MoviesContentDescriptionCommon .None ,
60
+ modifier = Modifier .fillMaxSize(),
61
+ onState = { state ->
62
+ isNoImageVisible = state.isErrorOrEmpty
63
+ },
64
+ contentScale = ContentScale .Crop
85
65
)
66
+
67
+ if (isNoImageVisible) {
68
+ Text (
69
+ text = stringResource(Res .string.no_image),
70
+ style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.secondary),
71
+ modifier = Modifier .align(Alignment .Center )
72
+ )
73
+ }
86
74
}
87
75
88
76
Text (
89
77
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
- },
78
+ modifier = Modifier
79
+ .fillMaxWidth()
80
+ .padding(16 .dp),
98
81
maxLines = 10 ,
99
82
overflow = TextOverflow .Ellipsis ,
100
83
style = MaterialTheme .typography.bodyLarge.copy(MaterialTheme .colorScheme.onPrimaryContainer)
0 commit comments