@momo-kits/native-kits 0.152.4-beta.3 → 0.152.4-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.
- package/package.json +7 -6
- package/shared/build.gradle.kts +74 -0
- package/CODE_OF_CONDUCT.md +0 -133
- package/CONTRIBUTING.md +0 -114
- package/LICENSE +0 -20
- package/README.md +0 -7
- package/build.gradle.kts +0 -32
- package/compose/MoMoComposeKits.podspec +0 -54
- package/compose/build.gradle.kts +0 -149
- package/compose/src/androidMain/AndroidManifest.xml +0 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -105
- package/compose/src/commonMain/composeResources/files/lottie_circle_loader.json +0 -1
- package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
- package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +0 -57
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +0 -201
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +0 -222
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +0 -48
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +0 -76
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +0 -76
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +0 -306
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +0 -33
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -715
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +0 -214
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -236
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +0 -69
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -77
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -27
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -334
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -345
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -90
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -131
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -543
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -23
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -69
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -143
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -179
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -111
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -384
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -160
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -234
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -223
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -232
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -236
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -228
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -364
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -34
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -85
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -33
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -338
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -95
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -64
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -91
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -84
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -208
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -172
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -199
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -237
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -191
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -306
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -191
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -258
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -59
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -68
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -49
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -232
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -111
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -94
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -159
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -232
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScaleSizeScope.kt +0 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -459
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -169
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -216
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -180
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -251
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -80
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -306
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -31
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -385
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -38
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -62
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -88
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -144
- package/gradle.properties +0 -19
- package/gradlew +0 -240
- package/gradlew.bat +0 -91
- package/ios/Application/ApplicationEnvironment.swift +0 -50
- package/ios/Application/Components.swift +0 -263
- package/ios/Application/ComposeApi.swift +0 -22
- package/ios/Application/FloatingButton.swift +0 -172
- package/ios/Application/HeaderRight.swift +0 -271
- package/ios/Application/Screen.swift +0 -249
- package/ios/Badge/BadgeDot.swift +0 -31
- package/ios/Button/Button.swift +0 -211
- package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +0 -126
- package/ios/Checkbox/Checkbox.swift +0 -81
- package/ios/Chip/Chip.swift +0 -96
- package/ios/Colors+Radius+Spacing/Colors.swift +0 -172
- package/ios/Colors+Radius+Spacing/Radius.swift +0 -22
- package/ios/Colors+Radius+Spacing/Spacing.swift +0 -12
- package/ios/Extensions/Color++.swift +0 -25
- package/ios/Icon/Icon.swift +0 -51
- package/ios/Image/Image.swift +0 -70
- package/ios/Input/Input.swift +0 -207
- package/ios/Input/InputPhoneNumber.swift +0 -176
- package/ios/Input/InputSearch.swift +0 -238
- package/ios/Input/InputTextArea.swift +0 -242
- package/ios/Lottie/LottieView.swift +0 -86
- package/ios/OTPKeyboard/KeyboardButton.swift +0 -41
- package/ios/OTPKeyboard/OTPKeyboard.swift +0 -145
- package/ios/Popup/PopupDisplay.swift +0 -284
- package/ios/Popup/PopupInput.swift +0 -96
- package/ios/Popup/PopupPromotion.swift +0 -73
- package/ios/PopupView/FullscreenPopup.swift +0 -251
- package/ios/PopupView/Modifiers.swift +0 -158
- package/ios/PopupView/PopupView.swift +0 -289
- package/ios/PopupView/Utils++.swift +0 -281
- package/ios/ScrollIndicator/ScrollIndicator.swift +0 -110
- package/ios/Swipeable/SwipeCell.swift +0 -278
- package/ios/Swipeable/SwipeCellModel.swift +0 -86
- package/ios/Switch/Switch.swift +0 -44
- package/ios/Template/Logo/Logo.swift +0 -75
- package/ios/Template/TrustBanner/TrustBanner.swift +0 -120
- package/ios/Theme.md +0 -18
- package/ios/Typography/Text.swift +0 -140
- package/ios/Typography/Typography.swift +0 -95
- package/ios/native-kits.podspec +0 -18
- package/settings.gradle.kts +0 -25
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.components
|
|
2
|
-
|
|
3
|
-
import androidx.compose.foundation.background
|
|
4
|
-
import androidx.compose.foundation.border
|
|
5
|
-
import androidx.compose.foundation.clickable
|
|
6
|
-
import androidx.compose.foundation.layout.Box
|
|
7
|
-
import androidx.compose.foundation.layout.size
|
|
8
|
-
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
9
|
-
import androidx.compose.runtime.Composable
|
|
10
|
-
import androidx.compose.runtime.remember
|
|
11
|
-
import androidx.compose.ui.Alignment
|
|
12
|
-
import androidx.compose.ui.Modifier
|
|
13
|
-
import androidx.compose.ui.draw.clip
|
|
14
|
-
import androidx.compose.ui.graphics.Color
|
|
15
|
-
import androidx.compose.ui.unit.Dp
|
|
16
|
-
import androidx.compose.ui.unit.dp
|
|
17
|
-
import vn.momo.kits.const.AppTheme
|
|
18
|
-
import vn.momo.kits.const.Colors
|
|
19
|
-
import vn.momo.kits.const.Radius
|
|
20
|
-
|
|
21
|
-
data class IconSpecs(
|
|
22
|
-
val width: Dp,
|
|
23
|
-
val height: Dp,
|
|
24
|
-
val radius: Dp,
|
|
25
|
-
val size: Dp
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
enum class IconSize(val value: IconSpecs) {
|
|
29
|
-
LARGE(
|
|
30
|
-
IconSpecs(
|
|
31
|
-
height = 48.dp,
|
|
32
|
-
radius = Radius.XL,
|
|
33
|
-
width = 48.dp,
|
|
34
|
-
size = 48.dp
|
|
35
|
-
)
|
|
36
|
-
),
|
|
37
|
-
SMALL(
|
|
38
|
-
IconSpecs(
|
|
39
|
-
height = 40.dp,
|
|
40
|
-
radius = Radius.XL,
|
|
41
|
-
width = 40.dp,
|
|
42
|
-
size = 40.dp
|
|
43
|
-
)
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Pre-computed shape to avoid repeated creation
|
|
48
|
-
private val iconButtonShape = RoundedCornerShape(Radius.XL)
|
|
49
|
-
|
|
50
|
-
// Cache for icon sizes to avoid repeated calculations
|
|
51
|
-
private val iconSizeMap = mapOf(
|
|
52
|
-
IconSize.SMALL to 16.dp,
|
|
53
|
-
IconSize.LARGE to 24.dp
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
@Composable
|
|
57
|
-
fun getIconStyle(type: ButtonType, color: Color? = null): Modifier {
|
|
58
|
-
val theme = AppTheme.current
|
|
59
|
-
|
|
60
|
-
return remember(type, color, theme) {
|
|
61
|
-
when (type) {
|
|
62
|
-
ButtonType.DISABLED -> Modifier
|
|
63
|
-
.background(theme.colors.background.disable, iconButtonShape)
|
|
64
|
-
.border(0.dp, Color.Unspecified, iconButtonShape)
|
|
65
|
-
|
|
66
|
-
ButtonType.PRIMARY -> Modifier
|
|
67
|
-
.background(theme.colors.primary, iconButtonShape)
|
|
68
|
-
.border(0.dp, Color.Unspecified, iconButtonShape)
|
|
69
|
-
|
|
70
|
-
ButtonType.SECONDARY -> Modifier
|
|
71
|
-
.background(theme.colors.background.surface, iconButtonShape)
|
|
72
|
-
.border(1.dp, theme.colors.border.default, iconButtonShape)
|
|
73
|
-
|
|
74
|
-
ButtonType.OUTLINE -> Modifier
|
|
75
|
-
.background(theme.colors.background.surface, iconButtonShape)
|
|
76
|
-
.border(1.dp, color ?: theme.colors.primary, iconButtonShape)
|
|
77
|
-
|
|
78
|
-
ButtonType.TONAL -> Modifier
|
|
79
|
-
.background(theme.colors.background.tonal, iconButtonShape)
|
|
80
|
-
.border(0.dp, Color.Unspecified, iconButtonShape)
|
|
81
|
-
|
|
82
|
-
ButtonType.DANGER -> Modifier
|
|
83
|
-
.background(theme.colors.error.primary, iconButtonShape)
|
|
84
|
-
.border(0.dp, Color.Unspecified, iconButtonShape)
|
|
85
|
-
|
|
86
|
-
ButtonType.TEXT -> Modifier
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Composable
|
|
92
|
-
fun getIconColor(type: ButtonType): Color {
|
|
93
|
-
val theme = AppTheme.current
|
|
94
|
-
return remember(type, theme) {
|
|
95
|
-
when (type) {
|
|
96
|
-
ButtonType.DISABLED -> theme.colors.text.disable
|
|
97
|
-
ButtonType.PRIMARY -> Colors.black_01
|
|
98
|
-
ButtonType.SECONDARY -> theme.colors.text.default
|
|
99
|
-
ButtonType.OUTLINE -> theme.colors.primary
|
|
100
|
-
ButtonType.TONAL -> theme.colors.primary
|
|
101
|
-
ButtonType.DANGER -> Colors.black_01
|
|
102
|
-
ButtonType.TEXT -> theme.colors.primary
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@Composable
|
|
108
|
-
fun IconButton(
|
|
109
|
-
onClick: () -> Unit,
|
|
110
|
-
type: ButtonType = ButtonType.PRIMARY,
|
|
111
|
-
size: IconSize = IconSize.SMALL,
|
|
112
|
-
icon: String = "",
|
|
113
|
-
) {
|
|
114
|
-
// Memoize icon size calculation
|
|
115
|
-
val iconSize = remember(size) {
|
|
116
|
-
iconSizeMap[size] ?: 16.dp
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Memoize enabled state
|
|
120
|
-
val isEnabled = remember(type) {
|
|
121
|
-
type != ButtonType.DISABLED
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Memoize radius for clipping
|
|
125
|
-
val radius = remember(size) {
|
|
126
|
-
size.value.radius
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
Box(
|
|
130
|
-
modifier = Modifier
|
|
131
|
-
.size(size.value.size)
|
|
132
|
-
.then(getIconStyle(type))
|
|
133
|
-
.clip(RoundedCornerShape(radius))
|
|
134
|
-
.clickable(enabled = isEnabled, onClick = onClick),
|
|
135
|
-
contentAlignment = Alignment.Center
|
|
136
|
-
) {
|
|
137
|
-
Icon(
|
|
138
|
-
source = icon,
|
|
139
|
-
color = getIconColor(type),
|
|
140
|
-
size = iconSize,
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.components
|
|
2
|
-
|
|
3
|
-
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
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
|
|
9
|
-
import androidx.compose.ui.Alignment
|
|
10
|
-
import androidx.compose.ui.Modifier
|
|
11
|
-
import androidx.compose.ui.graphics.ColorFilter
|
|
12
|
-
import androidx.compose.ui.graphics.DefaultAlpha
|
|
13
|
-
import androidx.compose.ui.graphics.painter.Painter
|
|
14
|
-
import androidx.compose.ui.layout.ContentScale
|
|
15
|
-
import androidx.compose.ui.semantics.contentDescription
|
|
16
|
-
import androidx.compose.ui.semantics.semantics
|
|
17
|
-
import androidx.compose.ui.platform.LocalDensity
|
|
18
|
-
import coil3.compose.AsyncImage
|
|
19
|
-
import vn.momo.kits.const.AppTheme
|
|
20
|
-
|
|
21
|
-
data class Options(
|
|
22
|
-
val alignment: Alignment = Alignment.TopStart,
|
|
23
|
-
val contentScale: ContentScale = ContentScale.Crop,
|
|
24
|
-
val colorFilter: ColorFilter? = null,
|
|
25
|
-
val alpha: Float = DefaultAlpha,
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
enum class ImageState {
|
|
29
|
-
Loading, Success, Error
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Cached domain set for better performance
|
|
33
|
-
private val supportedDomains = setOf(
|
|
34
|
-
"static.momocdn.net",
|
|
35
|
-
"img.mservice.com.vn",
|
|
36
|
-
"cdn.mservice.com.vn",
|
|
37
|
-
"img.mservice.io",
|
|
38
|
-
"image.momocdn.net"
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
// Pre-computed size chart for optimal image sizing
|
|
42
|
-
private val sizeChart = mapOf(
|
|
43
|
-
64 to "XXS",
|
|
44
|
-
128 to "XS",
|
|
45
|
-
256 to "S",
|
|
46
|
-
512 to "M",
|
|
47
|
-
768 to "L",
|
|
48
|
-
1024 to "XL",
|
|
49
|
-
2048 to "XXL"
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
// Optimized size selection using binary search approach
|
|
53
|
-
private fun closestSizeForWidth(width: Float): String {
|
|
54
|
-
val targetWidth = width.toInt()
|
|
55
|
-
return sizeChart.entries
|
|
56
|
-
.minByOrNull { kotlin.math.abs(it.key - targetWidth) }
|
|
57
|
-
?.value ?: "M"
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Cached regex for better URL parsing performance
|
|
61
|
-
private val urlHostRegex = Regex("^(?:https?://)?([^:/\\s]+)")
|
|
62
|
-
|
|
63
|
-
private fun getHostFromUrl(url: String): String? {
|
|
64
|
-
return try {
|
|
65
|
-
urlHostRegex.find(url)?.groupValues?.get(1)
|
|
66
|
-
} catch (_: Exception) {
|
|
67
|
-
null
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Optimized query parameter appending
|
|
72
|
-
private fun appendSizeQueryParam(url: String, value: String): String {
|
|
73
|
-
val fragmentIndex = url.indexOf('#')
|
|
74
|
-
val (baseUrl, fragment) = if (fragmentIndex != -1) {
|
|
75
|
-
url.take(fragmentIndex) to url.substring(fragmentIndex)
|
|
76
|
-
} else {
|
|
77
|
-
url to ""
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
val separator = if (baseUrl.contains('?')) "&" else "?"
|
|
81
|
-
return "${baseUrl}${separator}size=$value$fragment"
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Cache for processed URLs to avoid repeated calculations
|
|
85
|
-
private val urlCache = mutableMapOf<String, String>()
|
|
86
|
-
|
|
87
|
-
@Composable
|
|
88
|
-
fun Image(
|
|
89
|
-
source: Any,
|
|
90
|
-
modifier: Modifier = Modifier,
|
|
91
|
-
options: Options? = null,
|
|
92
|
-
loading: Boolean = true,
|
|
93
|
-
) {
|
|
94
|
-
val imageOptions = remember(options) {
|
|
95
|
-
options ?: Options()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
var imageState by remember { mutableStateOf(ImageState.Loading) }
|
|
99
|
-
val density = LocalDensity.current
|
|
100
|
-
|
|
101
|
-
BoxWithConstraints(
|
|
102
|
-
modifier = modifier.semantics { contentDescription = "img|$source" },
|
|
103
|
-
) {
|
|
104
|
-
val urlToLoad = remember(source, maxWidth, maxHeight, density) {
|
|
105
|
-
when (source) {
|
|
106
|
-
is String -> {
|
|
107
|
-
// Check cache first
|
|
108
|
-
val cacheKey = "$source|${maxWidth}|${density.density}"
|
|
109
|
-
urlCache[cacheKey] ?: run {
|
|
110
|
-
val processedUrl = processImageUrl(source, maxWidth, density)
|
|
111
|
-
urlCache[cacheKey] = processedUrl
|
|
112
|
-
processedUrl
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
else -> source
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
AsyncImage(
|
|
120
|
-
modifier = Modifier.matchParentSize(),
|
|
121
|
-
model = urlToLoad,
|
|
122
|
-
contentDescription = null,
|
|
123
|
-
contentScale = imageOptions.contentScale,
|
|
124
|
-
alignment = imageOptions.alignment,
|
|
125
|
-
colorFilter = imageOptions.colorFilter,
|
|
126
|
-
alpha = imageOptions.alpha,
|
|
127
|
-
onLoading = { imageState = ImageState.Loading },
|
|
128
|
-
onSuccess = { imageState = ImageState.Success },
|
|
129
|
-
onError = { imageState = ImageState.Error },
|
|
130
|
-
)
|
|
131
|
-
|
|
132
|
-
when (imageState) {
|
|
133
|
-
ImageState.Loading -> if (loading) Skeleton()
|
|
134
|
-
ImageState.Error -> {
|
|
135
|
-
val theme = AppTheme.current
|
|
136
|
-
Icon(
|
|
137
|
-
source = "media_fail",
|
|
138
|
-
color = theme.colors.text.disable,
|
|
139
|
-
modifier = Modifier.align(Alignment.Center)
|
|
140
|
-
)
|
|
141
|
-
}
|
|
142
|
-
ImageState.Success -> {}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Extracted URL processing logic for better performance
|
|
148
|
-
private fun processImageUrl(url: String, maxWidth: androidx.compose.ui.unit.Dp, density: androidx.compose.ui.unit.Density): String {
|
|
149
|
-
val host = getHostFromUrl(url)
|
|
150
|
-
return if (host != null && supportedDomains.contains(host)) {
|
|
151
|
-
val widthPx = with(density) { maxWidth.roundToPx() }
|
|
152
|
-
val pixelRatio = density.density
|
|
153
|
-
val pixelFitForWidth = widthPx * pixelRatio
|
|
154
|
-
val sizeKey = closestSizeForWidth(pixelFitForWidth)
|
|
155
|
-
appendSizeQueryParam(url, sizeKey)
|
|
156
|
-
} else {
|
|
157
|
-
url
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
@Composable
|
|
162
|
-
fun Image(
|
|
163
|
-
source: Painter,
|
|
164
|
-
modifier: Modifier = Modifier,
|
|
165
|
-
colorFilter: ColorFilter? = null,
|
|
166
|
-
alpha: Float = DefaultAlpha,
|
|
167
|
-
contentScale: ContentScale = ContentScale.Crop,
|
|
168
|
-
alignment: Alignment = Alignment.Center,
|
|
169
|
-
) {
|
|
170
|
-
androidx.compose.foundation.Image(
|
|
171
|
-
modifier = modifier,
|
|
172
|
-
painter = source,
|
|
173
|
-
contentDescription = null,
|
|
174
|
-
contentScale = contentScale,
|
|
175
|
-
alignment = alignment,
|
|
176
|
-
colorFilter = colorFilter,
|
|
177
|
-
alpha = alpha,
|
|
178
|
-
)
|
|
179
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.components
|
|
2
|
-
|
|
3
|
-
import androidx.compose.foundation.background
|
|
4
|
-
import androidx.compose.foundation.border
|
|
5
|
-
import androidx.compose.foundation.clickable
|
|
6
|
-
import androidx.compose.foundation.layout.Column
|
|
7
|
-
import androidx.compose.foundation.layout.Row
|
|
8
|
-
import androidx.compose.foundation.layout.height
|
|
9
|
-
import androidx.compose.foundation.layout.padding
|
|
10
|
-
import androidx.compose.foundation.layout.width
|
|
11
|
-
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
12
|
-
import androidx.compose.runtime.Composable
|
|
13
|
-
import androidx.compose.ui.Modifier
|
|
14
|
-
import androidx.compose.ui.draw.clip
|
|
15
|
-
import androidx.compose.ui.text.style.TextAlign
|
|
16
|
-
import androidx.compose.ui.unit.dp
|
|
17
|
-
import vn.momo.kits.const.Colors
|
|
18
|
-
import vn.momo.kits.const.Radius
|
|
19
|
-
import vn.momo.kits.const.Spacing
|
|
20
|
-
import vn.momo.kits.const.Typography
|
|
21
|
-
|
|
22
|
-
enum class InformationState {
|
|
23
|
-
DEFAULT,
|
|
24
|
-
WARNING,
|
|
25
|
-
ERROR
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Composable
|
|
29
|
-
fun Information(
|
|
30
|
-
title: String? = null,
|
|
31
|
-
description: String = "Description",
|
|
32
|
-
state: InformationState = InformationState.DEFAULT,
|
|
33
|
-
image: String? = null,
|
|
34
|
-
onPressAction: (() -> Unit)? = null,
|
|
35
|
-
showIcon: Boolean = true,
|
|
36
|
-
action: String? = null,
|
|
37
|
-
showIconClose: Boolean = true,
|
|
38
|
-
onPressClose: (() -> Unit)? = null,
|
|
39
|
-
) {
|
|
40
|
-
var borderColor = Colors.blue_07
|
|
41
|
-
var backgroundColor = Colors.blue_10
|
|
42
|
-
var color = Colors.blue_03
|
|
43
|
-
var iconSource = "notifications_info"
|
|
44
|
-
|
|
45
|
-
if (state === InformationState.WARNING) {
|
|
46
|
-
borderColor = Colors.yellow_06
|
|
47
|
-
backgroundColor = Colors.yellow_09
|
|
48
|
-
color = Colors.orange_03
|
|
49
|
-
iconSource = "24_notifications_alert_triangle"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (state === InformationState.ERROR) {
|
|
53
|
-
borderColor = Colors.red_07
|
|
54
|
-
backgroundColor = Colors.red_10
|
|
55
|
-
color = Colors.red_03
|
|
56
|
-
iconSource = "24_notifications_alert_octagon"
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
Column(
|
|
60
|
-
modifier = Modifier.border(
|
|
61
|
-
width = 0.5.dp,
|
|
62
|
-
shape = RoundedCornerShape(Radius.S),
|
|
63
|
-
color = borderColor
|
|
64
|
-
).background(color = backgroundColor)
|
|
65
|
-
.padding(Spacing.M)
|
|
66
|
-
) {
|
|
67
|
-
Row {
|
|
68
|
-
if (image != null) {
|
|
69
|
-
Image(
|
|
70
|
-
source = image,
|
|
71
|
-
modifier = Modifier.padding(end = Spacing.S).width(40.dp).height(40.dp).clip(
|
|
72
|
-
RoundedCornerShape(Radius.S)
|
|
73
|
-
)
|
|
74
|
-
)
|
|
75
|
-
}
|
|
76
|
-
if (image == null && showIcon) {
|
|
77
|
-
Icon(
|
|
78
|
-
source = iconSource,
|
|
79
|
-
size = 16.dp,
|
|
80
|
-
color = color,
|
|
81
|
-
modifier = Modifier.padding(end = Spacing.S)
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
Column(modifier = Modifier.weight(1f)) {
|
|
85
|
-
if (title != null) {
|
|
86
|
-
Text(title, style = Typography.labelDefaultMedium)
|
|
87
|
-
}
|
|
88
|
-
Text(description, style = Typography.descriptionDefaultRegular)
|
|
89
|
-
}
|
|
90
|
-
if (onPressClose != null && showIconClose) {
|
|
91
|
-
Icon(
|
|
92
|
-
source = "navigation_close",
|
|
93
|
-
size = 16.dp,
|
|
94
|
-
modifier = Modifier.clickable(onClick = onPressClose)
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (action != null && onPressAction != null) {
|
|
99
|
-
Row(modifier = Modifier.padding(top = Spacing.S)) {
|
|
100
|
-
Text(
|
|
101
|
-
action,
|
|
102
|
-
modifier = Modifier.weight(1f).clickable(onClick = onPressAction),
|
|
103
|
-
textAlign = TextAlign.End,
|
|
104
|
-
style = Typography.actionXsBold,
|
|
105
|
-
color = color
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
}
|