@momo-kits/native-kits 0.120.0-beta.3 → 0.120.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,10 @@ package vn.momo.kits.components
|
|
|
2
2
|
|
|
3
3
|
import androidx.compose.foundation.layout.Box
|
|
4
4
|
import androidx.compose.runtime.Composable
|
|
5
|
+
import androidx.compose.runtime.getValue
|
|
6
|
+
import androidx.compose.runtime.mutableStateOf
|
|
7
|
+
import androidx.compose.runtime.remember
|
|
8
|
+
import androidx.compose.runtime.setValue
|
|
5
9
|
import androidx.compose.ui.Alignment
|
|
6
10
|
import androidx.compose.ui.Modifier
|
|
7
11
|
import androidx.compose.ui.graphics.ColorFilter
|
|
@@ -10,6 +14,10 @@ import androidx.compose.ui.graphics.painter.Painter
|
|
|
10
14
|
import androidx.compose.ui.layout.ContentScale
|
|
11
15
|
import androidx.compose.ui.semantics.contentDescription
|
|
12
16
|
import androidx.compose.ui.semantics.semantics
|
|
17
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
18
|
+
import androidx.compose.ui.layout.onSizeChanged
|
|
19
|
+
import coil3.compose.AsyncImage
|
|
20
|
+
import vn.momo.kits.const.AppTheme
|
|
13
21
|
|
|
14
22
|
data class Options(
|
|
15
23
|
val alignment: Alignment = Alignment.TopStart,
|
|
@@ -70,59 +78,57 @@ fun Image(
|
|
|
70
78
|
options: Options? = null,
|
|
71
79
|
loading: Boolean = true,
|
|
72
80
|
) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
var imageOptions = Options()
|
|
82
|
+
var imageState by remember { mutableStateOf(ImageState.Loading) }
|
|
83
|
+
var urlToLoad by remember(source) { mutableStateOf(source) }
|
|
84
|
+
val density = LocalDensity.current
|
|
77
85
|
|
|
78
86
|
options?.let {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
imageOptions = Options(
|
|
88
|
+
alignment = options.alignment,
|
|
89
|
+
contentScale = options.contentScale,
|
|
90
|
+
colorFilter = options.colorFilter,
|
|
91
|
+
alpha = DefaultAlpha,
|
|
92
|
+
)
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
Box(
|
|
88
96
|
modifier = modifier
|
|
89
97
|
.semantics { contentDescription = "img|$source" }
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// }
|
|
102
|
-
// }
|
|
98
|
+
.onSizeChanged { size ->
|
|
99
|
+
if (source is String && supportedDomains.contains(source)) {
|
|
100
|
+
val widthPx = size.width.toFloat()
|
|
101
|
+
val pixelRatio = density.density
|
|
102
|
+
val pixelFitForWidth = widthPx * pixelRatio
|
|
103
|
+
val sizeKey = closestSizeForWidth(pixelFitForWidth)
|
|
104
|
+
urlToLoad = appendQueryParam(source, "size", sizeKey)
|
|
105
|
+
} else {
|
|
106
|
+
urlToLoad = source
|
|
107
|
+
}
|
|
108
|
+
}
|
|
103
109
|
) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
110
|
+
AsyncImage(
|
|
111
|
+
modifier = Modifier.matchParentSize(),
|
|
112
|
+
model = urlToLoad,
|
|
113
|
+
contentDescription = null,
|
|
114
|
+
contentScale = imageOptions.contentScale,
|
|
115
|
+
alignment = imageOptions.alignment,
|
|
116
|
+
colorFilter = imageOptions.colorFilter,
|
|
117
|
+
alpha = imageOptions.alpha,
|
|
118
|
+
onLoading = { imageState = ImageState.Loading },
|
|
119
|
+
onSuccess = { imageState = ImageState.Success },
|
|
120
|
+
onError = { imageState = ImageState.Error },
|
|
121
|
+
)
|
|
122
|
+
when (imageState) {
|
|
123
|
+
ImageState.Loading -> if (loading) Skeleton()
|
|
124
|
+
ImageState.Error -> Icon(
|
|
125
|
+
source = "media_fail",
|
|
126
|
+
color = AppTheme.current.colors.text.disable,
|
|
127
|
+
modifier = modifier
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
ImageState.Success -> {}
|
|
131
|
+
}
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
}
|