@momo-kits/native-kits 0.165.2-beta.2 → 0.165.2-beta.2-debug
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/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +190 -0
- package/compose/build.gradle.kts.backup +190 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +151 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +124 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +293 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +831 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +356 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +189 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +475 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +266 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +223 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +264 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +185 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +328 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +220 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +552 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +207 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitDesignSystem.kt +18 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +296 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +52 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +38 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +299 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +393 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +609 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +148 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +225 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +331 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +75 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +37 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +364 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +40 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +213 -0
- package/gradle/libs.versions.toml +69 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +26 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/ios-demo/README.md +120 -0
- package/local.properties +8 -0
- package/package.json +1 -1
- package/settings.gradle.kts +64 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package vn.momo.kits.modifier
|
|
2
|
+
|
|
3
|
+
import androidx.compose.animation.core.animateFloatAsState
|
|
4
|
+
import androidx.compose.foundation.clickable
|
|
5
|
+
import androidx.compose.foundation.gestures.detectTapGestures
|
|
6
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
7
|
+
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
|
8
|
+
import androidx.compose.runtime.getValue
|
|
9
|
+
import androidx.compose.runtime.remember
|
|
10
|
+
import androidx.compose.ui.Modifier
|
|
11
|
+
import androidx.compose.ui.composed
|
|
12
|
+
import androidx.compose.ui.graphics.graphicsLayer
|
|
13
|
+
import androidx.compose.ui.input.pointer.pointerInput
|
|
14
|
+
import androidx.compose.ui.platform.LocalFocusManager
|
|
15
|
+
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
16
|
+
import androidx.compose.ui.semantics.Role
|
|
17
|
+
|
|
18
|
+
fun Modifier.noFeedbackClickable(
|
|
19
|
+
enabled: Boolean = true, onClickLabel: String? = null, role: Role? = null, onClick: () -> Unit
|
|
20
|
+
): Modifier = composed {
|
|
21
|
+
clickable(
|
|
22
|
+
interactionSource = remember { MutableInteractionSource() },
|
|
23
|
+
indication = null,
|
|
24
|
+
enabled,
|
|
25
|
+
onClickLabel,
|
|
26
|
+
role,
|
|
27
|
+
onClick
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fun Modifier.activeOpacityClickable(
|
|
32
|
+
activeOpacity: Float = 0.2f,
|
|
33
|
+
enabled: Boolean = true,
|
|
34
|
+
onClickLabel: String? = null,
|
|
35
|
+
role: Role? = null,
|
|
36
|
+
onClick: () -> Unit
|
|
37
|
+
): Modifier = composed {
|
|
38
|
+
val interactionSource = remember { MutableInteractionSource() }
|
|
39
|
+
val isPressed by interactionSource.collectIsPressedAsState()
|
|
40
|
+
val animatedAlpha by animateFloatAsState(
|
|
41
|
+
targetValue = if (isPressed) activeOpacity else 1f,
|
|
42
|
+
label = "ActiveOpacity"
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
this
|
|
46
|
+
.graphicsLayer { alpha = animatedAlpha }
|
|
47
|
+
.clickable(
|
|
48
|
+
interactionSource = interactionSource,
|
|
49
|
+
indication = null,
|
|
50
|
+
enabled,
|
|
51
|
+
onClickLabel,
|
|
52
|
+
role,
|
|
53
|
+
onClick
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
fun Modifier.hideKeyboardOnTap() = composed {
|
|
57
|
+
val focusManager = LocalFocusManager.current
|
|
58
|
+
val keyboardManager = LocalSoftwareKeyboardController.current
|
|
59
|
+
|
|
60
|
+
pointerInput(Unit) {
|
|
61
|
+
detectTapGestures {
|
|
62
|
+
keyboardManager?.hide()
|
|
63
|
+
focusManager.clearFocus()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
package vn.momo.kits.modifier
|
|
2
|
+
|
|
3
|
+
import androidx.compose.animation.core.LinearEasing
|
|
4
|
+
import androidx.compose.animation.core.RepeatMode
|
|
5
|
+
import androidx.compose.animation.core.animateFloat
|
|
6
|
+
import androidx.compose.animation.core.infiniteRepeatable
|
|
7
|
+
import androidx.compose.animation.core.rememberInfiniteTransition
|
|
8
|
+
import androidx.compose.animation.core.tween
|
|
9
|
+
import androidx.compose.runtime.Composable
|
|
10
|
+
import androidx.compose.runtime.getValue
|
|
11
|
+
import androidx.compose.ui.Modifier
|
|
12
|
+
import androidx.compose.ui.draw.drawWithContent
|
|
13
|
+
import androidx.compose.ui.geometry.Offset
|
|
14
|
+
import androidx.compose.ui.graphics.Color
|
|
15
|
+
import androidx.compose.ui.graphics.drawscope.clipRect
|
|
16
|
+
import androidx.compose.ui.text.TextStyle
|
|
17
|
+
import androidx.compose.ui.text.drawText
|
|
18
|
+
import androidx.compose.ui.text.font.FontWeight
|
|
19
|
+
import androidx.compose.ui.text.rememberTextMeasurer
|
|
20
|
+
import androidx.compose.ui.unit.sp
|
|
21
|
+
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
22
|
+
import vn.momo.kits.const.Colors
|
|
23
|
+
|
|
24
|
+
@Suppress("ExperimentalAnnotationRetention")
|
|
25
|
+
@RequiresOptIn(
|
|
26
|
+
message = "This is internal API of native-kits, become internal in next sprint",
|
|
27
|
+
level = RequiresOptIn.Level.WARNING,
|
|
28
|
+
)
|
|
29
|
+
@Retention(AnnotationRetention.BINARY)
|
|
30
|
+
@Target(
|
|
31
|
+
AnnotationTarget.CLASS,
|
|
32
|
+
AnnotationTarget.FUNCTION,
|
|
33
|
+
AnnotationTarget.PROPERTY,
|
|
34
|
+
)
|
|
35
|
+
annotation class InternalApi
|
|
36
|
+
|
|
37
|
+
@Composable
|
|
38
|
+
fun DeprecatedModifier(text: String = "Deprecated component"): Modifier = debugMarker(
|
|
39
|
+
label = text,
|
|
40
|
+
background = Colors.red_04.copy(alpha = 0.7f),
|
|
41
|
+
textColor = Colors.red_01,
|
|
42
|
+
animationLabel = "deprecatedMarquee",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
@Composable
|
|
46
|
+
private fun debugMarker(
|
|
47
|
+
label: String,
|
|
48
|
+
background: Color,
|
|
49
|
+
textColor: Color,
|
|
50
|
+
animationLabel: String,
|
|
51
|
+
): Modifier {
|
|
52
|
+
if (!IsShowBaseLineDebug) return Modifier
|
|
53
|
+
|
|
54
|
+
val textMeasurer = rememberTextMeasurer()
|
|
55
|
+
val marquee = rememberInfiniteTransition(label = animationLabel)
|
|
56
|
+
val progress by marquee.animateFloat(
|
|
57
|
+
initialValue = 0f,
|
|
58
|
+
targetValue = 1f,
|
|
59
|
+
animationSpec = infiniteRepeatable(
|
|
60
|
+
animation = tween(durationMillis = 4000, easing = LinearEasing),
|
|
61
|
+
repeatMode = RepeatMode.Restart,
|
|
62
|
+
),
|
|
63
|
+
label = "${animationLabel}Progress",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return Modifier.drawWithContent {
|
|
67
|
+
drawContent()
|
|
68
|
+
drawRect(color = background)
|
|
69
|
+
|
|
70
|
+
if (size.width <= 0f || size.height <= 0f) return@drawWithContent
|
|
71
|
+
|
|
72
|
+
val fontPx = (size.width * 0.1f).coerceIn(12.sp.toPx(), 20.sp.toPx())
|
|
73
|
+
val style = TextStyle(
|
|
74
|
+
color = textColor,
|
|
75
|
+
fontSize = fontPx.toSp(),
|
|
76
|
+
fontWeight = FontWeight.Bold,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
val intrinsic = textMeasurer.measure(
|
|
80
|
+
text = label,
|
|
81
|
+
style = style,
|
|
82
|
+
maxLines = 1,
|
|
83
|
+
softWrap = false,
|
|
84
|
+
)
|
|
85
|
+
val textW = intrinsic.size.width
|
|
86
|
+
val textH = intrinsic.size.height
|
|
87
|
+
val y = (size.height - textH) / 2f
|
|
88
|
+
|
|
89
|
+
if (textW <= size.width) {
|
|
90
|
+
drawText(
|
|
91
|
+
textLayoutResult = intrinsic,
|
|
92
|
+
topLeft = Offset((size.width - textW) / 2f, y),
|
|
93
|
+
)
|
|
94
|
+
} else {
|
|
95
|
+
clipRect(right = size.width, bottom = size.height) {
|
|
96
|
+
val gap = textW * 0.5f
|
|
97
|
+
val travel = textW + gap
|
|
98
|
+
val x = -progress * travel
|
|
99
|
+
drawText(textLayoutResult = intrinsic, topLeft = Offset(x, y))
|
|
100
|
+
drawText(textLayoutResult = intrinsic, topLeft = Offset(x + travel, y))
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package vn.momo.kits.modifier
|
|
2
|
+
|
|
3
|
+
import androidx.compose.ui.Modifier
|
|
4
|
+
import androidx.compose.ui.draw.drawBehind
|
|
5
|
+
import androidx.compose.ui.graphics.Color
|
|
6
|
+
import androidx.compose.ui.graphics.Paint
|
|
7
|
+
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
|
|
8
|
+
import androidx.compose.ui.unit.Dp
|
|
9
|
+
import androidx.compose.ui.unit.dp
|
|
10
|
+
import vn.momo.kits.platform.setColor
|
|
11
|
+
import vn.momo.kits.platform.setMaskFilter
|
|
12
|
+
fun Modifier.shadow(
|
|
13
|
+
color: Color = Color.Black,
|
|
14
|
+
borderRadius: Dp = 0.dp,
|
|
15
|
+
blurRadius: Float = 0f,
|
|
16
|
+
offsetY: Dp = 0.dp,
|
|
17
|
+
offsetX: Dp = 0.dp,
|
|
18
|
+
spread: Dp = 0f.dp,
|
|
19
|
+
modifier: Modifier = Modifier
|
|
20
|
+
) = this.then(
|
|
21
|
+
modifier.drawBehind {
|
|
22
|
+
this.drawIntoCanvas {
|
|
23
|
+
val paint = Paint()
|
|
24
|
+
val frameworkPaint = paint.asFrameworkPaint()
|
|
25
|
+
val spreadPixel = spread.toPx()
|
|
26
|
+
val leftPixel = (0f - spreadPixel) + offsetX.toPx()
|
|
27
|
+
val topPixel = (0f - spreadPixel) + offsetY.toPx()
|
|
28
|
+
val rightPixel = (this.size.width + spreadPixel)
|
|
29
|
+
val bottomPixel = (0f + spreadPixel) - offsetY.toPx()
|
|
30
|
+
|
|
31
|
+
if (blurRadius != 0f) {
|
|
32
|
+
frameworkPaint.setMaskFilter(blurRadius)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
frameworkPaint.setColor(color)
|
|
36
|
+
|
|
37
|
+
it.drawRoundRect(
|
|
38
|
+
left = leftPixel,
|
|
39
|
+
top = topPixel,
|
|
40
|
+
right = rightPixel,
|
|
41
|
+
bottom = bottomPixel,
|
|
42
|
+
radiusX = borderRadius.toPx(),
|
|
43
|
+
radiusY = borderRadius.toPx(),
|
|
44
|
+
paint
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
package vn.momo.kits.modifier
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.State
|
|
5
|
+
import androidx.compose.ui.Modifier
|
|
6
|
+
import androidx.compose.ui.layout.Measurable
|
|
7
|
+
import androidx.compose.ui.layout.MeasureResult
|
|
8
|
+
import androidx.compose.ui.layout.MeasureScope
|
|
9
|
+
import androidx.compose.ui.node.LayoutModifierNode
|
|
10
|
+
import androidx.compose.ui.node.ModifierNodeElement
|
|
11
|
+
import androidx.compose.ui.unit.Constraints
|
|
12
|
+
import androidx.compose.ui.unit.IntOffset
|
|
13
|
+
|
|
14
|
+
@Composable
|
|
15
|
+
fun Modifier.dynamicSize(
|
|
16
|
+
widthState: State<Int>? = null,
|
|
17
|
+
heightState: State<Int>? = null,
|
|
18
|
+
) = this then DynamicSizeElement(widthState, heightState)
|
|
19
|
+
|
|
20
|
+
private data class DynamicSizeElement(
|
|
21
|
+
val widthState: State<Int>?,
|
|
22
|
+
val heightState: State<Int>?,
|
|
23
|
+
) : ModifierNodeElement<DynamicSizeNode>() {
|
|
24
|
+
override fun create(): DynamicSizeNode {
|
|
25
|
+
return DynamicSizeNode(widthState, heightState)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun update(node: DynamicSizeNode) {
|
|
29
|
+
node.widthState = widthState
|
|
30
|
+
node.heightState = heightState
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private class DynamicSizeNode(
|
|
36
|
+
var widthState: State<Int>?,
|
|
37
|
+
var heightState: State<Int>?,
|
|
38
|
+
) : Modifier.Node(), LayoutModifierNode {
|
|
39
|
+
override fun MeasureScope.measure(
|
|
40
|
+
measurable: Measurable,
|
|
41
|
+
constraints: Constraints
|
|
42
|
+
): MeasureResult {
|
|
43
|
+
val p = measurable.measure(constraints)
|
|
44
|
+
return layout(
|
|
45
|
+
width = widthState?.value ?: p.width,
|
|
46
|
+
height = heightState?.value ?: p.height,
|
|
47
|
+
) {
|
|
48
|
+
p.place(IntOffset.Zero)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.animation.core.Animatable
|
|
4
|
+
import androidx.compose.animation.core.CubicBezierEasing
|
|
5
|
+
import androidx.compose.animation.core.tween
|
|
6
|
+
import androidx.compose.foundation.background
|
|
7
|
+
import androidx.compose.foundation.border
|
|
8
|
+
import androidx.compose.foundation.gestures.detectDragGestures
|
|
9
|
+
import androidx.compose.foundation.layout.Box
|
|
10
|
+
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
11
|
+
import androidx.compose.foundation.layout.Column
|
|
12
|
+
import androidx.compose.foundation.layout.Row
|
|
13
|
+
import androidx.compose.foundation.layout.Spacer
|
|
14
|
+
import androidx.compose.foundation.layout.fillMaxHeight
|
|
15
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
16
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
17
|
+
import androidx.compose.foundation.layout.height
|
|
18
|
+
import androidx.compose.foundation.layout.heightIn
|
|
19
|
+
import androidx.compose.foundation.layout.offset
|
|
20
|
+
import androidx.compose.foundation.layout.padding
|
|
21
|
+
import androidx.compose.foundation.layout.size
|
|
22
|
+
import androidx.compose.foundation.layout.width
|
|
23
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
24
|
+
import androidx.compose.runtime.Composable
|
|
25
|
+
import androidx.compose.runtime.DisposableEffect
|
|
26
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
27
|
+
import androidx.compose.runtime.remember
|
|
28
|
+
import androidx.compose.runtime.rememberCoroutineScope
|
|
29
|
+
import androidx.compose.ui.Alignment
|
|
30
|
+
import androidx.compose.ui.Modifier
|
|
31
|
+
import androidx.compose.ui.graphics.Brush
|
|
32
|
+
import androidx.compose.ui.graphics.Color
|
|
33
|
+
import androidx.compose.ui.input.pointer.pointerInput
|
|
34
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
35
|
+
import androidx.compose.ui.unit.IntOffset
|
|
36
|
+
import androidx.compose.ui.unit.dp
|
|
37
|
+
import kotlinx.coroutines.launch
|
|
38
|
+
import vn.momo.kits.components.Divider
|
|
39
|
+
import vn.momo.kits.components.Icon
|
|
40
|
+
import vn.momo.kits.components.Text
|
|
41
|
+
import vn.momo.kits.const.AppTheme
|
|
42
|
+
import vn.momo.kits.const.Colors
|
|
43
|
+
import vn.momo.kits.const.Radius
|
|
44
|
+
import vn.momo.kits.const.Spacing
|
|
45
|
+
import vn.momo.kits.application.LocalContext
|
|
46
|
+
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
47
|
+
import vn.momo.kits.const.AppNavigationBar
|
|
48
|
+
import vn.momo.kits.const.Typography
|
|
49
|
+
import vn.momo.kits.navigation.tracking.ScreenTracker
|
|
50
|
+
import vn.momo.kits.modifier.conditional
|
|
51
|
+
import vn.momo.kits.modifier.noFeedbackClickable
|
|
52
|
+
import vn.momo.kits.platform.BackHandler
|
|
53
|
+
import vn.momo.kits.platform.getScreenHeight
|
|
54
|
+
|
|
55
|
+
@Composable
|
|
56
|
+
internal fun BottomSheet(
|
|
57
|
+
content: @Composable () -> Unit,
|
|
58
|
+
header: BottomHeader,
|
|
59
|
+
isSurface: Boolean = false,
|
|
60
|
+
barrierDismissible: Boolean = true,
|
|
61
|
+
draggable: Boolean = true,
|
|
62
|
+
useBottomInset: Boolean = true,
|
|
63
|
+
footerComponent: (@Composable () -> Unit)? = null,
|
|
64
|
+
onDismiss: (() -> Unit)?
|
|
65
|
+
) {
|
|
66
|
+
val screenHeightDp = getScreenHeight()
|
|
67
|
+
val screenHeightPx = with(LocalDensity.current) { screenHeightDp.toPx() }
|
|
68
|
+
val sheetOffset = remember { Animatable(screenHeightPx) }
|
|
69
|
+
|
|
70
|
+
val backgroundAlpha = remember { Animatable(0f) }
|
|
71
|
+
val dynamicAlpha = ((1f - (sheetOffset.value / screenHeightPx)).coerceIn(0f, 1f)) * 0.3f
|
|
72
|
+
val alpha = backgroundAlpha.value + dynamicAlpha
|
|
73
|
+
|
|
74
|
+
val sheetCloseOffset = with(LocalDensity.current) { 100.dp.toPx() }
|
|
75
|
+
|
|
76
|
+
val coroutineScope = rememberCoroutineScope()
|
|
77
|
+
|
|
78
|
+
val maxApi = LocalMaxApi.current
|
|
79
|
+
val context = LocalContext.current
|
|
80
|
+
|
|
81
|
+
DisposableEffect(Unit) {
|
|
82
|
+
ScreenTracker.trackPopupDisplayed(
|
|
83
|
+
maxApi = maxApi,
|
|
84
|
+
context = context,
|
|
85
|
+
parentScreenName = ScreenTracker.getLastScreenName()
|
|
86
|
+
)
|
|
87
|
+
onDispose { }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
suspend fun openEvent(){
|
|
91
|
+
backgroundAlpha.animateTo(
|
|
92
|
+
targetValue = 0.3f,
|
|
93
|
+
animationSpec = tween(
|
|
94
|
+
durationMillis = 100,
|
|
95
|
+
easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
sheetOffset.animateTo(
|
|
99
|
+
targetValue = 0f,
|
|
100
|
+
animationSpec = tween(
|
|
101
|
+
durationMillis = 350,
|
|
102
|
+
easing = CubicBezierEasing(0.05f, 0.7f, 0.1f, 1f)
|
|
103
|
+
)
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fun closeEvent(){
|
|
108
|
+
coroutineScope.launch {
|
|
109
|
+
sheetOffset.animateTo(
|
|
110
|
+
targetValue = screenHeightPx,
|
|
111
|
+
animationSpec = tween(
|
|
112
|
+
durationMillis = 200,
|
|
113
|
+
easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
backgroundAlpha.animateTo(
|
|
117
|
+
targetValue = 0f,
|
|
118
|
+
animationSpec = tween(
|
|
119
|
+
durationMillis = 100,
|
|
120
|
+
easing = CubicBezierEasing(0.3f, 0.0f, 0.8f, 0.15f)
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
LaunchedEffect(Unit) {
|
|
128
|
+
openEvent()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
DisposableEffect(Unit) {
|
|
132
|
+
OverplayComponentRegistry.bindClose { closeEvent() }
|
|
133
|
+
onDispose {
|
|
134
|
+
onDismiss?.invoke()
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
BackHandler(true){
|
|
139
|
+
closeEvent()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
BoxWithConstraints(
|
|
143
|
+
modifier = Modifier
|
|
144
|
+
.fillMaxSize()
|
|
145
|
+
.background(Color.Black.copy(alpha = alpha))
|
|
146
|
+
.noFeedbackClickable {
|
|
147
|
+
if(barrierDismissible) closeEvent()
|
|
148
|
+
}
|
|
149
|
+
) {
|
|
150
|
+
val parentHeight = with(LocalDensity.current) { constraints.maxHeight.toDp() }
|
|
151
|
+
|
|
152
|
+
Box(
|
|
153
|
+
modifier = Modifier
|
|
154
|
+
.align(Alignment.BottomCenter)
|
|
155
|
+
.offset { IntOffset(x = 0, y = sheetOffset.value.toInt()) }
|
|
156
|
+
.fillMaxWidth()
|
|
157
|
+
.heightIn(max = parentHeight - 90.dp)
|
|
158
|
+
.background(
|
|
159
|
+
color = if (isSurface) AppTheme.current.colors.background.surface else AppTheme.current.colors.background.default,
|
|
160
|
+
shape = RoundedCornerShape(topStart = Radius.M, topEnd = Radius.M)
|
|
161
|
+
)
|
|
162
|
+
.conditional(IsShowBaseLineDebug) {
|
|
163
|
+
border(1.dp, Colors.blue_03)
|
|
164
|
+
}
|
|
165
|
+
.noFeedbackClickable { },
|
|
166
|
+
contentAlignment = Alignment.BottomCenter
|
|
167
|
+
) {
|
|
168
|
+
val bottomInset = if (useBottomInset) {
|
|
169
|
+
(AppNavigationBar.current - keyboardSizeState().value).coerceAtLeast(0.dp)
|
|
170
|
+
} else 0.dp
|
|
171
|
+
Column(Modifier.padding(bottom = bottomInset)) {
|
|
172
|
+
Box(
|
|
173
|
+
modifier = Modifier
|
|
174
|
+
.height(72.dp)
|
|
175
|
+
.fillMaxWidth()
|
|
176
|
+
.conditional(draggable) {
|
|
177
|
+
pointerInput(Unit) {
|
|
178
|
+
detectDragGestures(
|
|
179
|
+
onDrag = { change, dragAmount ->
|
|
180
|
+
change.consume()
|
|
181
|
+
coroutineScope.launch {
|
|
182
|
+
val newOffset = (sheetOffset.value + dragAmount.y).coerceAtLeast(0f)
|
|
183
|
+
sheetOffset.snapTo(newOffset)
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
onDragEnd = {
|
|
187
|
+
coroutineScope.launch {
|
|
188
|
+
if (sheetOffset.value > sheetCloseOffset) {
|
|
189
|
+
closeEvent()
|
|
190
|
+
} else {
|
|
191
|
+
sheetOffset.animateTo(0f)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
) {
|
|
199
|
+
Column(
|
|
200
|
+
modifier = Modifier
|
|
201
|
+
.fillMaxSize()
|
|
202
|
+
.padding(horizontal = Spacing.M),
|
|
203
|
+
horizontalAlignment = Alignment.CenterHorizontally
|
|
204
|
+
) {
|
|
205
|
+
Spacer(Modifier.height(8.dp))
|
|
206
|
+
Box(
|
|
207
|
+
modifier = Modifier
|
|
208
|
+
.height(4.dp)
|
|
209
|
+
.width(40.dp)
|
|
210
|
+
.background(
|
|
211
|
+
color = Colors.black_06,
|
|
212
|
+
shape = RoundedCornerShape(Radius.S)
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
Spacer(Modifier.height(4.dp))
|
|
216
|
+
Box(Modifier.fillMaxWidth().height(56.dp), contentAlignment = Alignment.Center){
|
|
217
|
+
when (header) {
|
|
218
|
+
is BottomHeader.Title -> {
|
|
219
|
+
Row(modifier = Modifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
|
|
220
|
+
Box(Modifier.size(24.dp))
|
|
221
|
+
Box(Modifier.fillMaxHeight().weight(1f), contentAlignment = Alignment.Center){
|
|
222
|
+
Text(
|
|
223
|
+
text = header.data,
|
|
224
|
+
color = Colors.black_17,
|
|
225
|
+
style = Typography.headerDefaultBold
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
Box(Modifier
|
|
229
|
+
.size(24.dp)
|
|
230
|
+
.noFeedbackClickable {
|
|
231
|
+
closeEvent()
|
|
232
|
+
},
|
|
233
|
+
contentAlignment = Alignment.Center
|
|
234
|
+
){
|
|
235
|
+
Icon(source = "navigation_close")
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
is BottomHeader.Custom -> {
|
|
240
|
+
header.content()
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
Divider()
|
|
247
|
+
if (footerComponent != null) {
|
|
248
|
+
Box(Modifier.weight(1f, fill = false)) {
|
|
249
|
+
content()
|
|
250
|
+
}
|
|
251
|
+
BottomSheetFooter(footerComponent)
|
|
252
|
+
} else {
|
|
253
|
+
content()
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@Composable
|
|
261
|
+
private fun BottomSheetFooter(footerComponent: @Composable () -> Unit) {
|
|
262
|
+
val shadowBrush = remember {
|
|
263
|
+
Brush.verticalGradient(
|
|
264
|
+
colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
Box {
|
|
269
|
+
Box(
|
|
270
|
+
Modifier
|
|
271
|
+
.fillMaxWidth()
|
|
272
|
+
.background(AppTheme.current.colors.background.surface)
|
|
273
|
+
.conditional(IsShowBaseLineDebug) {
|
|
274
|
+
border(1.dp, Colors.blue_03)
|
|
275
|
+
}
|
|
276
|
+
.padding(vertical = Spacing.S)
|
|
277
|
+
) {
|
|
278
|
+
footerComponent()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
Box(
|
|
282
|
+
modifier = Modifier
|
|
283
|
+
.fillMaxWidth()
|
|
284
|
+
.height(6.dp)
|
|
285
|
+
.offset(x = 0.dp, y = (-6).dp)
|
|
286
|
+
.background(shadowBrush)
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
sealed class BottomHeader {
|
|
292
|
+
data class Title(
|
|
293
|
+
val data: String = "Bottom Sheet Title",
|
|
294
|
+
) : BottomHeader()
|
|
295
|
+
|
|
296
|
+
data class Custom(
|
|
297
|
+
val content: @Composable () -> Unit
|
|
298
|
+
) : BottomHeader()
|
|
299
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
interface HostBackTarget {
|
|
4
|
+
fun canPop(): Boolean
|
|
5
|
+
|
|
6
|
+
fun onBack()
|
|
7
|
+
|
|
8
|
+
fun backStarted()
|
|
9
|
+
fun backProgressed(progress: Float)
|
|
10
|
+
fun backCompleted()
|
|
11
|
+
fun backCancelled()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
object HostBackGestureBridge {
|
|
15
|
+
private val targets = mutableListOf<HostBackTarget>()
|
|
16
|
+
private var gestureTarget: HostBackTarget? = null
|
|
17
|
+
|
|
18
|
+
var shouldUseFloatingArrowBack: Boolean = false
|
|
19
|
+
|
|
20
|
+
fun checkCanPop(): Boolean = targets.isNotEmpty()
|
|
21
|
+
|
|
22
|
+
fun canPopInner(): Boolean = top()?.canPop() == true
|
|
23
|
+
|
|
24
|
+
fun pop() {
|
|
25
|
+
top()?.onBack()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun started() {
|
|
29
|
+
val target = top() ?: return
|
|
30
|
+
gestureTarget = target
|
|
31
|
+
target.backStarted()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fun progressed(progress: Float) {
|
|
35
|
+
gestureTarget?.backProgressed(progress.coerceIn(0f, 1f))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fun completed() {
|
|
39
|
+
(gestureTarget ?: top())?.backCompleted()
|
|
40
|
+
gestureTarget = null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fun cancelled() {
|
|
44
|
+
gestureTarget?.backCancelled()
|
|
45
|
+
gestureTarget = null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun attach(target: HostBackTarget) {
|
|
49
|
+
targets += target
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun detach(target: HostBackTarget) {
|
|
53
|
+
targets -= target
|
|
54
|
+
if (gestureTarget === target) gestureTarget = null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private fun top(): HostBackTarget? = targets.lastOrNull()
|
|
58
|
+
}
|