@momo-kits/native-kits 0.89.30-beta.1 → 0.89.30-beta.4

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.
@@ -4,6 +4,7 @@ import androidx.compose.animation.animateColorAsState
4
4
  import androidx.compose.foundation.background
5
5
  import androidx.compose.foundation.border
6
6
  import androidx.compose.foundation.clickable
7
+ import androidx.compose.foundation.interaction.MutableInteractionSource
7
8
  import androidx.compose.foundation.layout.Arrangement
8
9
  import androidx.compose.foundation.layout.Box
9
10
  import androidx.compose.foundation.layout.BoxWithConstraints
@@ -15,6 +16,7 @@ import androidx.compose.foundation.layout.padding
15
16
  import androidx.compose.foundation.layout.size
16
17
  import androidx.compose.foundation.layout.width
17
18
  import androidx.compose.foundation.shape.RoundedCornerShape
19
+ import androidx.compose.material.ripple.rememberRipple
18
20
  import androidx.compose.runtime.Composable
19
21
  import androidx.compose.runtime.LaunchedEffect
20
22
  import androidx.compose.runtime.getValue
@@ -24,12 +26,9 @@ import androidx.compose.runtime.setValue
24
26
  import androidx.compose.runtime.snapshotFlow
25
27
  import androidx.compose.ui.Alignment
26
28
  import androidx.compose.ui.Modifier
27
- import androidx.compose.ui.geometry.Offset
28
- import androidx.compose.ui.graphics.Brush
29
29
  import androidx.compose.ui.graphics.Color
30
30
  import androidx.compose.ui.graphics.graphicsLayer
31
31
  import androidx.compose.ui.layout.ContentScale
32
- import androidx.compose.ui.platform.LocalDensity
33
32
  import androidx.compose.ui.semantics.contentDescription
34
33
  import androidx.compose.ui.semantics.semantics
35
34
  import androidx.compose.ui.semantics.testTag
@@ -61,76 +60,45 @@ data class AnimatedHeader(
61
60
  )
62
61
 
63
62
  @Composable
