@momo-kits/native-kits 0.169.13-beta.2 → 0.169.13-beta.3-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 +4 -1
- package/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +202 -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 +154 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +647 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +1411 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +130 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +524 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +559 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +741 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +221 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +270 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +849 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +212 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +239 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +252 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -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 +81 -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 +354 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -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 +130 -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 +482 -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 +86 -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 +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -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 +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -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 +88 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -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 +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -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 +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -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 +12 -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 +194 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -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 +315 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -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 +397 -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 +153 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -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 +750 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -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 +242 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
- 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 +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -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 +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -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 +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +154 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +1038 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +848 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +47 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +463 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +1146 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +667 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +240 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +185 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +200 -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 +117 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -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 +65 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
- 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 +143 -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 +24 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/ios/Navigation/BottomTab/BottomTabBar.swift +4 -14
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/README.md +120 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +3 -16
- package/package.json +1 -1
- package/scripts/sdui-visual/README.md +64 -0
- package/scripts/sdui-visual/diff.py +65 -0
- package/scripts/sdui-visual/drive.py +234 -0
- package/scripts/sdui-visual/plan.json +713 -0
- package/scripts/sdui-visual/run.sh +92 -0
- package/settings.gradle.kts +64 -0
|
@@ -0,0 +1,848 @@
|
|
|
1
|
+
// File: compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt
|
|
2
|
+
// Created At: 2026-10-30 10:00:00 +07:00
|
|
3
|
+
// Created By: AI
|
|
4
|
+
// AI Agent: Claude Code
|
|
5
|
+
// Model: claude-sonnet-5-5
|
|
6
|
+
|
|
7
|
+
package vn.momo.kits.sdui
|
|
8
|
+
|
|
9
|
+
import androidx.compose.foundation.layout.Box
|
|
10
|
+
import androidx.compose.foundation.layout.Column
|
|
11
|
+
import androidx.compose.runtime.Composable
|
|
12
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
13
|
+
import androidx.compose.runtime.MutableState
|
|
14
|
+
import androidx.compose.runtime.key
|
|
15
|
+
import androidx.compose.runtime.mutableStateOf
|
|
16
|
+
import androidx.compose.runtime.remember
|
|
17
|
+
import androidx.compose.ui.Modifier
|
|
18
|
+
import androidx.compose.ui.graphics.Color
|
|
19
|
+
import androidx.compose.ui.text.input.KeyboardType
|
|
20
|
+
import androidx.compose.ui.unit.Dp
|
|
21
|
+
import androidx.compose.ui.unit.dp
|
|
22
|
+
import vn.momo.kits.components.Avatar
|
|
23
|
+
import vn.momo.kits.components.InputFontWeight
|
|
24
|
+
import vn.momo.kits.components.AvatarSize
|
|
25
|
+
import vn.momo.kits.components.ButtonType
|
|
26
|
+
import vn.momo.kits.components.CheckBox
|
|
27
|
+
import vn.momo.kits.components.Collapse
|
|
28
|
+
import vn.momo.kits.components.Divider
|
|
29
|
+
import vn.momo.kits.components.DividerType
|
|
30
|
+
import vn.momo.kits.components.IconButton
|
|
31
|
+
import vn.momo.kits.components.IconShape
|
|
32
|
+
import vn.momo.kits.components.IconSize
|
|
33
|
+
import vn.momo.kits.components.Information
|
|
34
|
+
import vn.momo.kits.components.InformationState
|
|
35
|
+
import vn.momo.kits.components.Input
|
|
36
|
+
import vn.momo.kits.components.InputDropDown
|
|
37
|
+
import vn.momo.kits.components.InputMoney
|
|
38
|
+
import vn.momo.kits.components.InputOTP
|
|
39
|
+
import vn.momo.kits.components.InputPhoneNumber
|
|
40
|
+
import vn.momo.kits.components.InputPhoneNumberSize
|
|
41
|
+
import vn.momo.kits.components.InputSize
|
|
42
|
+
import vn.momo.kits.components.InputTextArea
|
|
43
|
+
import vn.momo.kits.components.Loader
|
|
44
|
+
import vn.momo.kits.components.LoaderType
|
|
45
|
+
import vn.momo.kits.components.PopupAction
|
|
46
|
+
import vn.momo.kits.components.PopupActionDirection
|
|
47
|
+
import vn.momo.kits.components.PopupNotify
|
|
48
|
+
import vn.momo.kits.components.PopupNotifyProps
|
|
49
|
+
import vn.momo.kits.components.PopupPromotion
|
|
50
|
+
import vn.momo.kits.components.ProgressInfo
|
|
51
|
+
import vn.momo.kits.components.ProgressInfoAlign
|
|
52
|
+
import vn.momo.kits.components.ProgressInfoItem
|
|
53
|
+
import vn.momo.kits.components.ProgressInfoSize
|
|
54
|
+
import vn.momo.kits.components.Radio
|
|
55
|
+
import vn.momo.kits.components.Rating
|
|
56
|
+
import vn.momo.kits.components.RatingSize
|
|
57
|
+
import vn.momo.kits.components.Skeleton
|
|
58
|
+
import vn.momo.kits.components.Slider
|
|
59
|
+
import vn.momo.kits.components.StepItem
|
|
60
|
+
import vn.momo.kits.components.Stepper
|
|
61
|
+
import vn.momo.kits.components.StepperSize
|
|
62
|
+
import vn.momo.kits.components.Steps
|
|
63
|
+
import vn.momo.kits.components.StepsAlign
|
|
64
|
+
import vn.momo.kits.components.StepsSize
|
|
65
|
+
import vn.momo.kits.components.SuggestAction
|
|
66
|
+
import vn.momo.kits.components.Swipe
|
|
67
|
+
import vn.momo.kits.components.SwipeAction
|
|
68
|
+
import vn.momo.kits.components.Switch
|
|
69
|
+
import vn.momo.kits.components.TagColor
|
|
70
|
+
import vn.momo.kits.components.TrustBanner
|
|
71
|
+
import vn.momo.kits.components.UploadImage
|
|
72
|
+
import vn.momo.kits.components.Uploader
|
|
73
|
+
import vn.momo.kits.components.CollapseTitleSize as CollapseSize
|
|
74
|
+
import vn.momo.kits.const.AppTheme
|
|
75
|
+
|
|
76
|
+
/** Same value as the kit Avatar's private `iconSupport` default (components/Avatar.kt); the kit is reused, never modified. */
|
|
77
|
+
internal const val AVATAR_ICON_SUPPORT_DEFAULT = "https://static.momocdn.net/app/img/kits/_indicator.png"
|
|
78
|
+
|
|
79
|
+
// AI-GENERATED START: SDUI nodes drawn by the remaining vn.momo.kits components (props -> kit parameters, callbacks -> actions)
|
|
80
|
+
/** Node types this file draws; the registry in SduiRenderer sends them to [KitNode]. */
|
|
81
|
+
internal val KIT_NODE_TYPES = setOf(
|
|
82
|
+
"Avatar", "CheckBox", "Collapse", "Divider", "IconButton", "Information", "Input", "InputDropDown", "InputMoney", "InputOTP",
|
|
83
|
+
"InputPhoneNumber", "InputTextArea", "Loader", "PopupNotify", "PopupPromotion", "ProgressInfo", "Radio", "Rating", "Skeleton",
|
|
84
|
+
"Slider", "Stepper", "Steps", "SuggestAction", "Swipe", "Switch", "TrustBanner", "Uploader",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
// ---- pure prop -> kit mapping (unit-tested) ------------------------------------------------------------------------
|
|
88
|
+
internal fun numOf(v: Any?): Double? = when (v) { is Number -> v.toDouble(); is String -> v.toDoubleOrNull(); else -> null }
|
|
89
|
+
internal fun intOf(v: Any?): Int? = numOf(v)?.toInt()
|
|
90
|
+
private fun strOrNull(v: Any?): String? = if (v == null) null else str(v)
|
|
91
|
+
/** A prop's text, or [default] only when the prop is absent: a binding that resolves to "" stays "". */
|
|
92
|
+
internal fun textOr(p: Map<String, Any?>, k: String, default: String): String = if (p[k] == null) default else str(p[k])
|
|
93
|
+
/** A size prop (number, "12", `Spacing.*` / `Radius.*` token) as a non-negative Dp. */
|
|
94
|
+
internal fun dpProp(v: Any?, default: Dp): Dp = (parseDp(v) ?: default).coerceAtLeast(0.dp)
|
|
95
|
+
/**
|
|
96
|
+
* Upper bound for a count the kit draws one item per (Rating stars, InputOTP cells, Pagination dots): a spec value like
|
|
97
|
+
* 1e9 would make the kit compose that many items and hang or run out of memory.
|
|
98
|
+
*/
|
|
99
|
+
internal const val MAX_SPEC_COUNT = 100
|
|
100
|
+
/** A count prop (maxLength, length...) that must not be negative. */
|
|
101
|
+
internal fun countProp(v: Any?): Int? = intOf(v)?.takeIf { it >= 0 }
|
|
102
|
+
|
|
103
|
+
/** A number handed to an action: whole values become Long (like every number in a spec), the rest Double. */
|
|
104
|
+
internal fun actionNumber(f: Float): Any = if (f % 1f == 0f) f.toLong() else f.toString().toDouble()
|
|
105
|
+
|
|
106
|
+
internal fun avatarSizeOf(v: Any?): AvatarSize {
|
|
107
|
+
val n = numOf(v)?.toInt() ?: 32
|
|
108
|
+
return when {
|
|
109
|
+
n <= 28 -> AvatarSize.SIZE_24
|
|
110
|
+
n <= 36 -> AvatarSize.SIZE_32
|
|
111
|
+
n <= 44 -> AvatarSize.SIZE_40
|
|
112
|
+
n <= 52 -> AvatarSize.SIZE_48
|
|
113
|
+
n <= 64 -> AvatarSize.SIZE_56
|
|
114
|
+
else -> AvatarSize.SIZE_72
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
internal fun inputSizeOf(v: Any?) = if (v == "large") InputSize.LARGE else InputSize.SMALL
|
|
118
|
+
internal fun phoneSizeOf(v: Any?) = if (v == "large") InputPhoneNumberSize.LARGE else InputPhoneNumberSize.SMALL
|
|
119
|
+
internal fun dividerTypeOf(v: Any?) = if (v == "dash") DividerType.DASH else DividerType.DEFAULT
|
|
120
|
+
/** Button iconLeft/iconRight: a kit icon name; anything else -> no icon. */
|
|
121
|
+
internal fun buttonIconOf(v: Any?): String = (v as? String) ?: ""
|
|
122
|
+
|
|
123
|
+
/** A boolean prop with a default: only a real boolean overrides it. */
|
|
124
|
+
internal fun boolOr(v: Any?, default: Boolean): Boolean = (v as? Boolean) ?: default
|
|
125
|
+
|
|
126
|
+
internal fun loaderTypeOf(v: Any?) = if (v == "spinner") LoaderType.SPINNER else LoaderType.DOT
|
|
127
|
+
internal fun iconButtonTypeOf(v: Any?) = when (v) {
|
|
128
|
+
"tonal" -> ButtonType.TONAL; "secondary" -> ButtonType.SECONDARY; "danger" -> ButtonType.DANGER
|
|
129
|
+
"outline" -> ButtonType.OUTLINE; "disabled" -> ButtonType.DISABLED; "text" -> ButtonType.TEXT; else -> ButtonType.PRIMARY
|
|
130
|
+
}
|
|
131
|
+
internal fun iconButtonSizeOf(v: Any?) = when (v) { "large" -> IconSize.LARGE; "medium" -> IconSize.MEDIUM; else -> IconSize.SMALL }
|
|
132
|
+
internal fun iconShapeOf(v: Any?) = if (v == "square") IconShape.SQUARE else IconShape.CIRCLE
|
|
133
|
+
internal fun informationStateOf(v: Any?) = when (v) { "warning" -> InformationState.WARNING; "error" -> InformationState.ERROR; else -> InformationState.DEFAULT }
|
|
134
|
+
internal fun collapseTitleSizeOf(v: Any?) = when (v) { "small" -> CollapseSize.Small; "large" -> CollapseSize.Large; else -> CollapseSize.Medium }
|
|
135
|
+
internal fun tagColorOf(v: Any?) = when (v) {
|
|
136
|
+
"blue" -> TagColor.Blue; "green" -> TagColor.Green; "orange" -> TagColor.Orange; "red" -> TagColor.Red; "grey" -> TagColor.Grey
|
|
137
|
+
else -> TagColor.Default
|
|
138
|
+
}
|
|
139
|
+
internal fun ratingSizeOf(v: Any?) = when (v) { "small" -> RatingSize.SMALL; "medium" -> RatingSize.MEDIUM; else -> RatingSize.LARGE }
|
|
140
|
+
internal fun stepperSizeOf(v: Any?) = if (v == "small") StepperSize.SMALL else StepperSize.LARGE
|
|
141
|
+
internal fun stepsSizeOf(v: Any?) = if (v == "small") StepsSize.SMALL else StepsSize.LARGE
|
|
142
|
+
internal fun stepsAlignOf(v: Any?) = when (v) { "left" -> StepsAlign.LEFT; "right" -> StepsAlign.RIGHT; "stretch" -> StepsAlign.STRETCH; else -> StepsAlign.CENTER }
|
|
143
|
+
internal fun progressSizeOf(v: Any?) = if (v == "small") ProgressInfoSize.Small else ProgressInfoSize.Large
|
|
144
|
+
internal fun progressAlignOf(v: Any?) = when (v) {
|
|
145
|
+
"left" -> ProgressInfoAlign.Left; "right" -> ProgressInfoAlign.Right; "stretch" -> ProgressInfoAlign.Stretch; else -> ProgressInfoAlign.Center
|
|
146
|
+
}
|
|
147
|
+
internal fun popupDirectionOf(v: Any?) = when (v) { "column" -> PopupActionDirection.COLUMN; "auto" -> PopupActionDirection.AUTO; else -> PopupActionDirection.ROW }
|
|
148
|
+
/**
|
|
149
|
+
* A keyboard prop: the usual names ("number-pad", "email-address"...) or the lowercase / snake_case kit constant
|
|
150
|
+
* ("number", "number_password"...). Unknown or absent -> [default] (the kit default of that component).
|
|
151
|
+
*/
|
|
152
|
+
internal fun keyboardTypeOr(v: Any?, default: KeyboardType): KeyboardType = when (snake(v)) {
|
|
153
|
+
"text" -> KeyboardType.Text
|
|
154
|
+
"ascii" -> KeyboardType.Ascii
|
|
155
|
+
"number_pad", "numeric", "number" -> KeyboardType.Number
|
|
156
|
+
"phone_pad", "phone" -> KeyboardType.Phone
|
|
157
|
+
"uri", "url" -> KeyboardType.Uri
|
|
158
|
+
"email_address", "email" -> KeyboardType.Email
|
|
159
|
+
"password" -> KeyboardType.Password
|
|
160
|
+
"number_password" -> KeyboardType.NumberPassword
|
|
161
|
+
"decimal_pad", "decimal" -> KeyboardType.Decimal
|
|
162
|
+
else -> default
|
|
163
|
+
}
|
|
164
|
+
internal fun keyboardTypeOf(v: Any?): KeyboardType = keyboardTypeOr(v, KeyboardType.Text)
|
|
165
|
+
/** `fontWeight`: "regular" / "bold"; unknown or absent -> [default] (REGULAR for Input / TextArea, BOLD for InputMoney). */
|
|
166
|
+
internal fun inputFontWeightOf(v: Any?, default: InputFontWeight): InputFontWeight = when (snake(v)) {
|
|
167
|
+
"regular" -> InputFontWeight.REGULAR; "bold" -> InputFontWeight.BOLD; else -> default
|
|
168
|
+
}
|
|
169
|
+
/** A colour prop; an absent or unreadable one falls back to [default] (the kit's own theme colour). */
|
|
170
|
+
internal fun colorOr(v: Any?, default: Color): Color = parseColor(v) ?: default
|
|
171
|
+
/** TrustBanner `onPress` hands the action the banner's link data as a string map. */
|
|
172
|
+
internal fun trustArg(m: Map<String, String>): Map<String, Any?> = m
|
|
173
|
+
internal fun progressItems(v: Any?) = v.asList().orEmpty().mapNotNull { it.asMap() }
|
|
174
|
+
.map { ProgressInfoItem(title = str(it["title"]), description = strOrNull(it["description"])) }
|
|
175
|
+
internal fun stepItems(v: Any?) = v.asList().orEmpty().mapNotNull { it.asMap() }.map {
|
|
176
|
+
StepItem(title = str(it["title"]), description = strOrNull(it["description"]), error = it["error"] == true, time = strOrNull(it["time"]))
|
|
177
|
+
}
|
|
178
|
+
internal fun uploadImages(v: Any?) = v.asList().orEmpty().mapNotNull { it.asMap() }
|
|
179
|
+
.map { UploadImage(uri = strOrNull(it["uri"]), loading = it["loading"] == true) }
|
|
180
|
+
/** What an action sees as `step` / `image` when a callback hands it a kit data object. */
|
|
181
|
+
internal fun stepArg(s: StepItem): Map<String, Any?> = mapOf("title" to s.title, "description" to s.description, "error" to s.error, "time" to s.time)
|
|
182
|
+
internal fun imageArg(i: UploadImage): Map<String, Any?> = mapOf("uri" to i.uri, "loading" to i.loading)
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Actions a callback runs: `actions` entries named [name] on the node, plus the KB form where the callback is itself a prop
|
|
186
|
+
* (`props.onAdd = {type: "setState", params: {...}}` / a list of actions). Read from the RAW props: resolving them early would evaluate `{v}` before
|
|
187
|
+
* the callback's args exist.
|
|
188
|
+
*/
|
|
189
|
+
internal fun actionsFor(node: Node, name: String): List<Any?> {
|
|
190
|
+
val out = ArrayList<Any?>()
|
|
191
|
+
node["actions"].asList()?.forEach { if (it.asMap()?.get("name") == name) out += it }
|
|
192
|
+
when (val inProps = node.props()[name]) {
|
|
193
|
+
is Map<*, *> -> out += inProps.asMap().orEmpty() + ("name" to name)
|
|
194
|
+
is List<*> -> inProps.forEach { a -> a.asMap()?.let { out += it + ("name" to name) } }
|
|
195
|
+
else -> Unit
|
|
196
|
+
}
|
|
197
|
+
return out
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Slider `disabled` (kit) or both of the KB's disabledLow + disabledHigh. */
|
|
201
|
+
internal fun sliderDisabled(p: Map<String, Any?>) = p["disabled"] == true || (p["disabledLow"] == true && p["disabledHigh"] == true)
|
|
202
|
+
|
|
203
|
+
/** `Stepper.disabled` is `true` or a BooleanArray [minus, plus] (the kit checks `is BooleanArray`, not a List). */
|
|
204
|
+
internal fun stepperDisabled(v: Any?): Any = when (v) { is List<*> -> BooleanArray(2) { v.getOrNull(it) == true }; else -> v == true }
|
|
205
|
+
|
|
206
|
+
/** Stepper numbers; the kit does `defaultValue.coerceIn(min, max)`, which throws when min > max. */
|
|
207
|
+
internal data class StepperArgs(val defaultValue: Int, val min: Int, val max: Int, val step: Int)
|
|
208
|
+
internal fun stepperArgs(p: Map<String, Any?>): StepperArgs {
|
|
209
|
+
val min = intOf(p["min"]) ?: 0
|
|
210
|
+
val max = maxOf(intOf(p["max"]) ?: 100, min)
|
|
211
|
+
return StepperArgs((intOf(p["defaultValue"]) ?: 0).coerceIn(min, max), min, max, intOf(p["step"]) ?: 1)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Actions of a button-style prop (`primary`, `secondary`, a Swipe action): its `actions`, each defaulting a missing `name` to
|
|
216
|
+
* "onPress". Read from the RAW prop (so `{v}` survives until the press); a prop that is a binding string uses the resolved map.
|
|
217
|
+
*/
|
|
218
|
+
internal fun propActions(raw: Any?, resolved: Any?): List<Any?> {
|
|
219
|
+
val holder = if (raw is Map<*, *>) raw.asMap() else resolved.asMap()
|
|
220
|
+
val acts = holder?.get("actions").let { if (it is String) resolved.asMap()?.get("actions") else it }
|
|
221
|
+
return acts.asList().orEmpty().mapNotNull { it.asMap() }.map { if (it["name"] == null) it + ("name" to "onPress") else it }
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** One Swipe side: the resolved action (label/icon/colour) with its raw press actions, at most 3 like the kit. */
|
|
225
|
+
internal class SwipeSpec(val label: String, val icon: String, val backgroundColor: Any?, val actions: List<Any?>)
|
|
226
|
+
internal fun swipeSpecs(raw: Any?, resolved: Any?): List<SwipeSpec> {
|
|
227
|
+
val rawList = (if (raw is List<*>) raw else resolved).asList().orEmpty()
|
|
228
|
+
val resList = resolved.asList().orEmpty()
|
|
229
|
+
return rawList.take(3).mapIndexedNotNull { i, r ->
|
|
230
|
+
val shown = resList.getOrNull(i).asMap() ?: r.asMap() ?: return@mapIndexedNotNull null
|
|
231
|
+
SwipeSpec(str(shown["label"]), str(shown["icon"]), shown["backgroundColor"], propActions(r, resList.getOrNull(i)))
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Re-key token for InputOTP: bumps when the bound value changed AND differs from what the user last typed
|
|
237
|
+
* (`set: {otp: ""}` clears it; echoing the typed text back does not re-create the field).
|
|
238
|
+
*/
|
|
239
|
+
internal class OtpSync(initial: String) {
|
|
240
|
+
var lastEmitted = initial
|
|
241
|
+
private var seen = initial
|
|
242
|
+
private var token = 0
|
|
243
|
+
fun tokenFor(bound: String): Int {
|
|
244
|
+
if (bound != seen) { seen = bound; if (bound != lastEmitted) { lastEmitted = bound; token++ } }
|
|
245
|
+
return token
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// ---- per-node args: every kit parameter a node derives from its props (pure, unit-tested) --------------------------------
|
|
250
|
+
/** Fires the callback [name] of the node with [args]; a no-op when the node declares no such action. */
|
|
251
|
+
internal typealias Fire = (String, List<Any?>) -> Unit
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The node's [Fire]: runs [dispatch] with the actions [node] declares for a callback (`actions` entries or the prop form, see
|
|
255
|
+
* [actionsFor]); a callback the node declares nothing for dispatches nothing.
|
|
256
|
+
*/
|
|
257
|
+
internal fun gatedFire(node: Node, dispatch: (actions: List<Any?>, name: String, args: List<Any?>) -> Unit): Fire = { name, args ->
|
|
258
|
+
val actions = actionsFor(node, name)
|
|
259
|
+
if (actions.isNotEmpty()) dispatch(actions, name, args)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** A prop's text, "" when absent. */
|
|
263
|
+
internal fun textProp(p: Map<String, Any?>, k: String): String = strOrNull(p[k]) ?: ""
|
|
264
|
+
|
|
265
|
+
internal data class AvatarArgs(
|
|
266
|
+
val size: AvatarSize, val rounded: Boolean, val name: String?, val image: String?, val showIconMomo: Boolean,
|
|
267
|
+
val showIconSupport: Boolean, val iconSupport: String, val accessibilityLabel: String?,
|
|
268
|
+
)
|
|
269
|
+
internal fun avatarArgsOf(p: Map<String, Any?>) = AvatarArgs(
|
|
270
|
+
size = avatarSizeOf(p["size"]), rounded = p["rounded"] != false, name = strOrNull(p["name"]), image = strOrNull(p["image"]),
|
|
271
|
+
showIconMomo = p["showIconMomo"] == true, showIconSupport = p["showIconSupport"] == true,
|
|
272
|
+
iconSupport = textOr(p, "iconSupport", AVATAR_ICON_SUPPORT_DEFAULT),
|
|
273
|
+
accessibilityLabel = strOrNull(p["accessibilityLabel"]),
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
internal data class CheckBoxArgs(
|
|
277
|
+
val disabled: Boolean, val checked: Boolean, val indeterminate: Boolean, val title: String, val onCheckedChange: (Boolean) -> Unit,
|
|
278
|
+
)
|
|
279
|
+
internal fun checkBoxArgsOf(p: Map<String, Any?>, fire: Fire) = CheckBoxArgs(
|
|
280
|
+
disabled = p["disabled"] == true, checked = p["value"] == true, indeterminate = p["indeterminate"] == true,
|
|
281
|
+
title = textProp(p, "label"), onCheckedChange = { fire("onChange", listOf(it)) },
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
internal data class SwitchArgs(
|
|
285
|
+
val value: Boolean, val disabled: Boolean, val title: String, val accessibilityId: String?, val onChange: (Boolean) -> Unit,
|
|
286
|
+
)
|
|
287
|
+
internal fun switchArgsOf(p: Map<String, Any?>, fire: Fire) = SwitchArgs(
|
|
288
|
+
value = p["value"] == true, disabled = p["disabled"] == true, title = strOrNull(p["label"] ?: p["title"]) ?: "",
|
|
289
|
+
accessibilityId = strOrNull(p["accessibilityLabel"]), onChange = { fire("onChange", listOf(it)) },
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
internal data class RadioArgs(val value: Any, val groupValue: Any, val disabled: Boolean, val label: String, val onChange: () -> Unit)
|
|
293
|
+
internal fun radioArgsOf(p: Map<String, Any?>, fire: Fire) = RadioArgs(
|
|
294
|
+
value = p["value"] ?: "", groupValue = p["groupValue"] ?: "", disabled = p["disabled"] == true,
|
|
295
|
+
label = textProp(p, "label"), onChange = { fire("onChange", emptyList()) },
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
internal data class DividerArgs(val useMargin: Boolean, val type: DividerType)
|
|
299
|
+
internal fun dividerArgsOf(p: Map<String, Any?>) = DividerArgs(useMargin = boolOr(p["useMargin"], false), type = dividerTypeOf(p["type"]))
|
|
300
|
+
|
|
301
|
+
internal data class LoaderArgs(val type: LoaderType, val tintColor: Color?)
|
|
302
|
+
internal fun loaderArgsOf(p: Map<String, Any?>) = LoaderArgs(type = loaderTypeOf(p["type"]), tintColor = parseColor(p["color"]))
|
|
303
|
+
|
|
304
|
+
internal data class IconButtonArgs(val onClick: () -> Unit, val type: ButtonType, val size: IconSize, val shape: IconShape, val icon: String)
|
|
305
|
+
internal fun iconButtonArgsOf(p: Map<String, Any?>, fire: Fire) = IconButtonArgs(
|
|
306
|
+
onClick = { fire("onPress", emptyList()) }, type = iconButtonTypeOf(p["type"]), size = iconButtonSizeOf(p["size"]),
|
|
307
|
+
shape = iconShapeOf(p["shape"]), icon = textProp(p, "icon"),
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
internal data class InformationArgs(
|
|
311
|
+
val title: String?, val description: String, val state: InformationState, val image: String?, val onPressAction: (() -> Unit)?,
|
|
312
|
+
val showIcon: Boolean, val action: String?, val showIconClose: Boolean, val onPressClose: (() -> Unit)?,
|
|
313
|
+
val accessibilityLabel: String?, val highlightText: List<String>,
|
|
314
|
+
)
|
|
315
|
+
internal fun informationArgsOf(p: Map<String, Any?>, has: (String) -> Boolean, fire: Fire) = InformationArgs(
|
|
316
|
+
title = strOrNull(p["title"]), description = textOr(p, "description", "Description"), state = informationStateOf(p["state"]),
|
|
317
|
+
image = strOrNull(p["image"]), onPressAction = if (has("onPressCTA")) { { fire("onPressCTA", emptyList()) } } else null,
|
|
318
|
+
showIcon = boolOr(p["showIcon"], true),
|
|
319
|
+
action = strOrNull(p["CTA"]), showIconClose = boolOr(p["showIconClose"], true),
|
|
320
|
+
onPressClose = if (has("onPressClose")) { { fire("onPressClose", emptyList()) } } else null,
|
|
321
|
+
accessibilityLabel = strOrNull(p["accessibilityLabel"]),
|
|
322
|
+
highlightText = p["highlightText"].asList().orEmpty().map(::str),
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
internal data class InputArgs(
|
|
326
|
+
val floatingValue: String, val floatingIcon: String, val placeholder: String, val size: InputSize, val onChangeText: (String) -> Unit,
|
|
327
|
+
val hintText: String, val error: String, val errorSpacing: Boolean, val disabled: Boolean, val readOnly: Boolean,
|
|
328
|
+
val secureTextEntry: Boolean, val icon: String, val onRightIconPressed: () -> Unit, val leadingIcon: String, val onFocus: () -> Unit,
|
|
329
|
+
val onBlur: () -> Unit, val loading: Boolean, val required: Boolean, val maxLength: Int?, val keyboardType: KeyboardType,
|
|
330
|
+
val floatingValueColor: Color, val floatingIconColor: Color, val iconColor: Color, val leadingIconColor: Color,
|
|
331
|
+
val fontWeight: InputFontWeight,
|
|
332
|
+
)
|
|
333
|
+
/** [hint] / [defaultText] are the theme's `colors.text.hint` / `colors.text.default`, read in the composable. */
|
|
334
|
+
internal fun inputArgsOf(p: Map<String, Any?>, fire: Fire, hint: Color, defaultText: Color) = InputArgs(
|
|
335
|
+
floatingValue = textProp(p, "floatingValue"), floatingIcon = textProp(p, "floatingIcon"), placeholder = textProp(p, "placeholder"),
|
|
336
|
+
size = inputSizeOf(p["size"]), onChangeText = { fire("onChangeText", listOf(it)) }, hintText = textProp(p, "hintText"),
|
|
337
|
+
error = textProp(p, "errorMessage"), errorSpacing = p["errorSpacing"] == true, disabled = p["disabled"] == true,
|
|
338
|
+
readOnly = p["editable"] == false, secureTextEntry = p["secureTextEntry"] == true, icon = textProp(p, "trailing"),
|
|
339
|
+
onRightIconPressed = { fire("onPressTrailing", emptyList()) }, leadingIcon = textProp(p, "leadingIcon"),
|
|
340
|
+
onFocus = { fire("onFocus", emptyList()) }, onBlur = { fire("onBlur", emptyList()) }, loading = p["loading"] == true,
|
|
341
|
+
required = p["required"] == true, maxLength = countProp(p["maxLength"]), keyboardType = keyboardTypeOf(p["keyboardType"]),
|
|
342
|
+
floatingValueColor = colorOr(p["floatingValueColor"], hint),
|
|
343
|
+
floatingIconColor = colorOr(p["floatingIconColor"], defaultText),
|
|
344
|
+
iconColor = colorOr(p["iconColor"], defaultText),
|
|
345
|
+
leadingIconColor = colorOr(p["leadingIconColor"], hint),
|
|
346
|
+
fontWeight = inputFontWeightOf(p["fontWeight"], InputFontWeight.REGULAR),
|
|
347
|
+
)
|
|
348
|
+
|
|
349
|
+
internal data class InputDropDownArgs(
|
|
350
|
+
val floatingValue: String, val floatingIcon: String, val placeholder: String, val size: InputSize, val onPress: () -> Unit,
|
|
351
|
+
val hintText: String, val error: String, val errorSpacing: Boolean, val disabled: Boolean, val leadingIcon: String,
|
|
352
|
+
val loading: Boolean, val required: Boolean, val icon: String, val onRightIconPressed: () -> Unit,
|
|
353
|
+
val floatingValueColor: Color, val floatingIconColor: Color, val iconColor: Color, val leadingIconColor: Color,
|
|
354
|
+
)
|
|
355
|
+
internal fun inputDropDownArgsOf(p: Map<String, Any?>, fire: Fire, hint: Color, defaultText: Color) = InputDropDownArgs(
|
|
356
|
+
floatingValue = textProp(p, "floatingValue"), floatingIcon = textProp(p, "floatingIcon"), placeholder = textProp(p, "placeholder"),
|
|
357
|
+
size = inputSizeOf(p["size"]), onPress = { fire("onPress", emptyList()) }, hintText = textProp(p, "hintText"),
|
|
358
|
+
error = textProp(p, "errorMessage"),
|
|
359
|
+
errorSpacing = p["errorSpacing"] == true, disabled = p["disabled"] == true, leadingIcon = textProp(p, "leadingIcon"),
|
|
360
|
+
loading = p["loading"] == true, required = p["required"] == true,
|
|
361
|
+
icon = textOr(p, "icon", "arrow_chevron_down_small"), onRightIconPressed = { fire("onRightIconPressed", emptyList()) },
|
|
362
|
+
floatingValueColor = colorOr(p["floatingValueColor"], hint),
|
|
363
|
+
floatingIconColor = colorOr(p["floatingIconColor"], defaultText),
|
|
364
|
+
iconColor = colorOr(p["iconColor"], defaultText),
|
|
365
|
+
leadingIconColor = colorOr(p["leadingIconColor"], hint),
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
internal data class InputMoneyArgs(
|
|
369
|
+
val floatingValue: String, val floatingIcon: String, val placeholder: String, val size: InputSize, val onChangeText: (String) -> Unit,
|
|
370
|
+
val error: String, val errorSpacing: Boolean, val disabled: Boolean, val icon: String, val onPressIcon: () -> Unit,
|
|
371
|
+
val leadingIcon: String, val onFocus: () -> Unit, val onBlur: () -> Unit, val loading: Boolean, val required: Boolean,
|
|
372
|
+
val floatingValueColor: Color, val floatingIconColor: Color, val iconColor: Color, val leadingIconColor: Color,
|
|
373
|
+
val fontWeight: InputFontWeight, val keyboardType: KeyboardType,
|
|
374
|
+
)
|
|
375
|
+
internal fun inputMoneyArgsOf(p: Map<String, Any?>, fire: Fire, hint: Color, defaultText: Color) = InputMoneyArgs(
|
|
376
|
+
floatingValue = textProp(p, "floatingValue"), floatingIcon = textProp(p, "floatingIcon"),
|
|
377
|
+
placeholder = textProp(p, "placeholder").ifEmpty { "0đ" },
|
|
378
|
+
size = inputSizeOf(p["size"]), onChangeText = { fire("onChangeText", listOf(it)) }, error = textProp(p, "errorMessage"),
|
|
379
|
+
errorSpacing = p["errorSpacing"] == true, disabled = p["disabled"] == true, icon = textProp(p, "trailing"),
|
|
380
|
+
onPressIcon = { fire("onPressTrailing", emptyList()) }, leadingIcon = textProp(p, "leadingIcon"),
|
|
381
|
+
onFocus = { fire("onFocus", emptyList()) },
|
|
382
|
+
onBlur = { fire("onBlur", emptyList()) }, loading = p["loading"] == true, required = p["required"] == true,
|
|
383
|
+
floatingValueColor = colorOr(p["floatingValueColor"], hint),
|
|
384
|
+
floatingIconColor = colorOr(p["floatingIconColor"], defaultText),
|
|
385
|
+
iconColor = colorOr(p["iconColor"], defaultText),
|
|
386
|
+
leadingIconColor = colorOr(p["leadingIconColor"], hint),
|
|
387
|
+
fontWeight = inputFontWeightOf(p["fontWeight"], InputFontWeight.BOLD),
|
|
388
|
+
keyboardType = keyboardTypeOr(p["keyboardType"], KeyboardType.Number),
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
/** [onChangeText] fires the action only; the composable also records the typed text in its [OtpSync]. */
|
|
392
|
+
internal data class InputOtpArgs(
|
|
393
|
+
val value: String, val length: Int?, val errorMessage: String, val errorSpacing: Boolean, val floatingValue: String,
|
|
394
|
+
val placeholder: String, val onChangeText: (String) -> Unit, val onFocus: () -> Unit, val onBlur: () -> Unit, val dataType: String,
|
|
395
|
+
)
|
|
396
|
+
internal fun inputOtpArgsOf(p: Map<String, Any?>, fire: Fire) = InputOtpArgs(
|
|
397
|
+
value = textProp(p, "value"), length = countProp(p["length"])?.coerceAtMost(MAX_SPEC_COUNT), errorMessage = textProp(p, "errorMessage"),
|
|
398
|
+
errorSpacing = p["errorSpacing"] == true,
|
|
399
|
+
floatingValue = textOr(p, "floatingValue", "Label"), placeholder = textProp(p, "placeholder"),
|
|
400
|
+
onChangeText = { fire("onChangeText", listOf(it)) },
|
|
401
|
+
onFocus = { fire("onFocus", emptyList()) }, onBlur = { fire("onBlur", emptyList()) },
|
|
402
|
+
dataType = textProp(p, "dataType").ifEmpty { "number" },
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
internal data class InputPhoneNumberArgs(
|
|
406
|
+
val placeholder: String, val size: InputPhoneNumberSize, val onChangeText: (String) -> Unit, val hintText: String, val error: String,
|
|
407
|
+
val errorSpacing: Boolean, val icon: String, val onRightIconPressed: () -> Unit, val onFocus: () -> Unit, val onBlur: () -> Unit,
|
|
408
|
+
val loading: Boolean, val iconColor: Color,
|
|
409
|
+
)
|
|
410
|
+
internal fun inputPhoneNumberArgsOf(p: Map<String, Any?>, fire: Fire, defaultText: Color) = InputPhoneNumberArgs(
|
|
411
|
+
placeholder = textProp(p, "placeholder").ifEmpty { "0123456789" }, size = phoneSizeOf(p["size"]),
|
|
412
|
+
onChangeText = { fire("onChangeText", listOf(it)) }, hintText = textProp(p, "hintText"), error = textProp(p, "errorMessage"),
|
|
413
|
+
errorSpacing = p["errorSpacing"] == true, icon = textProp(p, "trailing"),
|
|
414
|
+
onRightIconPressed = { fire("onPressTrailing", emptyList()) },
|
|
415
|
+
onFocus = { fire("onFocus", emptyList()) }, onBlur = { fire("onBlur", emptyList()) }, loading = p["loading"] == true,
|
|
416
|
+
iconColor = colorOr(p["iconColor"], defaultText),
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
internal data class InputTextAreaArgs(
|
|
420
|
+
val maxLength: Int, val height: Dp, val floatingValue: String, val floatingIcon: String, val placeholder: String,
|
|
421
|
+
val onChangeText: (String) -> Unit, val error: String, val errorSpacing: Boolean, val disabled: Boolean, val onFocus: () -> Unit,
|
|
422
|
+
val onBlur: () -> Unit, val required: Boolean, val floatingValueColor: Color, val floatingIconColor: Color, val size: InputSize,
|
|
423
|
+
val icon: String, val iconColor: Color, val onRightIconPressed: () -> Unit, val loading: Boolean, val fontWeight: InputFontWeight,
|
|
424
|
+
val keyboardType: KeyboardType,
|
|
425
|
+
)
|
|
426
|
+
internal fun inputTextAreaArgsOf(p: Map<String, Any?>, fire: Fire, hint: Color, defaultText: Color) = InputTextAreaArgs(
|
|
427
|
+
maxLength = countProp(p["maxLength"]) ?: 300, height = dpProp(p["height"], 104.dp),
|
|
428
|
+
floatingValue = textProp(p, "floatingValue"), floatingIcon = textProp(p, "floatingIcon"), placeholder = textProp(p, "placeholder"),
|
|
429
|
+
onChangeText = { fire("onChangeText", listOf(it)) }, error = textProp(p, "errorMessage"), errorSpacing = p["errorSpacing"] == true,
|
|
430
|
+
disabled = p["disabled"] == true, onFocus = { fire("onFocus", emptyList()) }, onBlur = { fire("onBlur", emptyList()) },
|
|
431
|
+
required = p["required"] == true,
|
|
432
|
+
floatingValueColor = colorOr(p["floatingValueColor"], hint),
|
|
433
|
+
floatingIconColor = colorOr(p["floatingIconColor"], defaultText),
|
|
434
|
+
size = inputSizeOf(p["size"]), icon = textProp(p, "icon"), iconColor = colorOr(p["iconColor"], defaultText),
|
|
435
|
+
onRightIconPressed = { fire("onRightIconPressed", emptyList()) }, loading = p["loading"] == true,
|
|
436
|
+
fontWeight = inputFontWeightOf(p["fontWeight"], InputFontWeight.REGULAR),
|
|
437
|
+
keyboardType = keyboardTypeOf(p["keyboardType"]),
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
internal data class RatingArgs(val numOfStars: Int, val rating: Float, val size: RatingSize, val onRatingChange: ((Int) -> Unit)?)
|
|
441
|
+
internal fun ratingArgsOf(p: Map<String, Any?>, has: (String) -> Boolean, fire: Fire) = RatingArgs(
|
|
442
|
+
numOfStars = (intOf(p["numOfStars"]) ?: 0).coerceAtMost(MAX_SPEC_COUNT), rating = (numOf(p["rating"]) ?: 0.0).toFloat(), size = ratingSizeOf(p["size"]),
|
|
443
|
+
// no handler = every star disabled = a read-only score
|
|
444
|
+
onRatingChange = if (has("onRatingChange")) { v -> fire("onRatingChange", listOf(v.toLong())) } else null,
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
internal data class SliderArgs(
|
|
448
|
+
val min: Float, val max: Float, val step: Float, val low: Float?, val high: Float?, val minRange: Float, val disableRange: Boolean,
|
|
449
|
+
val floatingLabel: Boolean, val disabled: Boolean, val onValueChanged: (Float, Float, Boolean) -> Unit,
|
|
450
|
+
val onSliderTouchStart: (Float, Float) -> Unit, val onSliderTouchEnd: (Float, Float) -> Unit,
|
|
451
|
+
)
|
|
452
|
+
internal fun sliderArgsOf(p: Map<String, Any?>, fire: Fire) = SliderArgs(
|
|
453
|
+
min = (numOf(p["min"]) ?: 0.0).toFloat(), max = (numOf(p["max"]) ?: 100.0).toFloat(), step = (numOf(p["step"]) ?: 1.0).toFloat(),
|
|
454
|
+
low = numOf(p["low"])?.toFloat(), high = numOf(p["high"])?.toFloat(),
|
|
455
|
+
minRange = (numOf(p["minRange"]) ?: 0.0).toFloat(), disableRange = p["disableRange"] == true,
|
|
456
|
+
floatingLabel = p["floatingLabel"] == true, disabled = sliderDisabled(p),
|
|
457
|
+
onValueChanged = { lo, hi, byUser -> fire("onValueChanged", listOf(actionNumber(lo), actionNumber(hi), byUser)) },
|
|
458
|
+
onSliderTouchStart = { lo, hi -> fire("onSliderTouchStart", listOf(actionNumber(lo), actionNumber(hi))) },
|
|
459
|
+
onSliderTouchEnd = { lo, hi -> fire("onSliderTouchEnd", listOf(actionNumber(lo), actionNumber(hi))) },
|
|
460
|
+
)
|
|
461
|
+
|
|
462
|
+
internal data class StepperNodeArgs(
|
|
463
|
+
val numbers: StepperArgs, val disabled: Any, val size: StepperSize, val editable: Boolean, val onValueChange: (Int) -> Unit,
|
|
464
|
+
)
|
|
465
|
+
internal fun stepperNodeArgsOf(p: Map<String, Any?>, fire: Fire) = StepperNodeArgs(
|
|
466
|
+
numbers = stepperArgs(p), disabled = stepperDisabled(p["disabled"]), size = stepperSizeOf(p["size"]), editable = p["editable"] == true,
|
|
467
|
+
onValueChange = { fire("onValueChange", listOf(it.toLong())) },
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
internal data class StepsNodeArgs(
|
|
471
|
+
val steps: List<StepItem>, val activeIndex: Int, val horizontal: Boolean, val size: StepsSize, val useNumber: Boolean,
|
|
472
|
+
val align: StepsAlign, val customIcon: String?, val disabled: Boolean, val onPress: ((StepItem, Int) -> Unit)?,
|
|
473
|
+
)
|
|
474
|
+
internal fun stepsNodeArgsOf(p: Map<String, Any?>, has: (String) -> Boolean, fire: Fire) = StepsNodeArgs(
|
|
475
|
+
steps = stepItems(p["steps"]), activeIndex = intOf(p["activeIndex"]) ?: 0, horizontal = p["horizontal"] == true,
|
|
476
|
+
size = stepsSizeOf(p["size"]), useNumber = p["useNumber"] == true, align = stepsAlignOf(p["align"]),
|
|
477
|
+
customIcon = strOrNull(p["customIcon"]), disabled = p["disabled"] == true,
|
|
478
|
+
onPress = if (has("onPress")) { s, i -> fire("onPress", listOf(stepArg(s), i.toLong())) } else null,
|
|
479
|
+
)
|
|
480
|
+
|
|
481
|
+
internal data class ProgressInfoArgs(
|
|
482
|
+
val steps: List<ProgressInfoItem>, val horizontal: Boolean, val size: ProgressInfoSize, val useNumber: Boolean,
|
|
483
|
+
val align: ProgressInfoAlign, val showTitle: Boolean, val showDescription: Boolean, val customIcon: String?,
|
|
484
|
+
)
|
|
485
|
+
internal fun progressInfoArgsOf(p: Map<String, Any?>) = ProgressInfoArgs(
|
|
486
|
+
steps = progressItems(p["steps"]), horizontal = p["horizontal"] == true, size = progressSizeOf(p["size"]),
|
|
487
|
+
useNumber = p["useNumber"] == true, align = progressAlignOf(p["align"]), showTitle = p["showTitle"] != false,
|
|
488
|
+
showDescription = p["showDescription"] != false, customIcon = strOrNull(p["customIcon"]),
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
internal data class CollapseArgs(
|
|
492
|
+
val title: String, val description: String?, val image: String?, val imageSize: Int, val subTitle: String?, val tagLabel: String?,
|
|
493
|
+
val tagColor: TagColor, val showBorder: Boolean, val expandDefault: Boolean, val titleSize: CollapseSize,
|
|
494
|
+
val useBackgroundCollapseButton: Boolean, val backgroundColor: Color?, val titleColor: Color?, val onPress: (Boolean) -> Unit,
|
|
495
|
+
val accessibilityId: String?,
|
|
496
|
+
)
|
|
497
|
+
internal fun collapseArgsOf(p: Map<String, Any?>, fire: Fire): CollapseArgs {
|
|
498
|
+
val tag = p["tagProps"].asMap()
|
|
499
|
+
return CollapseArgs(
|
|
500
|
+
title = textOr(p, "title", "Title"), description = strOrNull(p["description"]), image = strOrNull(p["image"]),
|
|
501
|
+
imageSize = countProp(p["imageSize"]) ?: 24, subTitle = strOrNull(p["subTitle"]),
|
|
502
|
+
tagLabel = if (p["subTitle"] == null) strOrNull(tag?.get("label")) else null, tagColor = tagColorOf(tag?.get("color")),
|
|
503
|
+
showBorder = p["showBorder"] == true, expandDefault = p["expandDefault"] == true, titleSize = collapseTitleSizeOf(p["titleSize"]),
|
|
504
|
+
useBackgroundCollapseButton = p["useBackgroundCollapseButton"] == true, backgroundColor = parseColor(p["backgroundColor"]),
|
|
505
|
+
titleColor = parseColor(p["titleColor"]), onPress = { fire("onPress", listOf(it)) },
|
|
506
|
+
accessibilityId = strOrNull(p["accessibilityLabel"]),
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
internal data class SuggestActionArgs(
|
|
511
|
+
val message: String, val buttonTitle: String, val boldMessage: String, val image: String, val visible: Boolean,
|
|
512
|
+
val onClose: () -> Unit, val onPressButton: () -> Unit,
|
|
513
|
+
)
|
|
514
|
+
internal fun suggestActionArgsOf(p: Map<String, Any?>, fire: Fire) = SuggestActionArgs(
|
|
515
|
+
message = textOr(p, "message", "Message"), buttonTitle = textOr(p, "buttonTitle", "Button"),
|
|
516
|
+
boldMessage = textProp(p, "boldMessage"), image = textProp(p, "image"), visible = boolOr(p["visible"], false),
|
|
517
|
+
onClose = { fire("onClose", emptyList()) }, onPressButton = { fire("onPressButton", emptyList()) },
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
internal data class TrustBannerArgs(
|
|
521
|
+
val serviceName: String, val screenName: String, val onPress: ((Map<String, String>) -> Unit)?,
|
|
522
|
+
val trackEvent: ((String, Map<String, String>) -> Unit)?,
|
|
523
|
+
)
|
|
524
|
+
internal fun trustBannerArgsOf(p: Map<String, Any?>, has: (String) -> Boolean, fire: Fire) = TrustBannerArgs(
|
|
525
|
+
serviceName = textProp(p, "serviceName"), screenName = textProp(p, "screenName"),
|
|
526
|
+
// no handler = the kit keeps its own link handling / no tracking
|
|
527
|
+
onPress = if (has("onPress")) { d -> fire("onPress", listOf(trustArg(d))) } else null,
|
|
528
|
+
trackEvent = if (has("trackEvent")) { name, d -> fire("trackEvent", listOf(name, trustArg(d))) } else null,
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
internal data class UploaderArgs(
|
|
532
|
+
val images: List<UploadImage>, val numberOfImages: Int, val disabled: Boolean, val width: Dp, val height: Dp,
|
|
533
|
+
val onAdd: () -> Unit, val onCancel: ((UploadImage, Int) -> Unit)?, val onPressImage: (UploadImage, Int) -> Unit,
|
|
534
|
+
)
|
|
535
|
+
internal fun uploaderArgsOf(p: Map<String, Any?>, has: (String) -> Boolean, fire: Fire) = UploaderArgs(
|
|
536
|
+
images = uploadImages(p["images"]), numberOfImages = intOf(p["numberOfImages"]) ?: 1, disabled = p["disabled"] == true,
|
|
537
|
+
width = dpProp(p["width"], 64.dp), height = dpProp(p["height"], 64.dp),
|
|
538
|
+
onAdd = { fire("onAdd", emptyList()) },
|
|
539
|
+
onCancel = if (has("onCancel")) { img, i -> fire("onCancel", listOf(imageArg(img), i.toLong())) } else null,
|
|
540
|
+
onPressImage = { img, i -> fire("onPressImage", listOf(imageArg(img), i.toLong())) },
|
|
541
|
+
)
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Swipe: [leftActions] / [rightActions] press the (raw) actions of each side through [press]; [radius] is null when `itemRadius`
|
|
545
|
+
* is absent (the kit's own radius then applies).
|
|
546
|
+
*/
|
|
547
|
+
internal data class SwipeArgs(
|
|
548
|
+
val rowHeight: Dp, val radius: Dp?, val leftActions: List<SwipeAction>, val rightActions: List<SwipeAction>,
|
|
549
|
+
val onSwipeableOpen: () -> Unit, val onSwipeableClose: () -> Unit, val onSwipeableLeftOpen: () -> Unit, val onSwipeableRightOpen: () -> Unit,
|
|
550
|
+
)
|
|
551
|
+
internal fun swipeArgsOf(p: Map<String, Any?>, raw: Map<String, Any?>, fire: Fire, press: (List<Any?>) -> Unit): SwipeArgs {
|
|
552
|
+
val actionsOf = { key: String ->
|
|
553
|
+
swipeSpecs(raw[key], p[key]).map {
|
|
554
|
+
SwipeAction(
|
|
555
|
+
label = it.label, icon = it.icon, backgroundColor = parseColor(it.backgroundColor),
|
|
556
|
+
onPress = { press(it.actions) },
|
|
557
|
+
)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return SwipeArgs(
|
|
561
|
+
rowHeight = dpProp(p["height"], 56.dp), radius = parseDp(p["itemRadius"])?.coerceAtLeast(0.dp),
|
|
562
|
+
leftActions = actionsOf("leftActions"), rightActions = actionsOf("rightActions"),
|
|
563
|
+
onSwipeableOpen = { fire("onSwipeableOpen", emptyList()) }, onSwipeableClose = { fire("onSwipeableClose", emptyList()) },
|
|
564
|
+
onSwipeableLeftOpen = { fire("onSwipeableLeftOpen", emptyList()) }, onSwipeableRightOpen = { fire("onSwipeableRightOpen", emptyList()) },
|
|
565
|
+
)
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/** PopupNotify props; each button presses its (raw) actions through [press]. */
|
|
569
|
+
internal fun popupNotifyPropsOf(p: Map<String, Any?>, raw: Map<String, Any?>, fire: Fire, press: (List<Any?>) -> Unit): PopupNotifyProps {
|
|
570
|
+
fun button(key: String): PopupAction? {
|
|
571
|
+
val b = p[key].asMap() ?: return null
|
|
572
|
+
val acts = propActions(raw[key], p[key])
|
|
573
|
+
return PopupAction(title = str(b["title"]), onPress = { press(acts) })
|
|
574
|
+
}
|
|
575
|
+
return PopupNotifyProps(
|
|
576
|
+
image = textProp(p, "image"), title = textOr(p, "title", "Title"), description = textOr(p, "description", "Description"),
|
|
577
|
+
error = textProp(p, "error"), primary = button("primary"), secondary = button("secondary"),
|
|
578
|
+
buttonDirection = popupDirectionOf(p["buttonDirection"]), onIconClose = { fire("onIconClose", emptyList()) },
|
|
579
|
+
isShowCloseIcon = boolOr(p["isShowCloseIcon"], true),
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
internal data class PopupPromotionArgs(val source: String, val onPress: () -> Unit, val onClose: () -> Unit)
|
|
584
|
+
internal fun popupPromotionArgsOf(p: Map<String, Any?>, fire: Fire) = PopupPromotionArgs(
|
|
585
|
+
source = textProp(p, "image"), onPress = { fire("onActionClick", emptyList()) }, onClose = { fire("onIconClose", emptyList()) },
|
|
586
|
+
)
|
|
587
|
+
|
|
588
|
+
// ---- composables ---------------------------------------------------------------------------------------------------
|
|
589
|
+
/** Text state a kit input edits, seeded from the bound value and re-synced when that value changes elsewhere. */
|
|
590
|
+
@Composable
|
|
591
|
+
private fun boundText(value: Any?): MutableState<String> {
|
|
592
|
+
val s = strOrNull(value) ?: ""
|
|
593
|
+
val st = remember { mutableStateOf(s) }
|
|
594
|
+
LaunchedEffect(s) { if (st.value != s) st.value = s }
|
|
595
|
+
return st
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
@Composable
|
|
599
|
+
internal fun KitNode(type: String, node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty? = null) {
|
|
600
|
+
val path = LocalNodePath.current
|
|
601
|
+
val p = propsOf(node, scope, ctx, path)
|
|
602
|
+
val sty = styOf(node, scope, ctx, path, pre)
|
|
603
|
+
val mod = extra.then(sty.toModifier(parent.stretch, base = parent.percentBase))
|
|
604
|
+
val id = node["id"] as? String
|
|
605
|
+
// Args holding callbacks are remembered so an unchanged node hands the kit the SAME lambda instances on recomposition
|
|
606
|
+
// (kit components skip on equal params, and some key `remember` on their callback). The keys must cover everything the
|
|
607
|
+
// builder and its lambdas capture: [fire] / [press] are keyed on all they capture (node, scope, ctx, path, type; id comes
|
|
608
|
+
// from node), and each args block is keyed on the resolved props `p` (compared by content), `fire` / `press`, `node` when
|
|
609
|
+
// it reads `has` or raw props, and any theme colour passed in. A new scope (e.g. a repeat row whose item changed) is a new
|
|
610
|
+
// key, so its lambdas are rebuilt; state is read live through the scope at action time.
|
|
611
|
+
val fire: Fire = remember(node, scope, ctx, path, type) {
|
|
612
|
+
gatedFire(node) { actions, name, args -> ctx.dispatch(actions, name, scope, args, path, id, type) }
|
|
613
|
+
}
|
|
614
|
+
val press: (List<Any?>) -> Unit = remember(node, scope, ctx, path, type) {
|
|
615
|
+
{ acts -> ctx.dispatch(acts, "onPress", scope, emptyList(), path, id, type) }
|
|
616
|
+
}
|
|
617
|
+
val has = { name: String -> actionsFor(node, name).isNotEmpty() }
|
|
618
|
+
val theme = AppTheme.current
|
|
619
|
+
val hint = theme.colors.text.hint
|
|
620
|
+
val defaultText = theme.colors.text.default
|
|
621
|
+
|
|
622
|
+
when (type) {
|
|
623
|
+
"Avatar" -> Box(mod) {
|
|
624
|
+
val a = avatarArgsOf(p)
|
|
625
|
+
Avatar(
|
|
626
|
+
size = a.size, rounded = a.rounded, name = a.name, image = a.image, showIconMomo = a.showIconMomo,
|
|
627
|
+
showIconSupport = a.showIconSupport, iconSupport = a.iconSupport, accessibilityLabel = a.accessibilityLabel,
|
|
628
|
+
)
|
|
629
|
+
}
|
|
630
|
+
"CheckBox" -> Box(mod) {
|
|
631
|
+
val a = remember(p, fire) { checkBoxArgsOf(p, fire) }
|
|
632
|
+
CheckBox(disabled = a.disabled, checked = a.checked, indeterminate = a.indeterminate, title = a.title, onCheckedChange = a.onCheckedChange)
|
|
633
|
+
}
|
|
634
|
+
"Switch" -> Box(mod) {
|
|
635
|
+
val a = remember(p, fire) { switchArgsOf(p, fire) }
|
|
636
|
+
Switch(value = a.value, disabled = a.disabled, title = a.title, accessibilityId = a.accessibilityId, onChange = a.onChange)
|
|
637
|
+
}
|
|
638
|
+
"Radio" -> Box(mod) {
|
|
639
|
+
val a = remember(p, fire) { radioArgsOf(p, fire) }
|
|
640
|
+
Radio(value = a.value, groupValue = a.groupValue, disabled = a.disabled, label = a.label, onChange = a.onChange)
|
|
641
|
+
}
|
|
642
|
+
"Divider" -> Box(mod) { val a = dividerArgsOf(p); Divider(useMargin = a.useMargin, type = a.type) }
|
|
643
|
+
"Loader" -> Box(mod) { val a = loaderArgsOf(p); Loader(type = a.type, tintColor = a.tintColor) }
|
|
644
|
+
"Skeleton" -> Box(extra.then(sty.toModifier(parent.stretch, isImage = true, base = parent.percentBase))) { Skeleton() } // isImage: borderRadius clips the shimmer
|
|
645
|
+
"IconButton" -> Box(mod) {
|
|
646
|
+
val a = remember(p, fire) { iconButtonArgsOf(p, fire) }
|
|
647
|
+
IconButton(onClick = a.onClick, type = a.type, size = a.size, shape = a.shape, icon = a.icon)
|
|
648
|
+
}
|
|
649
|
+
"Information" -> Box(mod) {
|
|
650
|
+
val a = remember(p, node, fire) { informationArgsOf(p, has, fire) }
|
|
651
|
+
Information(
|
|
652
|
+
title = a.title, description = a.description, state = a.state, image = a.image, onPressAction = a.onPressAction,
|
|
653
|
+
showIcon = a.showIcon, action = a.action, showIconClose = a.showIconClose, onPressClose = a.onPressClose,
|
|
654
|
+
accessibilityLabel = a.accessibilityLabel, highlightText = a.highlightText,
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
"Input" -> {
|
|
658
|
+
val t = boundText(p["value"] ?: p["defaultValue"])
|
|
659
|
+
val a = remember(p, fire, hint, defaultText) { inputArgsOf(p, fire, hint, defaultText) }
|
|
660
|
+
Input(
|
|
661
|
+
text = t, floatingValue = a.floatingValue, floatingIcon = a.floatingIcon, placeholder = a.placeholder,
|
|
662
|
+
size = a.size, onChangeText = a.onChangeText, hintText = a.hintText,
|
|
663
|
+
error = a.error, errorSpacing = a.errorSpacing, disabled = a.disabled,
|
|
664
|
+
readOnly = a.readOnly, secureTextEntry = a.secureTextEntry, icon = a.icon,
|
|
665
|
+
onRightIconPressed = a.onRightIconPressed, leadingIcon = a.leadingIcon, onFocus = a.onFocus,
|
|
666
|
+
onBlur = a.onBlur, loading = a.loading, required = a.required,
|
|
667
|
+
maxLength = a.maxLength, keyboardType = a.keyboardType, modifier = mod,
|
|
668
|
+
floatingValueColor = a.floatingValueColor, floatingIconColor = a.floatingIconColor,
|
|
669
|
+
iconColor = a.iconColor, leadingIconColor = a.leadingIconColor, fontWeight = a.fontWeight,
|
|
670
|
+
)
|
|
671
|
+
}
|
|
672
|
+
"InputDropDown" -> {
|
|
673
|
+
val t = boundText(p["value"])
|
|
674
|
+
Box(mod) {
|
|
675
|
+
val a = remember(p, fire, hint, defaultText) { inputDropDownArgsOf(p, fire, hint, defaultText) }
|
|
676
|
+
InputDropDown(
|
|
677
|
+
value = t, floatingValue = a.floatingValue, floatingIcon = a.floatingIcon, placeholder = a.placeholder,
|
|
678
|
+
size = a.size, onPress = a.onPress, hintText = a.hintText, error = a.error,
|
|
679
|
+
errorSpacing = a.errorSpacing, disabled = a.disabled, leadingIcon = a.leadingIcon,
|
|
680
|
+
loading = a.loading, required = a.required, icon = a.icon, onRightIconPressed = a.onRightIconPressed,
|
|
681
|
+
floatingValueColor = a.floatingValueColor, floatingIconColor = a.floatingIconColor,
|
|
682
|
+
iconColor = a.iconColor, leadingIconColor = a.leadingIconColor,
|
|
683
|
+
)
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
"InputMoney" -> {
|
|
687
|
+
val t = boundText(p["value"] ?: p["defaultValue"] ?: "0") // kit default text is "0"
|
|
688
|
+
Box(mod) {
|
|
689
|
+
val a = remember(p, fire, hint, defaultText) { inputMoneyArgsOf(p, fire, hint, defaultText) }
|
|
690
|
+
InputMoney(
|
|
691
|
+
text = t, floatingValue = a.floatingValue, floatingIcon = a.floatingIcon, placeholder = a.placeholder,
|
|
692
|
+
size = a.size, onChangeText = a.onChangeText, error = a.error,
|
|
693
|
+
errorSpacing = a.errorSpacing, disabled = a.disabled, icon = a.icon,
|
|
694
|
+
onPressIcon = a.onPressIcon, leadingIcon = a.leadingIcon, onFocus = a.onFocus,
|
|
695
|
+
onBlur = a.onBlur, loading = a.loading, required = a.required,
|
|
696
|
+
floatingValueColor = a.floatingValueColor, floatingIconColor = a.floatingIconColor,
|
|
697
|
+
iconColor = a.iconColor, leadingIconColor = a.leadingIconColor,
|
|
698
|
+
fontWeight = a.fontWeight, keyboardType = a.keyboardType,
|
|
699
|
+
)
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
"InputOTP" -> Box(mod) {
|
|
703
|
+
// the kit remembers its text without a key: `value` only seeds once, so re-key when the bound value changes elsewhere
|
|
704
|
+
val a = remember(p, fire) { inputOtpArgsOf(p, fire) }
|
|
705
|
+
val bound = a.value
|
|
706
|
+
val sync = remember { OtpSync(bound) }
|
|
707
|
+
key(sync.tokenFor(bound)) { InputOTP(
|
|
708
|
+
value = bound, length = a.length, errorMessage = a.errorMessage, errorSpacing = a.errorSpacing,
|
|
709
|
+
floatingValue = a.floatingValue, placeholder = a.placeholder, onChangeText = { sync.lastEmitted = it; a.onChangeText(it) },
|
|
710
|
+
onFocus = a.onFocus, onBlur = a.onBlur, dataType = a.dataType,
|
|
711
|
+
) }
|
|
712
|
+
}
|
|
713
|
+
"InputPhoneNumber" -> {
|
|
714
|
+
val t = boundText(p["value"] ?: p["defaultValue"])
|
|
715
|
+
Box(mod) {
|
|
716
|
+
val a = remember(p, fire, defaultText) { inputPhoneNumberArgsOf(p, fire, defaultText) }
|
|
717
|
+
InputPhoneNumber(
|
|
718
|
+
text = t, placeholder = a.placeholder, size = a.size,
|
|
719
|
+
onChangeText = a.onChangeText, hintText = a.hintText, error = a.error,
|
|
720
|
+
errorSpacing = a.errorSpacing, icon = a.icon, onRightIconPressed = a.onRightIconPressed,
|
|
721
|
+
onFocus = a.onFocus, onBlur = a.onBlur, loading = a.loading, iconColor = a.iconColor,
|
|
722
|
+
)
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
"InputTextArea" -> {
|
|
726
|
+
val t = boundText(p["value"])
|
|
727
|
+
Box(mod) {
|
|
728
|
+
val a = remember(p, fire, hint, defaultText) { inputTextAreaArgsOf(p, fire, hint, defaultText) }
|
|
729
|
+
InputTextArea(
|
|
730
|
+
text = t, maxLength = a.maxLength, height = a.height,
|
|
731
|
+
floatingValue = a.floatingValue, floatingIcon = a.floatingIcon, placeholder = a.placeholder,
|
|
732
|
+
onChangeText = a.onChangeText, error = a.error, errorSpacing = a.errorSpacing,
|
|
733
|
+
disabled = a.disabled, onFocus = a.onFocus, onBlur = a.onBlur,
|
|
734
|
+
required = a.required,
|
|
735
|
+
floatingValueColor = a.floatingValueColor, floatingIconColor = a.floatingIconColor,
|
|
736
|
+
size = a.size, icon = a.icon, iconColor = a.iconColor,
|
|
737
|
+
onRightIconPressed = a.onRightIconPressed, loading = a.loading,
|
|
738
|
+
fontWeight = a.fontWeight, keyboardType = a.keyboardType,
|
|
739
|
+
)
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
"Rating" -> Box(mod) {
|
|
743
|
+
val a = remember(p, node, fire) { ratingArgsOf(p, has, fire) }
|
|
744
|
+
Rating(numOfStars = a.numOfStars, rating = a.rating, size = a.size, onRatingChange = a.onRatingChange)
|
|
745
|
+
}
|
|
746
|
+
"Slider" -> {
|
|
747
|
+
val a = remember(p, fire) { sliderArgsOf(p, fire) }
|
|
748
|
+
Box(mod) {
|
|
749
|
+
Slider(
|
|
750
|
+
min = a.min, max = a.max, step = a.step, low = a.low, high = a.high, minRange = a.minRange,
|
|
751
|
+
disableRange = a.disableRange, floatingLabel = a.floatingLabel, disabled = a.disabled,
|
|
752
|
+
onValueChanged = a.onValueChanged, onSliderTouchStart = a.onSliderTouchStart, onSliderTouchEnd = a.onSliderTouchEnd,
|
|
753
|
+
)
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
"Stepper" -> Box(mod) {
|
|
757
|
+
val a = remember(p, fire) { stepperNodeArgsOf(p, fire) }
|
|
758
|
+
Stepper(
|
|
759
|
+
defaultValue = a.numbers.defaultValue, min = a.numbers.min, max = a.numbers.max, step = a.numbers.step,
|
|
760
|
+
disabled = a.disabled, size = a.size, editable = a.editable, onValueChange = a.onValueChange,
|
|
761
|
+
)
|
|
762
|
+
}
|
|
763
|
+
"Steps" -> Box(mod) {
|
|
764
|
+
val a = remember(p, node, fire) { stepsNodeArgsOf(p, has, fire) }
|
|
765
|
+
Steps(
|
|
766
|
+
steps = a.steps, activeIndex = a.activeIndex, horizontal = a.horizontal, size = a.size, useNumber = a.useNumber,
|
|
767
|
+
align = a.align, customIcon = a.customIcon, disabled = a.disabled, onPress = a.onPress,
|
|
768
|
+
)
|
|
769
|
+
}
|
|
770
|
+
"ProgressInfo" -> Box(mod) {
|
|
771
|
+
val a = progressInfoArgsOf(p)
|
|
772
|
+
ProgressInfo(
|
|
773
|
+
steps = a.steps, horizontal = a.horizontal, size = a.size, useNumber = a.useNumber, align = a.align,
|
|
774
|
+
showTitle = a.showTitle, showDescription = a.showDescription, customIcon = a.customIcon,
|
|
775
|
+
)
|
|
776
|
+
}
|
|
777
|
+
"Collapse" -> {
|
|
778
|
+
val base = path
|
|
779
|
+
val kids = rememberExpand(node.children(), scope, ctx.theme, path)
|
|
780
|
+
val a = remember(p, fire) { collapseArgsOf(p, fire) }
|
|
781
|
+
Collapse(
|
|
782
|
+
title = a.title, modifier = mod, description = a.description, image = a.image,
|
|
783
|
+
imageSize = a.imageSize, subTitle = a.subTitle,
|
|
784
|
+
tagLabel = a.tagLabel, tagColor = a.tagColor,
|
|
785
|
+
showBorder = a.showBorder, expandDefault = a.expandDefault, titleSize = a.titleSize,
|
|
786
|
+
useBackgroundCollapseButton = a.useBackgroundCollapseButton, backgroundColor = a.backgroundColor,
|
|
787
|
+
titleColor = a.titleColor, onPress = a.onPress, accessibilityId = a.accessibilityId,
|
|
788
|
+
content = {
|
|
789
|
+
Column {
|
|
790
|
+
kids.forEach { e -> RenderNode(e.node, e.scope, ctx, Parent(stretch = true), path = childPath(base, e)) }
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
)
|
|
794
|
+
}
|
|
795
|
+
"SuggestAction" -> Box(mod) {
|
|
796
|
+
val a = remember(p, fire) { suggestActionArgsOf(p, fire) }
|
|
797
|
+
SuggestAction(
|
|
798
|
+
message = a.message, buttonTitle = a.buttonTitle, boldMessage = a.boldMessage, image = a.image, visible = a.visible,
|
|
799
|
+
onClose = a.onClose, onPressButton = a.onPressButton,
|
|
800
|
+
)
|
|
801
|
+
}
|
|
802
|
+
"TrustBanner" -> Box(mod) {
|
|
803
|
+
val a = remember(p, node, fire) { trustBannerArgsOf(p, has, fire) }
|
|
804
|
+
TrustBanner(serviceName = a.serviceName, screenName = a.screenName, onPress = a.onPress, trackEvent = a.trackEvent)
|
|
805
|
+
}
|
|
806
|
+
"Uploader" -> Box(mod) {
|
|
807
|
+
val a = remember(p, node, fire) { uploaderArgsOf(p, has, fire) }
|
|
808
|
+
Uploader(
|
|
809
|
+
images = a.images, numberOfImages = a.numberOfImages, disabled = a.disabled, width = a.width, height = a.height,
|
|
810
|
+
onAdd = a.onAdd, onCancel = a.onCancel, onPressImage = a.onPressImage,
|
|
811
|
+
)
|
|
812
|
+
}
|
|
813
|
+
"Swipe" -> {
|
|
814
|
+
val base = path
|
|
815
|
+
val kids = rememberExpand(node.children(), scope, ctx.theme, path)
|
|
816
|
+
val a = remember(p, node, fire, press) { swipeArgsOf(p, node.props(), fire, press) }
|
|
817
|
+
val content: @Composable () -> Unit = {
|
|
818
|
+
Column {
|
|
819
|
+
kids.forEach { e -> RenderNode(e.node, e.scope, ctx, Parent(stretch = true), path = childPath(base, e)) }
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
val radius = a.radius
|
|
823
|
+
if (radius != null) {
|
|
824
|
+
Swipe(
|
|
825
|
+
modifier = mod, leftActions = a.leftActions, rightActions = a.rightActions, height = a.rowHeight,
|
|
826
|
+
itemRadius = radius, onSwipeableOpen = a.onSwipeableOpen, onSwipeableClose = a.onSwipeableClose,
|
|
827
|
+
onSwipeableLeftOpen = a.onSwipeableLeftOpen, onSwipeableRightOpen = a.onSwipeableRightOpen, content = content,
|
|
828
|
+
)
|
|
829
|
+
} else {
|
|
830
|
+
Swipe(
|
|
831
|
+
modifier = mod, leftActions = a.leftActions, rightActions = a.rightActions, height = a.rowHeight,
|
|
832
|
+
onSwipeableOpen = a.onSwipeableOpen, onSwipeableClose = a.onSwipeableClose,
|
|
833
|
+
onSwipeableLeftOpen = a.onSwipeableLeftOpen, onSwipeableRightOpen = a.onSwipeableRightOpen, content = content,
|
|
834
|
+
)
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
"PopupNotify" -> {
|
|
838
|
+
// The kit popup is an inline card (no Dialog): drawn in the flow like any block node.
|
|
839
|
+
val props = remember(p, node, fire, press) { popupNotifyPropsOf(p, node.props(), fire, press) }
|
|
840
|
+
Box(mod) { PopupNotify(props) }
|
|
841
|
+
}
|
|
842
|
+
"PopupPromotion" -> Box(mod) {
|
|
843
|
+
val a = remember(p, fire) { popupPromotionArgsOf(p, fire) }
|
|
844
|
+
PopupPromotion(source = a.source, onPress = a.onPress, onClose = a.onClose)
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
// AI-GENERATED END: SDUI kit nodes
|