@momo-kits/native-kits 0.300.7-debug → 0.300.8-beta.1-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/CLAUDE.md +12 -8
- package/README.md +8 -7
- package/compose/build.gradle.kts +2 -4
- package/compose/build.gradle.kts.backup +1 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +1 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +60 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +20 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +5 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +7 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +18 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +15 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +4 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +13 -73
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +1 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -53
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +3 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +12 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +20 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +7 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +83 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +6 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +13 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +2 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +5 -22
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +6 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +55 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +1 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +3 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +22 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +18 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +5 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +123 -64
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +24 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -19
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +59 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +69 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +14 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +5 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +43 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +330 -149
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +87 -70
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +1 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +92 -261
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +31 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +46 -72
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +8 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +29 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +8 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +26 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +1 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +4 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +2 -3
- package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +44 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +2 -7
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +9 -18
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +1 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +3 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +5 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -12
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +11 -6
- package/gradle/libs.versions.toml +1 -3
- package/gradle.properties +1 -3
- package/ios/Application/ApplicationEnvironment.swift +6 -4
- package/ios/Application/DesignSystemKits.swift +59 -13
- package/ios/Application/DesignSystemKitsPayload.swift +0 -8
- package/ios/Application/LanguageSource.swift +2 -11
- package/ios/Application/Localize.swift +8 -35
- package/ios/Application/LocalizeModifier.swift +2 -11
- package/ios/Application/MaxApi.swift +3 -11
- package/ios/Avatar/Avatar.swift +0 -1
- package/ios/Badge/Badge.swift +5 -8
- package/ios/Badge/BadgeRibbon.swift +2 -5
- package/ios/Button/Button.swift +4 -8
- package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
- package/ios/Carousel/Carousel.swift +4 -17
- package/ios/Checkbox/Checkbox.swift +0 -2
- package/ios/Collapse/Collapse.swift +17 -11
- package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
- package/ios/DateTimePicker/DateTimePicker.swift +4 -10
- package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
- package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
- package/ios/DateTimePicker/WheelPicker.swift +2 -4
- package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Extensions/SkeletonUICompat.swift +0 -8
- package/ios/Icon/Icon.swift +3 -6
- package/ios/IconButton/IconButton.swift +2 -5
- package/ios/Input/ErrorView.swift +0 -7
- package/ios/Input/Input.swift +9 -20
- package/ios/Input/InputPhoneNumber.swift +37 -20
- package/ios/Input/InputSearch.swift +23 -12
- package/ios/Input/InputTextArea.swift +4 -13
- package/ios/InputDropDown/InputDropDown.swift +1 -11
- package/ios/InputMoney/InputMoney.swift +9 -28
- package/ios/InputOTP/InputOTP.swift +2 -9
- package/ios/Layout/HeaderLayout.swift +72 -0
- package/ios/Layout/Item.swift +1 -2
- package/ios/Layout/ModalLayout.swift +144 -0
- package/ios/Layout/ScreenLayout.swift +48 -31
- package/ios/Layout/Section.swift +2 -3
- package/ios/Loader/Loader.swift +3 -12
- package/ios/Lottie/LottieView.swift +0 -11
- package/ios/Navigation/BottomSheet.swift +73 -94
- package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
- package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
- package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
- package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
- package/ios/Navigation/Component/FloatingButton.swift +4 -11
- package/ios/Navigation/Component/Header.swift +35 -54
- package/ios/Navigation/Component/HeaderBackground.swift +2 -8
- package/ios/Navigation/Component/HeaderJourney.swift +4 -8
- package/ios/Navigation/Component/HeaderLocation.swift +4 -8
- package/ios/Navigation/Component/HeaderRight.swift +20 -22
- package/ios/Navigation/Component/HeaderTitle.swift +1 -6
- package/ios/Navigation/Component/HeaderUser.swift +4 -10
- package/ios/Navigation/Component/SideBar.swift +6 -21
- package/ios/Navigation/Component/SnackBar.swift +9 -13
- package/ios/Navigation/HostBackGestureBridge.swift +2 -9
- package/ios/Navigation/ModalScreen.swift +24 -13
- package/ios/Navigation/Navigation.swift +35 -19
- package/ios/Navigation/NavigationContainer.swift +4 -15
- package/ios/Navigation/Navigator.swift +21 -39
- package/ios/Navigation/StackScreen.swift +64 -51
- package/ios/Navigation/StackTransition.swift +7 -14
- package/ios/Navigation/SwipeBackHaptic.swift +2 -7
- package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
- package/ios/Pagination/PaginationDot.swift +0 -9
- package/ios/Pagination/PaginationNumber.swift +1 -9
- package/ios/Pagination/PaginationScroll.swift +2 -14
- package/ios/Pagination/PaginationWhiteDot.swift +1 -10
- package/ios/Popup/PopupDisplay.swift +7 -5
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/PopupView/FullscreenPopup.swift +3 -4
- package/ios/PopupView/PopupView.swift +2 -2
- package/ios/PopupView/Utils++.swift +1 -2
- package/ios/ProgressInfo/ProgressInfo.swift +2 -13
- package/ios/Skeleton/Skeleton.swift +5 -16
- package/ios/Slider/Slider.swift +5 -12
- package/ios/StatusBarTap/StatusBarTap.h +2 -3
- package/ios/StatusBarTap/StatusBarTap.m +3 -16
- package/ios/Stepper/Stepper.swift +8 -27
- package/ios/Steps/Steps.swift +29 -26
- package/ios/Swipeable/SwipeCell.swift +2 -2
- package/ios/Swipeable/SwipeCellModel.swift +3 -6
- package/ios/TabView/TabView.swift +14 -28
- package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
- package/ios/Title/Title.swift +1 -3
- package/ios/Tooltip/Tooltip.swift +4 -9
- package/ios/Typography/FontScale.swift +79 -24
- package/ios/Typography/Text.swift +6 -12
- package/ios/Typography/Typography.swift +8 -11
- package/ios/Uploader/Uploader.swift +2 -17
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +11 -2
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
- package/package.json +1 -1
- package/publish.sh +8 -2
- package/scripts/ci/build-swiftui.sh +22 -0
- package/scripts/ci/resolve-version.mjs +144 -0
- package/settings.gradle.kts +0 -1
|
@@ -31,8 +31,7 @@ private val LABEL_PAD_V = Spacing.XXS
|
|
|
31
31
|
private val LABEL_GAP = Spacing.XS // space between label and thumb top
|
|
32
32
|
|
|
33
33
|
|
|
34
|
-
private fun clamp(value: Float, min: Float, max: Float): Float =
|
|
35
|
-
min(kotlin.math.max(value, min), max)
|
|
34
|
+
private fun clamp(value: Float, min: Float, max: Float): Float = min(kotlin.math.max(value, min), max)
|
|
36
35
|
|
|
37
36
|
private fun getValueForPosition(
|
|
38
37
|
positionInView: Float,
|
|
@@ -65,28 +64,16 @@ private fun valueToFraction(value: Float, min: Float, max: Float): Float {
|
|
|
65
64
|
return clamp((value - min) / (max - min), 0f, 1f)
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
private fun formatLabel(value: Float): String
|
|
69
|
-
if (value == value.toLong().toFloat())
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
private fun formatLabel(value: Float): String {
|
|
68
|
+
if (value == value.toLong().toFloat()) {
|
|
69
|
+
return value.toLong().toString()
|
|
70
|
+
}
|
|
71
|
+
return ((value * 10).toLong() / 10.0).toString()
|
|
72
|
+
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
* Range slider
|
|
76
|
-
*
|
|
77
|
-
* @param min Minimum selectable value.
|
|
78
|
-
* @param max Maximum selectable value.
|
|
79
|
-
* @param step Snap increment between values.
|
|
80
|
-
* @param modifier Modifier applied to the root container.
|
|
81
|
-
* @param low Initial lower-thumb value (defaults to [min]).
|
|
82
|
-
* @param high Initial upper-thumb value (defaults to [max]).
|
|
83
|
-
* @param minRange Minimum required gap between low and high (default 0).
|
|
84
|
-
* @param disableRange When true only the low thumb is shown (single-value mode).
|
|
85
|
-
* @param floatingLabel When true a value label floats above the active thumb during drag.
|
|
86
|
-
* @param disabled Non-interactive; rendered in the disabled colour.
|
|
87
|
-
* @param onValueChanged Invoked with (low, high, byUser) on every value change.
|
|
88
|
-
* @param onSliderTouchStart Invoked when a drag gesture begins.
|
|
89
|
-
* @param onSliderTouchEnd Invoked when a drag gesture ends.
|
|
75
|
+
* Range slider ported from RN; [disableRange] keeps only the low thumb.
|
|
76
|
+
* [low]/[high] only seed the thumbs (not controlled); [minRange] is the minimum gap between them.
|
|
90
77
|
*/
|
|
91
78
|
@Composable
|
|
92
79
|
fun Slider(
|
|
@@ -107,7 +94,6 @@ fun Slider(
|
|
|
107
94
|
val theme = AppTheme.current
|
|
108
95
|
val density = LocalDensity.current
|
|
109
96
|
|
|
110
|
-
// Validated, step-snapped initial values
|
|
111
97
|
val initLow = remember(low, min, max, step) {
|
|
112
98
|
clamp(low ?: min, min, max)
|
|
113
99
|
}
|
|
@@ -118,7 +104,6 @@ fun Slider(
|
|
|
118
104
|
var lowValue by remember { mutableFloatStateOf(initLow) }
|
|
119
105
|
var highValue by remember { mutableFloatStateOf(initHigh) }
|
|
120
106
|
|
|
121
|
-
// Smoothly animated display fractions
|
|
122
107
|
val lowFraction by animateFloatAsState(
|
|
123
108
|
targetValue = valueToFraction(lowValue, min, max),
|
|
124
109
|
animationSpec = spring(stiffness = 1200f),
|
|
@@ -155,13 +140,11 @@ fun Slider(
|
|
|
155
140
|
modifier = Modifier
|
|
156
141
|
.fillMaxWidth()
|
|
157
142
|
.onGloballyPositioned { coords -> trackWidthPx = coords.size.width.toFloat() }
|
|
158
|
-
// ── Gesture handling ──────────────────────────────────────────
|
|
159
143
|
.pointerInput(disabled, min, max, step, minRange, disableRange) {
|
|
160
144
|
if (disabled) return@pointerInput
|
|
161
145
|
|
|
162
146
|
awaitPointerEventScope {
|
|
163
147
|
while (true) {
|
|
164
|
-
// Finger down
|
|
165
148
|
val downEvent = awaitPointerEvent()
|
|
166
149
|
val downChange = downEvent.changes.firstOrNull() ?: continue
|
|
167
150
|
val touchX = downChange.position.x
|
|
@@ -176,7 +159,6 @@ fun Slider(
|
|
|
176
159
|
isDragging = true
|
|
177
160
|
currentOnTouchStart(lowValue, highValue)
|
|
178
161
|
|
|
179
|
-
// Apply initial press
|
|
180
162
|
applyDrag(touchX, trackWidthPx, thumbSizePx,
|
|
181
163
|
min, max, step, minRange, draggingLow,
|
|
182
164
|
lowValue, highValue) { nl, nh ->
|
|
@@ -185,7 +167,6 @@ fun Slider(
|
|
|
185
167
|
currentOnValueChanged(nl, nh, true)
|
|
186
168
|
}
|
|
187
169
|
|
|
188
|
-
// Track move / release
|
|
189
170
|
while (true) {
|
|
190
171
|
val moveEvent = awaitPointerEvent()
|
|
191
172
|
val moveChange = moveEvent.changes.firstOrNull() ?: break
|
|
@@ -212,7 +193,6 @@ fun Slider(
|
|
|
212
193
|
val trackWidth = maxWidth
|
|
213
194
|
val availableWidth = trackWidth - THUMB_SIZE
|
|
214
195
|
|
|
215
|
-
// ── Floating label ────────────────────────────────────────────────
|
|
216
196
|
if (floatingLabel && isDragging) {
|
|
217
197
|
val activeFraction = if (draggingLow) lowFraction else highFraction
|
|
218
198
|
val activeValue = if (draggingLow) lowValue else highValue
|
|
@@ -244,7 +224,7 @@ fun Slider(
|
|
|
244
224
|
// Top padding pushes track + thumbs below the label when floatingLabel is on
|
|
245
225
|
val topPad = if (floatingLabel) THUMB_SIZE + LABEL_GAP else 0.dp
|
|
246
226
|
|
|
247
|
-
//
|
|
227
|
+
// Inactive track, full width
|
|
248
228
|
Box(
|
|
249
229
|
modifier = Modifier
|
|
250
230
|
.align(Alignment.TopStart)
|
|
@@ -256,7 +236,7 @@ fun Slider(
|
|
|
256
236
|
.background(trackInactiveColor)
|
|
257
237
|
)
|
|
258
238
|
|
|
259
|
-
//
|
|
239
|
+
// Active track: the selected range, or up to the single thumb
|
|
260
240
|
val activeStartFraction = if (disableRange) 0f else lowFraction
|
|
261
241
|
val activeEndFraction = if (disableRange) lowFraction else highFraction
|
|
262
242
|
val activeStartDp = THUMB_SIZE / 2 + availableWidth * activeStartFraction
|
|
@@ -275,7 +255,7 @@ fun Slider(
|
|
|
275
255
|
)
|
|
276
256
|
}
|
|
277
257
|
|
|
278
|
-
//
|
|
258
|
+
// Low thumb
|
|
279
259
|
Box(
|
|
280
260
|
modifier = Modifier
|
|
281
261
|
.align(Alignment.TopStart)
|
|
@@ -287,7 +267,7 @@ fun Slider(
|
|
|
287
267
|
.border(THUMB_BORDER, theme.colors.background.surface, RoundedCornerShape(percent = 100))
|
|
288
268
|
)
|
|
289
269
|
|
|
290
|
-
//
|
|
270
|
+
// High thumb
|
|
291
271
|
if (!disableRange) {
|
|
292
272
|
Box(
|
|
293
273
|
modifier = Modifier
|
|
@@ -304,8 +284,6 @@ fun Slider(
|
|
|
304
284
|
}
|
|
305
285
|
}
|
|
306
286
|
|
|
307
|
-
// ── Private drag helper ───────────────────────────────────────────────────────
|
|
308
|
-
|
|
309
287
|
private fun applyDrag(
|
|
310
288
|
positionX: Float,
|
|
311
289
|
trackWidthPx: Float,
|
|
@@ -63,8 +63,7 @@ private fun StepperButton(
|
|
|
63
63
|
val specs = remember(size) { stepperSizeSpecs[size] ?: stepperSizeSpecs[StepperSize.LARGE]!! }
|
|
64
64
|
|
|
65
65
|
val iconColor: Color = if (disabled) theme.colors.text.disable else theme.colors.primary
|
|
66
|
-
val iconName: String =
|
|
67
|
-
if (sign == "-") "24_navigation_minus_circle" else "24_navigation_plus_circle"
|
|
66
|
+
val iconName: String = if (sign == "-") "24_navigation_minus_circle" else "24_navigation_plus_circle"
|
|
68
67
|
|
|
69
68
|
val clickableModifier: Modifier = if (!disabled) {
|
|
70
69
|
Modifier.activeOpacityClickable(onClick = onPress)
|
|
@@ -101,8 +100,7 @@ private fun StepperNumberView(
|
|
|
101
100
|
val specs = remember(size) { stepperSizeSpecs[size] ?: stepperSizeSpecs[StepperSize.LARGE]!! }
|
|
102
101
|
|
|
103
102
|
val textColor: Color = if (disabled) theme.colors.text.disable else theme.colors.text.default
|
|
104
|
-
val borderColor: Color =
|
|
105
|
-
if (disabled) theme.colors.border.disable else theme.colors.border.default
|
|
103
|
+
val borderColor: Color = if (disabled) theme.colors.border.disable else theme.colors.border.default
|
|
106
104
|
|
|
107
105
|
val scaledFontSize = scaleSize(12.sp)
|
|
108
106
|
|
|
@@ -186,10 +186,9 @@ private fun StepsHorizontal(
|
|
|
186
186
|
StepsAlign.CENTER -> TextAlign.Center
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
val
|
|
190
|
-
|
|
191
|
-
val hideLineRight = align == StepsAlign.RIGHT ||
|
|
192
|
-
(align == StepsAlign.STRETCH && index == steps.size - 1)
|
|
189
|
+
val isStretch = align == StepsAlign.STRETCH
|
|
190
|
+
val hideLineLeft = align == StepsAlign.LEFT || (isStretch && index == 0)
|
|
191
|
+
val hideLineRight = align == StepsAlign.RIGHT || (isStretch && index == steps.size - 1)
|
|
193
192
|
|
|
194
193
|
val lineLeft = when {
|
|
195
194
|
index == 0 -> Color.Transparent
|
|
@@ -213,7 +212,6 @@ private fun StepsHorizontal(
|
|
|
213
212
|
),
|
|
214
213
|
horizontalAlignment = colAlign,
|
|
215
214
|
) {
|
|
216
|
-
// time label shown above the icon row
|
|
217
215
|
if (!item.time.isNullOrEmpty()) {
|
|
218
216
|
Text(
|
|
219
217
|
text = item.time,
|
|
@@ -313,7 +311,6 @@ private fun StepsVertical(
|
|
|
313
311
|
val completedLine = remember(theme.colors.primary) { theme.colors.primary.copy(alpha = 0.2f) }
|
|
314
312
|
val defaultLine = theme.colors.background.default
|
|
315
313
|
val useSmall = size == StepsSize.SMALL
|
|
316
|
-
// Fixed connector height; grows proportionally with content in practice
|
|
317
314
|
val connectorHeight: Dp = if (useSmall) 24.dp else 32.dp
|
|
318
315
|
|
|
319
316
|
Column(modifier = Modifier.fillMaxWidth()) {
|
|
@@ -412,23 +409,9 @@ private fun StepsVertical(
|
|
|
412
409
|
}
|
|
413
410
|
}
|
|
414
411
|
|
|
415
|
-
// ─── Public API ────────────────────────────────────────────────────────────────
|
|
416
|
-
|
|
417
412
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* Mirrors the React Native `Steps` component from `@momo-kits/step`.
|
|
421
|
-
*
|
|
422
|
-
* @param steps Ordered list of [StepItem] values to display.
|
|
423
|
-
* @param activeIndex Zero-based index of the currently active step.
|
|
424
|
-
* @param modifier Modifier applied to the outermost container.
|
|
425
|
-
* @param horizontal `true` renders a horizontal layout; defaults to vertical.
|
|
426
|
-
* @param size [StepsSize.SMALL] or [StepsSize.LARGE] — affects bubble and typography scale.
|
|
427
|
-
* @param useNumber Shows the 1-based step number inside the bubble instead of a check/dot icon.
|
|
428
|
-
* @param align Text and icon alignment in horizontal mode: LEFT, RIGHT, CENTER, or STRETCH.
|
|
429
|
-
* @param customIcon Icon source name rendered inside the active-step bubble (replaces the dot).
|
|
430
|
-
* @param disabled Dims all steps and suppresses all press callbacks.
|
|
431
|
-
* @param onPress Invoked with the tapped [StepItem] and its index; only fires for completed steps.
|
|
413
|
+
* Port of RN `Steps` (`@momo-kits/step`). [onPress] fires for completed steps only;
|
|
414
|
+
* [align] applies to the horizontal layout only.
|
|
432
415
|
*/
|
|
433
416
|
@Composable
|
|
434
417
|
fun Steps(
|
|
@@ -103,7 +103,6 @@ fun Swipe(
|
|
|
103
103
|
.height(height)
|
|
104
104
|
.conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) }
|
|
105
105
|
) {
|
|
106
|
-
// Left actions
|
|
107
106
|
if (left.isNotEmpty()) {
|
|
108
107
|
Row(
|
|
109
108
|
modifier = Modifier
|
|
@@ -122,7 +121,6 @@ fun Swipe(
|
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
// Right actions
|
|
126
124
|
if (right.isNotEmpty()) {
|
|
127
125
|
Row(
|
|
128
126
|
modifier = Modifier
|
|
@@ -29,7 +29,6 @@ fun Switch(
|
|
|
29
29
|
title: String? = "",
|
|
30
30
|
accessibilityId: String? = ""
|
|
31
31
|
) {
|
|
32
|
-
// Memoize color calculations to avoid repeated conditional logic
|
|
33
32
|
val colors = remember(value, disabled) {
|
|
34
33
|
val circleColor = if (value) Colors.black_01 else Colors.black_03
|
|
35
34
|
val bgColor = when {
|
|
@@ -49,12 +48,10 @@ fun Switch(
|
|
|
49
48
|
?: "toggle_${title?.takeIf { it.isNotEmpty() } ?: "unknown"}_$value"
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
// Memoize alignment calculation
|
|
53
51
|
val contentAlignment = remember(value) {
|
|
54
52
|
if (value) Alignment.CenterEnd else Alignment.CenterStart
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
// Memoize click handler to avoid lambda recreation
|
|
58
55
|
val onClickHandler = remember(onChange, value) {
|
|
59
56
|
{ onChange(!value) }
|
|
60
57
|
}
|
|
@@ -105,7 +105,6 @@ fun TabView(
|
|
|
105
105
|
.fillMaxWidth()
|
|
106
106
|
.conditional(IsShowBaseLineDebug) { border(1.dp, Colors.blue_03) },
|
|
107
107
|
) {
|
|
108
|
-
// Tab bar
|
|
109
108
|
when {
|
|
110
109
|
type == TabViewType.CARD -> CardTabBar(
|
|
111
110
|
tabs = tabs,
|
|
@@ -135,7 +134,6 @@ fun TabView(
|
|
|
135
134
|
)
|
|
136
135
|
}
|
|
137
136
|
|
|
138
|
-
// Content area
|
|
139
137
|
if (fitContent) {
|
|
140
138
|
Box(modifier = Modifier.fillMaxWidth()) {
|
|
141
139
|
tabs.getOrNull(selectedIndex)?.content?.invoke()
|
|
@@ -207,7 +205,6 @@ private fun DefaultTabBar(
|
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
207
|
|
|
210
|
-
// Animated underline indicator
|
|
211
208
|
TabUnderlineIndicator(offsetX = indicatorOffsetX, width = indicatorWidth, color = selectedColor)
|
|
212
209
|
}
|
|
213
210
|
}
|
|
@@ -291,7 +288,6 @@ private fun ScrollableTabBar(
|
|
|
291
288
|
}
|
|
292
289
|
}
|
|
293
290
|
|
|
294
|
-
// Animated underline indicator aligned to bottom of the bar
|
|
295
291
|
TabUnderlineIndicator(
|
|
296
292
|
offsetX = animatedX - scrollOffsetDp + Spacing.XS,
|
|
297
293
|
width = (animatedWidth - Spacing.XS * 2).coerceAtLeast(0.dp),
|
|
@@ -312,21 +308,14 @@ private fun CardTabBar(
|
|
|
312
308
|
val theme = AppTheme.current
|
|
313
309
|
val surface = theme.colors.background.surface
|
|
314
310
|
|
|
315
|
-
// react-kits `
|
|
316
|
-
// tab
|
|
317
|
-
// The card is 4dp taller, sits `Spacing.XS` higher, and is joined to the strip
|
|
318
|
-
// on each side by a curved "ear" — the browser-tab silhouette that gives this
|
|
319
|
-
// variant its name. Rendering the active tab in place (just taller) loses both
|
|
320
|
-
// the overlap and the ears, and the strip used the theme's `tonal` pink where
|
|
321
|
-
// react-kits uses `Colors.black_02`, so the bar came out pink and flat.
|
|
311
|
+
// As react-kits: a flat `black_02` strip of unselected tabs, with one raised card over it for the
|
|
312
|
+
// active tab, 4dp taller and joined to the strip by a curved "ear" on each side.
|
|
322
313
|
val pathWidth = if (tabs.size > 2) 22.dp else 28.dp
|
|
323
314
|
val isFirst = selectedIndex == 0
|
|
324
315
|
val isLast = selectedIndex == tabs.lastIndex
|
|
325
316
|
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
// the 4dp margin. Letting the 44dp card size this box instead left a 4dp band of
|
|
329
|
-
// background showing between the tabs and the panel they sit on.
|
|
317
|
+
// Only as tall as the flat strip: like react-kits' absolute card, the raised one overflows up into
|
|
318
|
+
// the 4dp top padding instead of adding height.
|
|
330
319
|
BoxWithConstraints(
|
|
331
320
|
modifier = Modifier
|
|
332
321
|
.fillMaxWidth()
|
|
@@ -368,17 +357,10 @@ private fun CardTabBar(
|
|
|
368
357
|
val active = tabs.getOrNull(selectedIndex) ?: return@BoxWithConstraints
|
|
369
358
|
Row(
|
|
370
359
|
modifier = Modifier
|
|
371
|
-
// Pinned to the strip's
|
|
372
|
-
// pixel; `requiredHeight` then grows it upward into the 4dp margin.
|
|
373
|
-
// Offsetting it up by hand instead left a sub-dp sliver of strip
|
|
374
|
-
// showing under the card once rounding got involved.
|
|
360
|
+
// Pinned to the strip's bottom so both end on the same pixel (a manual offset leaves a sub-dp sliver).
|
|
375
361
|
.align(Alignment.BottomStart)
|
|
376
362
|
.offset(x = itemWidth * selectedIndex - (if (isFirst) 0.dp else pathWidth))
|
|
377
|
-
//
|
|
378
|
-
// flat strip, so a plain height would be coerced down to 40 and the
|
|
379
|
-
// raised card would stop 4dp short of the panel below, leaving a grey
|
|
380
|
-
// sliver. react-kits gets this free — its card is absolutely
|
|
381
|
-
// positioned and ignores the parent box entirely.
|
|
363
|
+
// requiredHeight: a plain height is coerced to the 40dp box and stops 4dp short of the panel.
|
|
382
364
|
.requiredHeight(CARD_TAB_ACTIVE_HEIGHT),
|
|
383
365
|
verticalAlignment = Alignment.Bottom,
|
|
384
366
|
) {
|
|
@@ -7,11 +7,15 @@ import androidx.compose.runtime.remember
|
|
|
7
7
|
import androidx.compose.ui.Modifier
|
|
8
8
|
import androidx.compose.ui.graphics.Color
|
|
9
9
|
import androidx.compose.ui.text.AnnotatedString
|
|
10
|
+
import androidx.compose.ui.text.SpanStyle
|
|
10
11
|
import androidx.compose.ui.text.TextLayoutResult
|
|
11
12
|
import androidx.compose.ui.text.TextStyle
|
|
13
|
+
import androidx.compose.ui.text.buildAnnotatedString
|
|
14
|
+
import androidx.compose.ui.text.font.FontSynthesis
|
|
12
15
|
import androidx.compose.ui.text.style.TextAlign
|
|
13
16
|
import androidx.compose.ui.text.style.TextDecoration
|
|
14
17
|
import androidx.compose.ui.text.style.TextOverflow
|
|
18
|
+
import androidx.compose.ui.text.withStyle
|
|
15
19
|
import androidx.compose.ui.unit.TextUnit
|
|
16
20
|
import androidx.compose.ui.unit.dp
|
|
17
21
|
import vn.momo.kits.application.IsShowBaseLineDebug
|
|
@@ -75,14 +79,12 @@ fun Text(
|
|
|
75
79
|
accessibilityId: String? = null,
|
|
76
80
|
inlineContent: Map<String, InlineTextContent> = mapOf(),
|
|
77
81
|
) {
|
|
78
|
-
// Cache theme access to avoid repeated lookups
|
|
79
82
|
val theme = AppTheme.current
|
|
80
83
|
|
|
81
84
|
val fontSize = scaleSize(style.fontSize)
|
|
82
85
|
val lineHeight = scaleSize(style.lineHeight)
|
|
83
86
|
val font = getFontFamily(fontFamily ?: theme.font, style.fontWeight)
|
|
84
87
|
|
|
85
|
-
// Memoize color calculation
|
|
86
88
|
val textColor = remember(color, theme) {
|
|
87
89
|
color ?: theme.colors.text.default
|
|
88
90
|
}
|
|
@@ -95,13 +97,10 @@ fun Text(
|
|
|
95
97
|
)
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
// Memoize automation ID
|
|
99
100
|
val automationId = remember(accessibilityId, text) {
|
|
100
101
|
accessibilityId ?: text
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
// on/off baseline config value, default will be false
|
|
104
|
-
|
|
105
104
|
androidx.compose.material3.Text(
|
|
106
105
|
modifier = modifier.conditional(IsShowBaseLineDebug){
|
|
107
106
|
border(1.dp, Colors.blue_03)
|
|
@@ -123,3 +122,54 @@ fun Text(
|
|
|
123
122
|
)
|
|
124
123
|
}
|
|
125
124
|
|
|
125
|
+
// Highlighted keywords keep the caller's text size; only the weight changes.
|
|
126
|
+
@Composable
|
|
127
|
+
internal fun rememberHighlightedText(text: String, highlightText: List<String>): AnnotatedString {
|
|
128
|
+
// Host fonts are one file per weight: swap fontFamily and disable synthesis so the SemiBold file isn't
|
|
129
|
+
// faux-bolded again; fontWeight still applies when no host font is bundled and the system font is used.
|
|
130
|
+
val highlightWeight = Typography.headerXsSemibold.fontWeight
|
|
131
|
+
val highlightFontFamily = getFontFamily(AppTheme.current.font, highlightWeight)
|
|
132
|
+
return remember(text, highlightText, highlightFontFamily) {
|
|
133
|
+
buildHighlightedText(
|
|
134
|
+
text,
|
|
135
|
+
highlightText,
|
|
136
|
+
SpanStyle(
|
|
137
|
+
fontFamily = highlightFontFamily,
|
|
138
|
+
fontWeight = highlightWeight,
|
|
139
|
+
fontSynthesis = FontSynthesis.None,
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Whole-word matches only; the longest keyword wins when keywords overlap (RN parity).
|
|
146
|
+
private fun buildHighlightedText(
|
|
147
|
+
text: String,
|
|
148
|
+
highlightText: List<String>,
|
|
149
|
+
style: SpanStyle,
|
|
150
|
+
): AnnotatedString {
|
|
151
|
+
val keywords = highlightText.filter { it.isNotEmpty() }
|
|
152
|
+
if (keywords.isEmpty()) return AnnotatedString(text)
|
|
153
|
+
val regex = Regex(keywords.sortedByDescending { it.length }.joinToString("|") { Regex.escape(it) })
|
|
154
|
+
fun isWordChar(index: Int) = text.getOrNull(index)?.let { it.isLetterOrDigit() || it == '_' } == true
|
|
155
|
+
|
|
156
|
+
return buildAnnotatedString {
|
|
157
|
+
var lastIndex = 0
|
|
158
|
+
var searchFrom = 0
|
|
159
|
+
while (true) {
|
|
160
|
+
val match = regex.find(text, searchFrom) ?: break
|
|
161
|
+
val start = match.range.first
|
|
162
|
+
val end = match.range.last + 1
|
|
163
|
+
if (isWordChar(start - 1) || isWordChar(end)) {
|
|
164
|
+
searchFrom = start + 1
|
|
165
|
+
continue
|
|
166
|
+
}
|
|
167
|
+
append(text.substring(lastIndex, start))
|
|
168
|
+
withStyle(style) { append(match.value) }
|
|
169
|
+
lastIndex = end
|
|
170
|
+
searchFrom = end
|
|
171
|
+
}
|
|
172
|
+
append(text.substring(lastIndex))
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
@@ -89,10 +89,7 @@ fun Title(
|
|
|
89
89
|
.conditional(IsShowBaseLineDebug) {
|
|
90
90
|
border(1.dp, Colors.blue_03)
|
|
91
91
|
}
|
|
92
|
-
//
|
|
93
|
-
// plus, for a SECTION only, `marginTop: Spacing.S` (foundations/Title
|
|
94
|
-
// index.tsx). It has no padding at all, so the 8dp box here inset every
|
|
95
|
-
// title by 8dp against the web render.
|
|
92
|
+
// RN parity: only a Section gets a top margin; the root has no padding.
|
|
96
93
|
.padding(top = if (type == TitleType.Section) Spacing.S else 0.dp),
|
|
97
94
|
verticalAlignment = Alignment.CenterVertically
|
|
98
95
|
) {
|
|
@@ -105,7 +102,6 @@ fun Title(
|
|
|
105
102
|
IconAlign.Bottom -> Arrangement.Bottom
|
|
106
103
|
},
|
|
107
104
|
) {
|
|
108
|
-
// Icon
|
|
109
105
|
Icon(
|
|
110
106
|
source = it,
|
|
111
107
|
color = iconColor ?: theme.colors.text.default,
|
|
@@ -130,7 +126,6 @@ fun Title(
|
|
|
130
126
|
maxLines = if (showTrailingAction || badgeLabel != null) 1 else 2,
|
|
131
127
|
)
|
|
132
128
|
|
|
133
|
-
// Badge
|
|
134
129
|
badgeLabel?.let {
|
|
135
130
|
Spacer(modifier = Modifier.width(4.dp))
|
|
136
131
|
Badge(
|
|
@@ -163,7 +158,6 @@ fun Title(
|
|
|
163
158
|
}
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
// Description
|
|
167
161
|
description?.let {
|
|
168
162
|
Spacer(modifier = Modifier.height(4.dp))
|
|
169
163
|
Text(
|
|
@@ -49,17 +49,14 @@ class TooltipState {
|
|
|
49
49
|
var isVisible by mutableStateOf(false)
|
|
50
50
|
private set
|
|
51
51
|
|
|
52
|
-
/** Shows the tooltip. */
|
|
53
52
|
fun show() {
|
|
54
53
|
isVisible = true
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
/** Hides the tooltip. */
|
|
58
56
|
fun hide() {
|
|
59
57
|
isVisible = false
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
/** Toggles the tooltip visibility. */
|
|
63
60
|
fun toggle() {
|
|
64
61
|
isVisible = !isVisible
|
|
65
62
|
}
|
|
@@ -200,10 +197,10 @@ private fun TooltipPopupContent(
|
|
|
200
197
|
modifier = Modifier
|
|
201
198
|
.widthIn(max = tooltipMaxWidth)
|
|
202
199
|
.width(IntrinsicSize.Max)
|
|
203
|
-
.background(Colors.
|
|
200
|
+
.background(Colors.blue_03, tooltipShape)
|
|
204
201
|
.clip(tooltipShape)
|
|
205
202
|
.conditional(IsShowBaseLineDebug) {
|
|
206
|
-
border(1.dp, Colors.
|
|
203
|
+
border(1.dp, Colors.red_03)
|
|
207
204
|
}
|
|
208
205
|
.padding(Spacing.M)
|
|
209
206
|
) {
|
|
@@ -327,7 +324,7 @@ private fun TooltipArrow(
|
|
|
327
324
|
}
|
|
328
325
|
}
|
|
329
326
|
|
|
330
|
-
val arrowColor = Colors.
|
|
327
|
+
val arrowColor = Colors.blue_03
|
|
331
328
|
|
|
332
329
|
Box(modifier = modifier) {
|
|
333
330
|
Canvas(
|
|
@@ -152,7 +152,7 @@ private fun UploaderImageItem(
|
|
|
152
152
|
modifier = Modifier
|
|
153
153
|
.fillMaxSize()
|
|
154
154
|
.clip(RoundedCornerShape(Radius.XS))
|
|
155
|
-
.background(
|
|
155
|
+
.background(Colors.opacity_white_40),
|
|
156
156
|
contentAlignment = Alignment.Center,
|
|
157
157
|
) {
|
|
158
158
|
Skeleton()
|
package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt
CHANGED
|
@@ -7,9 +7,6 @@ import kotlinx.datetime.number
|
|
|
7
7
|
import kotlin.time.Clock
|
|
8
8
|
import kotlin.time.ExperimentalTime
|
|
9
9
|
|
|
10
|
-
/**
|
|
11
|
-
* Format a LocalDateTime object into a string
|
|
12
|
-
*/
|
|
13
10
|
fun formatLocalDateTime(dateTime: LocalDateTime, format: String = "yyyy-MM-dd HH:mm"): String {
|
|
14
11
|
return when (format) {
|
|
15
12
|
"yyyy-MM-dd HH:mm" -> "${dateTime.year}-${paddingNum(dateTime.month.number)}-${
|
|
@@ -28,16 +25,11 @@ fun formatLocalDateTime(dateTime: LocalDateTime, format: String = "yyyy-MM-dd HH
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
/**
|
|
32
|
-
* Pad a number with a leading zero if it's less than 10
|
|
33
|
-
*/
|
|
34
28
|
fun paddingNum(num: Int): String {
|
|
35
29
|
return if (num > 9) num.toString() else "0$num"
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
/**
|
|
39
|
-
* Get a list of days in a month
|
|
40
|
-
*/
|
|
32
|
+
/** Zero-padded days of [month], clipped to [minDate] / [maxDate] when they fall in it. */
|
|
41
33
|
fun getDaysInMonth(
|
|
42
34
|
year: Int,
|
|
43
35
|
month: Int,
|
|
@@ -70,9 +62,7 @@ fun getDaysInMonth(
|
|
|
70
62
|
return days
|
|
71
63
|
}
|
|
72
64
|
|
|
73
|
-
/**
|
|
74
|
-
* Get a list of months
|
|
75
|
-
*/
|
|
65
|
+
/** Zero-padded months of [currentYear], clipped to [minDate] / [maxDate] when they fall in it. */
|
|
76
66
|
fun getMonths(
|
|
77
67
|
minDate: LocalDateTime,
|
|
78
68
|
maxDate: LocalDateTime,
|
|
@@ -97,9 +87,6 @@ fun getMonths(
|
|
|
97
87
|
return months
|
|
98
88
|
}
|
|
99
89
|
|
|
100
|
-
/**
|
|
101
|
-
* Get a list of years
|
|
102
|
-
*/
|
|
103
90
|
fun getYears(minDate: LocalDateTime, maxDate: LocalDateTime): List<String> {
|
|
104
91
|
val startYear = minDate.year
|
|
105
92
|
val endYear = maxDate.year
|
|
@@ -112,9 +99,7 @@ fun getYears(minDate: LocalDateTime, maxDate: LocalDateTime): List<String> {
|
|
|
112
99
|
return years
|
|
113
100
|
}
|
|
114
101
|
|
|
115
|
-
/**
|
|
116
|
-
* Get a list of hours
|
|
117
|
-
*/
|
|
102
|
+
/** 1...12 when [hourMode] is 12, otherwise 0 until [hourMode]; zero-padded. */
|
|
118
103
|
fun getHours(hourMode: Int): List<String> {
|
|
119
104
|
val hours = mutableListOf<String>()
|
|
120
105
|
for (i in 0 until hourMode) {
|
|
@@ -124,9 +109,6 @@ fun getHours(hourMode: Int): List<String> {
|
|
|
124
109
|
return hours
|
|
125
110
|
}
|
|
126
111
|
|
|
127
|
-
/**
|
|
128
|
-
* Get a list of minutes
|
|
129
|
-
*/
|
|
130
112
|
fun getMinutes(interval: Int): List<String> {
|
|
131
113
|
// A non-positive interval would never reach 60.
|
|
132
114
|
val step = interval.coerceAtLeast(1)
|
|
@@ -139,22 +121,14 @@ fun getMinutes(interval: Int): List<String> {
|
|
|
139
121
|
return minutes
|
|
140
122
|
}
|
|
141
123
|
|
|
142
|
-
/**
|
|
143
|
-
* Time mode for 12-hour clock
|
|
144
|
-
*/
|
|
145
124
|
val timeMode = listOf("AM", "PM")
|
|
146
125
|
|
|
147
|
-
/**
|
|
148
|
-
* Get today's date
|
|
149
|
-
*/
|
|
150
126
|
@OptIn(ExperimentalTime::class)
|
|
151
127
|
fun getCurrentDateTime(): LocalDateTime {
|
|
152
128
|
return Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())
|
|
153
129
|
}
|
|
154
130
|
|
|
155
|
-
/**
|
|
156
|
-
* Create a date that's a certain number of years before or after the current date
|
|
157
|
-
*/
|
|
131
|
+
/** Now shifted by [years] (negative = past), keeping the hour and minute. */
|
|
158
132
|
fun createRelativeDate(years: Int): LocalDateTime {
|
|
159
133
|
val currentDateTime = getCurrentDateTime()
|
|
160
134
|
val period = DatePeriod(years = if (years < 0) -years else years)
|
|
@@ -190,10 +164,9 @@ internal fun getDateComponents(
|
|
|
190
164
|
formatParts.size == 1 && formatParts[0] == "HH"
|
|
191
165
|
}
|
|
192
166
|
|
|
193
|
-
val dayData =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
167
|
+
val dayData = remember(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate) {
|
|
168
|
+
getDaysInMonth(currentDate.year, currentDate.month, effectiveMinDate, effectiveMaxDate)
|
|
169
|
+
}
|
|
197
170
|
|
|
198
171
|
val monthData = remember(currentDate.year, effectiveMinDate, effectiveMaxDate) {
|
|
199
172
|
getMonths(effectiveMinDate, effectiveMaxDate, currentDate.year)
|
|
@@ -211,26 +184,25 @@ internal fun getDateComponents(
|
|
|
211
184
|
getMinutes(minuteInterval)
|
|
212
185
|
}
|
|
213
186
|
|
|
214
|
-
val dateComponents =
|
|
215
|
-
|
|
216
|
-
val components = mutableListOf<DateComponent>()
|
|
217
|
-
|
|
218
|
-
formatParts.forEach { part ->
|
|
219
|
-
when (part) {
|
|
220
|
-
"DD" -> components.add(DateComponent("day", dayData))
|
|
221
|
-
"MM" -> components.add(DateComponent("month", monthData))
|
|
222
|
-
"YYYY" -> components.add(DateComponent("year", yearData))
|
|
223
|
-
"HH" -> components.add(DateComponent("hour", hourData))
|
|
224
|
-
"mm" -> components.add(DateComponent("minute", minData))
|
|
225
|
-
}
|
|
226
|
-
}
|
|
187
|
+
val dateComponents = remember(formatParts, dayData, monthData, yearData, hourData, minData, isOnlyHour) {
|
|
188
|
+
val components = mutableListOf<DateComponent>()
|
|
227
189
|
|
|
228
|
-
|
|
229
|
-
|
|
190
|
+
formatParts.forEach { part ->
|
|
191
|
+
when (part) {
|
|
192
|
+
"DD" -> components.add(DateComponent("day", dayData))
|
|
193
|
+
"MM" -> components.add(DateComponent("month", monthData))
|
|
194
|
+
"YYYY" -> components.add(DateComponent("year", yearData))
|
|
195
|
+
"HH" -> components.add(DateComponent("hour", hourData))
|
|
196
|
+
"mm" -> components.add(DateComponent("minute", minData))
|
|
230
197
|
}
|
|
198
|
+
}
|
|
231
199
|
|
|
232
|
-
|
|
200
|
+
if (isOnlyHour) {
|
|
201
|
+
components.add(DateComponent("timeMode", timeMode))
|
|
233
202
|
}
|
|
234
203
|
|
|
204
|
+
components
|
|
205
|
+
}
|
|
206
|
+
|
|
235
207
|
return dateComponents
|
|
236
208
|
}
|