@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.
@@ -17,7 +17,6 @@ enum class TitlePosition {
17
17
  }
18
18
 
19
19
  data class AnimatedHeader(
20
- val type: HeaderType = HeaderType.DEFAULT,
21
20
  val composable: @Composable (scrollState: Int) -> Unit = {}
22
21
  )
23
22
 
@@ -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
- // var imageOptions = Options()
74
- // var imageState by remember { mutableStateOf(ImageState.Loading) }
75
- // var urlToLoad by remember(source) { mutableStateOf(source) }
76
- // val density = LocalDensity.current
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
- // imageOptions = Options(
80
- // alignment = options.alignment,
81
- // contentScale = options.contentScale,
82
- // colorFilter = options.colorFilter,
83
- // alpha = DefaultAlpha,
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
- // .onSizeChanged { size ->
91
- // val src = source as? String ?: return@onSizeChanged
92
- // val host = getHostFromUrl(src)
93
- // if (host != null && supportedDomains.contains(host)) {
94
- // val widthPx = size.width.toFloat()
95
- // val pixelRatio = density.density
96
- // val pixelFitForWidth = widthPx * pixelRatio
97
- // val sizeKey = closestSizeForWidth(pixelFitForWidth)
98
- // urlToLoad = appendQueryParam(src, "size", sizeKey)
99
- // } else {
100
- // urlToLoad = src
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
- // AsyncImage(
105
- // modifier = Modifier.matchParentSize(),
106
- // model = urlToLoad,
107
- // contentDescription = null,
108
- // contentScale = imageOptions.contentScale,
109
- // alignment = imageOptions.alignment,
110
- // colorFilter = imageOptions.colorFilter,
111
- // alpha = imageOptions.alpha,
112
- // onLoading = { imageState = ImageState.Loading },
113
- // onSuccess = { imageState = ImageState.Success },
114
- // onError = { imageState = ImageState.Error },
115
- // )
116
- // when (imageState) {
117
- // ImageState.Loading -> if (loading) Skeleton()
118
- // ImageState.Error -> Icon(
119
- // source = "media_fail",
120
- // color = AppTheme.current.colors.text.disable,
121
- // modifier = modifier
122
- // )
123
- //
124
- // ImageState.Success -> {}
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.120.0-beta.3",
3
+ "version": "0.120.0-beta.5",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},