64
- fun HeaderBackground(
65
- headerType: HeaderType = HeaderType.DEFAULT
63
+ fun HeaderImage(
64
+ headerType: HeaderType = HeaderType.DEFAULT,
65
+ headerBackground: String?,
66
66
  ) {
67
67
  val statusBarHeight = AppStatusBar.current ?: getStatusBarHeight()
68
68
  when (headerType) {
69
69
  HeaderType.DEFAULT -> {
70
70
  val height = statusBarHeight + 52.dp
71
- Box(
72
- modifier = Modifier.fillMaxWidth().height(height)
73
- .bottomBorder(
74
- strokeWidth = 1.dp,
75
- color = AppTheme.current.colors.border.default
76
- )
77
- ) {
78
- Box(
79
- modifier = Modifier
80
- .height(height)
81
- .fillMaxWidth()
82
- .background(
83
- Brush.linearGradient(
84
- colors = listOf(
85
- Color(0xFFFDCACE),
86
- Color(0x00FDCACE)
87
- ),
88
- start = Offset(0f, 0f),
89
- end = Offset(0f, with(LocalDensity.current) { 154.dp.toPx() })
90
- )
91
- )
71
+ Image(
72
+ source = headerBackground ?: "",
73
+ loading = false,
74
+ modifier = Modifier.fillMaxWidth().height(height),
75
+ options = Options(
76
+ contentScale = ContentScale.FillWidth
92
77
  )
93
- if (AppTheme.current.assets.headerBackground != null) {
94
- Image(
95
- source = AppTheme.current.assets.headerBackground!!,
96
- modifier = Modifier.fillMaxWidth().height(height),
97
- options = Options(
98
- contentScale = ContentScale.FillWidth
99
- )
100
- )
101
- }
102
- }
103
-
78
+ )
104
79
  }
105
80
 
106
81
  HeaderType.EXTENDED -> {
82
+ Image(
83
+ source = headerBackground ?: "",
84
+ loading = false,
85
+ modifier = Modifier.fillMaxWidth(),
86
+ options = Options(
87
+ contentScale = ContentScale.FillWidth
88
+ )
89
+ )
90
+ }
91
+
92
+ HeaderType.SURFACE -> {
93
+ val height = statusBarHeight + 52.dp
107
94
  Box(
108
- modifier = Modifier.fillMaxWidth().height(154.dp)
109
- .background(
110
- Brush.linearGradient(
111
- colors = listOf(
112
- Color(0xFFFDCACE),
113
- Color(0x00FDCACE)
114
- ),
115
- start = Offset(0f, 0f),
116
- end = Offset(0f, with(LocalDensity.current) { 154.dp.toPx() })
117
- )
118
- )
95
+ modifier = Modifier.fillMaxWidth().height(height)
96
+ .background(AppTheme.current.colors.background.surface)
119
97
  .bottomBorder(
120
- strokeWidth = 1.dp,
98
+ strokeWidth = 2.dp,
121
99
  color = AppTheme.current.colors.border.default
122
100
  )
123
- ) {
124
- if (AppTheme.current.assets.headerBackground != null) {
125
- Image(
126
- source = AppTheme.current.assets.headerBackground!!,
127
- modifier = Modifier.fillMaxWidth().height(154.dp),
128
- options = Options(
129
- contentScale = ContentScale.FillWidth
130
- )
131
- )
132
- }
133
- }
101
+ )
134
102
  }
135
103
 
136
104
  else -> {
@@ -152,16 +120,22 @@ fun Header(
152
120
  scrollState: Int = 0
153
121
  ) {
154
122
  val statusBarHeight = AppStatusBar.current ?: getStatusBarHeight()
155
- val tintIconColor = AppTheme.current.colors.text.default
156
- val backgroundButton = Colors.black_01.copy(alpha = 0.2f)
123
+ var tintIconColor = Colors.black_01
124
+ var backgroundButton = Colors.black_20.copy(alpha = 0.4f)
125
+ if (headerType == HeaderType.SURFACE) {
126
+ tintIconColor = AppTheme.current.colors.text.default
127
+ backgroundButton = Color.Transparent
128
+ }
157
129
 
158
130
  var colorFraction by remember { mutableStateOf(0f) }
159
131
 
160
132
  LaunchedEffect(scrollState) {
161
- snapshotFlow { scrollState }
162
- .map { (it / 50f).coerceIn(0f, 1f) }
163
- .distinctUntilChanged()
164
- .collect { fraction -> colorFraction = fraction }
133
+ if (headerType == HeaderType.SURFACE) {
134
+ snapshotFlow { scrollState }
135
+ .map { (it / 50f).coerceIn(0f, 1f) }
136
+ .distinctUntilChanged()
137
+ .collect { fraction -> colorFraction = fraction }
138
+ }
165
139
  }
166
140
 
167
141
  val tintIconColorAnim by animateColorAsState(
@@ -192,11 +166,15 @@ fun Header(
192
166
  modifier = Modifier
193
167
  .size(28.dp)
194
168
  .then(
195
- Modifier.border(
196
- 0.5.dp,
197
- Colors.black_20.copy(alpha = 0.4f),
198
- RoundedCornerShape(100)
199
- )
169
+ if (headerType == HeaderType.SURFACE) {
170
+ Modifier.border(
171
+ 0.5.dp,
172
+ Colors.black_20.copy(alpha = 0.4f),
173
+ RoundedCornerShape(100)
174
+ )
175
+ } else {
176
+ Modifier
177
+ }
200
178
  )
201
179
  .background(
202
180
  backgroundButton,
@@ -214,7 +192,7 @@ fun Header(
214
192
  ) {
215
193
  Icon(
216
194
  source = "ic_back_ios",
217
- color = if (animatedHeader !== null) tintIconColorAnim else tintIconColor,
195
+ color = if (headerType == HeaderType.SURFACE && animatedHeader !== null) tintIconColorAnim else tintIconColor,
218
196
  size = 20.dp,
219
197
  )
220
198
  }
@@ -245,7 +223,7 @@ fun Header(
245
223
  ) {
246
224
  HeaderTitle(
247
225
  title = title,
248
- color = if (animatedHeader !== null) tintIconColorAnim else tintIconColor,
226
+ color = if (headerType == HeaderType.SURFACE && animatedHeader !== null) tintIconColorAnim else tintIconColor,
249
227
  modifier = Modifier.semantics {
250
228
  contentDescription = "title_navigation_header"
251
229
  testTag = "title_navigation_header"
@@ -38,6 +38,7 @@ import vn.momo.kits.platform.getStatusBarHeight
38
38
 
39
39
  enum class HeaderType {
40
40
  DEFAULT,
41
+ SURFACE,
41
42
  EXTENDED,
42
43
  NONE
43
44
  }
@@ -45,6 +46,7 @@ enum class HeaderType {
45
46
  @Composable
46
47
  fun Screen(
47
48
  backgroundColor: Color? = null,
49
+ headerBackground: String? = null,
48
50
  isBack: Boolean = true,
49
51
  headerType: HeaderType = HeaderType.DEFAULT,
50
52
  verticalArrangement: Arrangement.Vertical = Arrangement.Top,
@@ -88,14 +90,18 @@ fun Screen(
88
90
  ) {
89
91
 
90
92
  if (animatedHeader === null) {
91
- HeaderBackground(headerType)
93
+ HeaderImage(
94
+ headerType,
95
+ headerBackground ?: AppTheme.current.assets.headerBackground
96
+ )
92
97
  } else {
93
98
  Box(
94
- Modifier.zIndex(5f)
95
- .background(Color.White.copy(alpha = opacity))
96
- .graphicsLayer { alpha = opacity }
97
- ) {
98
- HeaderBackground(headerType)
99
+ Modifier.zIndex(5f).background(Color.White.copy(alpha = opacity))
100
+ .graphicsLayer { alpha = opacity }) {
101
+ HeaderImage(
102
+ headerType,
103
+ headerBackground ?: AppTheme.current.assets.headerBackground
104
+ )
99
105
  }
100
106
  }
101
107
 
@@ -123,7 +129,9 @@ fun Screen(
123
129
  ) {
124
130
 
125
131
  Column(
126
- modifier = if (scrollable) Modifier.weight(1f).padding(bottom = keyboardSize).verticalScroll(scrollState) else Modifier.padding(bottom = keyboardSize),
132
+ modifier = if (scrollable) Modifier.weight(1f).padding(bottom = keyboardSize)
133
+ .verticalScroll(scrollState) else
134
+ Modifier.padding(bottom = keyboardSize),
127
135
  verticalArrangement = verticalArrangement,
128
136
  horizontalAlignment = horizontalAlignment
129
137
  ) {
@@ -148,7 +156,8 @@ fun Screen(
148
156
  scrollPosition = fabProps.scrollState?.value ?: scrollState.value,
149
157
  onClick = fabProps.onClick,
150
158
  containerColor = AppTheme.current.colors.primary,
151
- bottom = fabProps.bottom ?: if (footer != null) bottomPadding + 76.dp else bottomPadding + 12.dp,
159
+ bottom = fabProps.bottom
160
+ ?: if (footer != null) bottomPadding + 76.dp else bottomPadding + 12.dp,
152
161
  icon = fabProps.icon,
153
162
  iconColor = fabProps.iconColor,
154
163
  text = fabProps.label,
@@ -177,8 +186,11 @@ fun Footer(footer: @Composable (() -> Unit)? = null, keyboardSize: Dp = 0.dp, bo
177
186
  .background(AppTheme.current.colors.background.surface)
178
187
  ) {
179
188
  Box(
180
- Modifier.fillMaxWidth().padding(vertical = Spacing.S, horizontal = Spacing.M)
181
- ) {
189
+ Modifier
190
+ .fillMaxWidth()
191
+ .padding(vertical = Spacing.S, horizontal = Spacing.M)
192
+ )
193
+ {
182
194
  footer?.invoke()
183
195
  }
184
196
  }
@@ -33,7 +33,6 @@ fun CheckBox(
33
33
  var backgroundColor = AppTheme.current.colors.background.surface
34
34
  val iconSource = if (indeterminate) "minus" else "ic_checked"
35
35
 
36
-
37
36
  if (checked) {
38
37
  borderColor = AppTheme.current.colors.primary
39
38
  backgroundColor = AppTheme.current.colors.primary
@@ -1,17 +1,13 @@
1
1
  package vn.momo.kits.components
2
2
 
3
- import androidx.compose.foundation.layout.Box
4
- import androidx.compose.foundation.layout.fillMaxSize
5
3
  import androidx.compose.foundation.layout.size
6
4
  import androidx.compose.runtime.Composable
7
- import androidx.compose.ui.Alignment
8
5
  import androidx.compose.ui.Modifier
9
6
  import androidx.compose.ui.graphics.Color
10
7
  import androidx.compose.ui.graphics.ColorFilter
11
8
  import androidx.compose.ui.layout.ContentScale
12
9
  import androidx.compose.ui.unit.Dp
13
10
  import androidx.compose.ui.unit.dp
14
- import coil3.compose.AsyncImage
15
11
  import vn.momo.kits.const.AppTheme
16
12
  import vn.momo.kits.utils.Icons
17
13
 
@@ -25,16 +21,16 @@ fun Icon(
25
21
  val icon = if (source.contains("https")) {
26
22
  source
27
23
  } else {
28
- Icons[source]
24
+ Icons[source] ?: ""
29
25
  }
30
- Box(modifier.size(size), contentAlignment = Alignment.Center) {
31
- AsyncImage(
32
- modifier = Modifier.fillMaxSize(),
33
- model = icon,
34
- contentDescription = null,
26
+ Image(
27
+ modifier = modifier.size(size),
28
+ source = icon,
29
+ loading = false,
30
+ options = Options(
35
31
  contentScale = ContentScale.Fit,
36
32
  colorFilter = color?.let { ColorFilter.tint(it) }
37
- )
38
- }
33
+ ),
34
+ )
39
35
  }
40
36
 
@@ -15,7 +15,6 @@ import androidx.compose.ui.layout.ContentScale
15
15
  import androidx.compose.ui.semantics.contentDescription
16
16
  import androidx.compose.ui.semantics.semantics
17
17
  import androidx.compose.ui.semantics.testTag
18
- import androidx.compose.ui.unit.dp
19
18
  import coil3.compose.AsyncImage
20
19
  import vn.momo.kits.const.AppTheme
21
20
 
@@ -123,7 +123,10 @@ fun TrustBanner(
123
123
  modifier = Modifier
124
124
  .width(64.dp)
125
125
  .height(64.dp)
126
- .padding(end = 8.dp)
126
+ .padding(end = 8.dp),
127
+ options = Options(
128
+ contentScale = ContentScale.Fit,
129
+ )
127
130
  )
128
131
  Column {
129
132
  Text(
@@ -141,11 +144,17 @@ fun TrustBanner(
141
144
  .padding(end = 4.dp)
142
145
  .width(52.dp)
143
146
  .height(20.dp)
147
+ ,options = Options(
148
+ contentScale = ContentScale.Fit,
149
+ )
144
150
  )
145
151
  Image(
146
152
  source = trustBanner.sslImage, modifier = Modifier
147
153
  .width(52.dp)
148
- .height(20.dp)
154
+ .height(20.dp),
155
+ options = Options(
156
+ contentScale = ContentScale.Fit,
157
+ )
149
158
  )
150
159
  }
151
160
  Row(
@@ -106,7 +106,7 @@ val defaultTheme = Theme(
106
106
  ),
107
107
  font = "SFProText",
108
108
  assets = ThemeAssets(
109
- headerBackground = null
109
+ headerBackground = "https://static.momocdn.net/app/img/app/img/header-background.png"
110
110
  )
111
111
  )
112
112
 
@@ -168,5 +168,6 @@ val darkTheme = Theme(
168
168
 
169
169
 
170
170
  val AppTheme = staticCompositionLocalOf { defaultTheme }
171
-
172
- val AppStatusBar = staticCompositionLocalOf<Dp?> { null }
171
+ val AppStatusBar = staticCompositionLocalOf<Dp?> {
172
+ null
173
+ }
@@ -0,0 +1,26 @@
1
+ package vn.momo.kits.utils
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import coil3.ImageLoader
5
+ import coil3.annotation.ExperimentalCoilApi
6
+ import coil3.compose.setSingletonImageLoaderFactory
7
+ import coil3.disk.DiskCache
8
+ import coil3.memory.MemoryCache
9
+ import coil3.request.CachePolicy
10
+ import coil3.request.crossfade
11
+ import okio.FileSystem
12
+
13
+
14
+ @OptIn(ExperimentalCoilApi::class)
15
+ @Composable
16
+ fun setImageLoaderSingleton() {
17
+ setSingletonImageLoaderFactory { context ->
18
+ ImageLoader.Builder(context).memoryCachePolicy(CachePolicy.ENABLED).memoryCache {
19
+ MemoryCache.Builder().maxSizePercent(context, 0.3).strongReferencesEnabled(true).build()
20
+ }.diskCachePolicy(CachePolicy.ENABLED).networkCachePolicy(CachePolicy.ENABLED).diskCache {
21
+ DiskCache.Builder().directory(FileSystem.SYSTEM_TEMPORARY_DIRECTORY / "coil3_image_cache")
22
+ .maxSizeBytes(1024L * 1024 * 1024)
23
+ .build()
24
+ }.crossfade(false).build()
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.89.30-beta.1",
3
+ "version": "0.89.30-beta.4",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},