@momo-kits/native-kits 0.169.13-beta.3 → 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/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-demo/README.md +120 -0
- package/package.json +1 -1
- package/scripts/sdui-visual/README.md +64 -0
- package/settings.gradle.kts +64 -0
|
@@ -0,0 +1,1146 @@
|
|
|
1
|
+
// File: compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt
|
|
2
|
+
// Created At: 2026-10-27 12: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.clickable
|
|
10
|
+
import androidx.compose.foundation.background
|
|
11
|
+
import androidx.compose.foundation.horizontalScroll
|
|
12
|
+
import androidx.compose.foundation.verticalScroll
|
|
13
|
+
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
14
|
+
import androidx.compose.ui.draw.clip
|
|
15
|
+
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
16
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
17
|
+
import androidx.compose.foundation.layout.Box
|
|
18
|
+
import androidx.compose.foundation.layout.BoxScope
|
|
19
|
+
import androidx.compose.ui.layout.IntrinsicMeasurable
|
|
20
|
+
import androidx.compose.ui.layout.IntrinsicMeasureScope
|
|
21
|
+
import androidx.compose.ui.layout.Layout
|
|
22
|
+
import androidx.compose.ui.layout.Measurable
|
|
23
|
+
import androidx.compose.ui.layout.MeasureResult
|
|
24
|
+
import androidx.compose.ui.layout.MeasureScope
|
|
25
|
+
import androidx.compose.ui.layout.MultiContentMeasurePolicy
|
|
26
|
+
import androidx.compose.ui.layout.Placeable
|
|
27
|
+
import androidx.compose.ui.unit.Constraints
|
|
28
|
+
import androidx.compose.ui.unit.IntSize
|
|
29
|
+
import androidx.compose.ui.unit.constrainWidth
|
|
30
|
+
import androidx.compose.ui.unit.constrainHeight
|
|
31
|
+
import androidx.compose.foundation.layout.BoxWithConstraints
|
|
32
|
+
import androidx.compose.foundation.layout.Column
|
|
33
|
+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
34
|
+
import androidx.compose.foundation.layout.IntrinsicSize
|
|
35
|
+
import androidx.compose.foundation.layout.FlowRow
|
|
36
|
+
import androidx.compose.foundation.layout.Row
|
|
37
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
38
|
+
import androidx.compose.foundation.layout.fillMaxHeight
|
|
39
|
+
import androidx.compose.runtime.getValue
|
|
40
|
+
import androidx.compose.runtime.mutableIntStateOf
|
|
41
|
+
import androidx.compose.runtime.remember
|
|
42
|
+
import androidx.compose.runtime.setValue
|
|
43
|
+
import androidx.compose.ui.unit.sp
|
|
44
|
+
import androidx.compose.foundation.layout.height
|
|
45
|
+
import androidx.compose.foundation.layout.fillMaxWidth
|
|
46
|
+
import androidx.compose.foundation.layout.offset
|
|
47
|
+
import androidx.compose.foundation.layout.padding
|
|
48
|
+
import androidx.compose.foundation.layout.width
|
|
49
|
+
import androidx.compose.foundation.layout.wrapContentSize
|
|
50
|
+
import androidx.compose.foundation.rememberScrollState
|
|
51
|
+
import androidx.compose.runtime.Composable
|
|
52
|
+
import vn.momo.kits.platform.getScreenDimensions
|
|
53
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
54
|
+
import androidx.compose.runtime.Immutable
|
|
55
|
+
import androidx.compose.runtime.remember
|
|
56
|
+
import androidx.compose.runtime.snapshots.SnapshotStateMap
|
|
57
|
+
import androidx.compose.runtime.mutableStateOf
|
|
58
|
+
import androidx.compose.ui.Alignment
|
|
59
|
+
import androidx.compose.ui.Modifier
|
|
60
|
+
import androidx.compose.ui.draw.alpha
|
|
61
|
+
import androidx.compose.ui.graphics.Color
|
|
62
|
+
import androidx.compose.ui.layout.ContentScale
|
|
63
|
+
import androidx.compose.ui.text.style.TextAlign
|
|
64
|
+
import androidx.compose.ui.text.style.TextOverflow
|
|
65
|
+
import androidx.compose.ui.unit.Dp
|
|
66
|
+
import androidx.compose.ui.unit.dp
|
|
67
|
+
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
68
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
69
|
+
import androidx.compose.runtime.key
|
|
70
|
+
import androidx.compose.runtime.snapshotFlow
|
|
71
|
+
import vn.momo.kits.components.Button
|
|
72
|
+
import vn.momo.kits.components.ButtonType
|
|
73
|
+
import vn.momo.kits.components.Icon
|
|
74
|
+
import vn.momo.kits.components.PaginationDot
|
|
75
|
+
import vn.momo.kits.components.PaginationNumber
|
|
76
|
+
import vn.momo.kits.components.PaginationScroll
|
|
77
|
+
import vn.momo.kits.components.PaginationWhiteDot
|
|
78
|
+
import vn.momo.kits.components.RibbonPosition
|
|
79
|
+
import vn.momo.kits.components.Size
|
|
80
|
+
import vn.momo.kits.components.Tag
|
|
81
|
+
import vn.momo.kits.components.TagColor
|
|
82
|
+
import vn.momo.kits.components.TagSize
|
|
83
|
+
import vn.momo.kits.components.TabView
|
|
84
|
+
import vn.momo.kits.components.TabViewDirection
|
|
85
|
+
import vn.momo.kits.components.TabViewItem
|
|
86
|
+
import vn.momo.kits.components.Carousel
|
|
87
|
+
import androidx.compose.foundation.layout.PaddingValues
|
|
88
|
+
import vn.momo.kits.components.Badge
|
|
89
|
+
import vn.momo.kits.layout.Card as KitCard
|
|
90
|
+
import androidx.compose.foundation.layout.size
|
|
91
|
+
import vn.momo.kits.layout.Item as KitItem
|
|
92
|
+
import vn.momo.kits.layout.Section as KitSection
|
|
93
|
+
import vn.momo.kits.modifier.activeOpacityClickable
|
|
94
|
+
import vn.momo.kits.components.BadgeRibbon
|
|
95
|
+
import vn.momo.kits.components.Chip
|
|
96
|
+
import vn.momo.kits.components.ChipSize
|
|
97
|
+
import vn.momo.kits.components.InputSearch
|
|
98
|
+
import vn.momo.kits.components.InputFontWeight
|
|
99
|
+
import vn.momo.kits.components.InputSearchProps
|
|
100
|
+
import vn.momo.kits.components.Image
|
|
101
|
+
import vn.momo.kits.components.Options
|
|
102
|
+
import vn.momo.kits.components.Text
|
|
103
|
+
import vn.momo.kits.components.Title
|
|
104
|
+
import vn.momo.kits.components.TitleSize
|
|
105
|
+
import vn.momo.kits.components.TitleType
|
|
106
|
+
import vn.momo.kits.const.Spacing
|
|
107
|
+
import vn.momo.kits.const.Theme
|
|
108
|
+
|
|
109
|
+
// AI-GENERATED START: SDUI node renderer (registry of node types -> Compose / MoMo kit)
|
|
110
|
+
/** Everything a node needs besides its own spec: theme, live state and the action dispatcher. */
|
|
111
|
+
internal class SduiCtx(
|
|
112
|
+
val theme: Theme,
|
|
113
|
+
val state: SnapshotStateMap<String, Any?>,
|
|
114
|
+
val dispatch: (actions: List<Any?>?, name: String, scope: SduiScope, args: List<Any?>, path: String, nodeId: String?, nodeType: String?) -> Unit,
|
|
115
|
+
/** Tracking session of the page being drawn (`sdui_node_error` on nodes). */
|
|
116
|
+
val session: RenderSession = RenderSession.NOOP,
|
|
117
|
+
/** The owning view's logger. */
|
|
118
|
+
val log: SduiLog = SduiLog.NONE,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
/** Path of the node being composed (`body.children.0.children.2`), for tracking events. */
|
|
122
|
+
internal val LocalNodePath = androidx.compose.runtime.compositionLocalOf { "" }
|
|
123
|
+
|
|
124
|
+
internal data class Expanded(val node: Map<String, Any?>, val scope: SduiScope, val index: Int)
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* What [expand] made at one call site on the previous composition, so an unchanged child keeps the same [Expanded] and
|
|
128
|
+
* scope (a repeat row only gets a new scope when its spec node, its parent scope or its item changed). Unchanged rows
|
|
129
|
+
* then pass the same arguments to [RenderNode] and are skipped when their parent recomposes; their own state reads
|
|
130
|
+
* still invalidate them since every scope reads the one live state map.
|
|
131
|
+
*/
|
|
132
|
+
internal class ExpandCache {
|
|
133
|
+
internal class Row(val node: Node, val parent: SduiScope, val item: Any?, val e: Expanded)
|
|
134
|
+
|
|
135
|
+
internal var rows = HashMap<Long, Row>()
|
|
136
|
+
internal var plain = HashMap<Int, Expanded>()
|
|
137
|
+
internal var last: List<Expanded>? = null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** [expand] for a composable call site: same result, with [Expanded] entries (and their scopes) kept stable across recompositions. */
|
|
141
|
+
@Composable
|
|
142
|
+
internal fun rememberExpand(nodes: List<Any?>, scope: SduiScope, theme: Theme, basePath: String?): List<Expanded> {
|
|
143
|
+
val cache = remember { ExpandCache() }
|
|
144
|
+
return expand(nodes, scope, theme, basePath, cache)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
internal fun childPath(base: String, e: Expanded) = "$base.children.${e.index}"
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* How the parent lays this child out (default: column, children stretch to full width). [percentBase]: the parent's
|
|
151
|
+
* content size for the child's percent sizes, set only by a parent that needs one ([rememberPercentBase]).
|
|
152
|
+
*/
|
|
153
|
+
internal data class Parent(val stretch: Boolean = true, val fillHeight: Boolean = false, val percentBase: PercentBase? = null)
|
|
154
|
+
|
|
155
|
+
internal typealias Node = Map<String, Any?>
|
|
156
|
+
|
|
157
|
+
internal fun Node.type() = this["type"] as? String
|
|
158
|
+
internal fun Node.props() = this["props"].asMap() ?: emptyMap()
|
|
159
|
+
internal fun Node.children() = this["children"].asList() ?: emptyList()
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Expand `repeat` and drop invisible nodes -> list of (node, scope). A broken child `visible` / `repeat` is reported on
|
|
163
|
+
* `<basePath>.children.<i>` (null [basePath] = quiet); repeat copies of one spec node share that path.
|
|
164
|
+
*/
|
|
165
|
+
internal fun expand(nodes: List<Any?>, scope: SduiScope, theme: Theme, basePath: String?, cache: ExpandCache? = null): List<Expanded> {
|
|
166
|
+
val out = ArrayList<Expanded>()
|
|
167
|
+
val rows = if (cache != null) HashMap<Long, ExpandCache.Row>() else null
|
|
168
|
+
val plain = if (cache != null) HashMap<Int, Expanded>() else null
|
|
169
|
+
for ((nodeIndex, raw) in nodes.withIndex()) {
|
|
170
|
+
val n = raw.asMap() ?: continue
|
|
171
|
+
val path = basePath?.let { "$it.children.$nodeIndex" }
|
|
172
|
+
val rep = n["repeat"].asMap()
|
|
173
|
+
if (rep != null) {
|
|
174
|
+
val src = rep["source"] ?: rep["from"]
|
|
175
|
+
val list = (src as? String)?.let { s ->
|
|
176
|
+
scope.nodeErrors.forNode(n, path) { resolveString(if (unwrapBinding(s) == null) "{$s}" else s, scope) }
|
|
177
|
+
}.asList() ?: emptyList()
|
|
178
|
+
val alias = rep["as"] as? String ?: "item"
|
|
179
|
+
val indexAlias = rep["index"] as? String
|
|
180
|
+
list.forEachIndexed { idx, item ->
|
|
181
|
+
// a row is (spec node, repeat index): reused only for the same node, parent scope and an equal item
|
|
182
|
+
val key = (nodeIndex.toLong() shl 32) or idx.toLong()
|
|
183
|
+
val prev = cache?.rows?.get(key)?.takeIf { it.node === n && it.parent === scope && it.item == item }
|
|
184
|
+
val e = prev?.e ?: run {
|
|
185
|
+
var sc = scope.with(alias, item)
|
|
186
|
+
if (indexAlias != null) sc = sc.with(indexAlias, idx.toLong())
|
|
187
|
+
Expanded(n, sc, nodeIndex)
|
|
188
|
+
}
|
|
189
|
+
rows?.put(key, prev ?: ExpandCache.Row(n, scope, item, e))
|
|
190
|
+
if (visible(n, e.scope, path)) out += e
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
val e = cache?.plain?.get(nodeIndex)?.takeIf { it.node === n && it.scope === scope } ?: Expanded(n, scope, nodeIndex)
|
|
194
|
+
plain?.put(nodeIndex, e)
|
|
195
|
+
if (visible(n, scope, path)) out += e
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (cache == null) return out
|
|
199
|
+
cache.rows = rows!!
|
|
200
|
+
cache.plain = plain!!
|
|
201
|
+
val last = cache.last
|
|
202
|
+
if (last != null && last.size == out.size && last.indices.all { last[it] === out[it] }) return last
|
|
203
|
+
cache.last = out
|
|
204
|
+
return out
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
private fun visible(n: Node, scope: SduiScope, path: String?): Boolean {
|
|
208
|
+
val v = n["visible"] ?: n["visibleWhen"] ?: return true
|
|
209
|
+
return when (v) {
|
|
210
|
+
is Boolean -> v
|
|
211
|
+
is String -> truthy(scope.nodeErrors.forNode(n, path) { resolveString(v, scope) })
|
|
212
|
+
else -> truthy(v)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** [n]'s resolved styles; failures are reported on [path] (the node's own path), or dropped when [path] is null. */
|
|
217
|
+
internal fun styOf(n: Node, scope: SduiScope, ctx: SduiCtx, path: String?): Sty {
|
|
218
|
+
val sty = Sty(scope.nodeErrors.forNode(n, path) { resolveValue(n["styles"], scope, ctx.theme) }.asMap() ?: emptyMap())
|
|
219
|
+
if (path != null) reportIgnoredStyles(n, sty, scope, ctx, path)
|
|
220
|
+
return sty
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* [IGNORED_STYLES] present in [sty] (the node's own resolved styles): one `sdui_node_error` (`unsupported_style`, reason =
|
|
225
|
+
* the key name) and one log line per key, on the node's own [path]. The session and the log dedupe, so a node resolved
|
|
226
|
+
* again on every recomposition still reports once. The styles themselves are untouched (the node renders as before).
|
|
227
|
+
*/
|
|
228
|
+
internal fun reportIgnoredStyles(n: Node, sty: Sty, scope: SduiScope, ctx: SduiCtx, path: String) {
|
|
229
|
+
if (sty.m.isEmpty()) return
|
|
230
|
+
for ((k, hint) in IGNORED_STYLES) {
|
|
231
|
+
if (!sty.m.containsKey(k)) continue
|
|
232
|
+
scope.nodeErrors.reportOn(n, path, NODE_ERR_UNSUPPORTED_STYLE, k)
|
|
233
|
+
ctx.log.w("$path: styles.$k is ignored; $hint")
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* A child's styles, resolved once by a parent that needs them for layout (absolute / flex). Nothing is reported then:
|
|
239
|
+
* the child reports [errors] on its own path when it renders ([styOf] with `pre`), where it would have resolved them itself.
|
|
240
|
+
*/
|
|
241
|
+
@Immutable
|
|
242
|
+
internal data class PreSty(val sty: Sty, val errors: Set<String>)
|
|
243
|
+
|
|
244
|
+
internal fun preStyOf(n: Node, scope: SduiScope, ctx: SduiCtx): PreSty {
|
|
245
|
+
val (v, codes) = scope.nodeErrors.capture { resolveValue(n["styles"], scope, ctx.theme) }
|
|
246
|
+
return PreSty(Sty(v.asMap() ?: emptyMap()), codes)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** [n]'s styles at [path]: [pre] when the parent already resolved them (its failures are reported now), else resolved here. */
|
|
250
|
+
internal fun styOf(n: Node, scope: SduiScope, ctx: SduiCtx, path: String, pre: PreSty?): Sty {
|
|
251
|
+
if (pre == null) return styOf(n, scope, ctx, path)
|
|
252
|
+
scope.nodeErrors.reportCodes(n, path, pre.errors)
|
|
253
|
+
reportIgnoredStyles(n, pre.sty, scope, ctx, path)
|
|
254
|
+
return pre.sty
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** A flex child with its styles resolved once ([resolve] is called exactly once per child); [index] = its place among all the children. */
|
|
258
|
+
internal class Laid(val e: Expanded, val pre: PreSty, val index: Int = 0)
|
|
259
|
+
|
|
260
|
+
/** [all] children with their styles, split into in-flow and `position: absolute` ones. */
|
|
261
|
+
internal fun layChildren(all: List<Expanded>, resolve: (Expanded) -> PreSty): Pair<List<Laid>, List<Laid>> =
|
|
262
|
+
all.mapIndexed { i, e -> Laid(e, resolve(e), i) }.partition { !it.pre.sty.isAbsolute }
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* How one absolute child is laid over its parent: [align] corner, [stretchW] / [stretchH] total insets when it spans
|
|
266
|
+
* the parent on that axis, and [below] = drawn under the in-flow content. React Native paints siblings in order, so an
|
|
267
|
+
* absolute child followed by an in-flow sibling (a background placed first) goes under the content; one after the last
|
|
268
|
+
* in-flow child (a badge) stays on top. The in-flow content is one layer, so an absolute child between two in-flow
|
|
269
|
+
* children goes under all of them. `zIndex` still overrides this.
|
|
270
|
+
*/
|
|
271
|
+
@Immutable
|
|
272
|
+
internal data class AbsSlot(val align: Alignment, val stretchW: Dp?, val stretchH: Dp?, val below: Boolean)
|
|
273
|
+
|
|
274
|
+
internal fun absSlotsOf(flow: List<Laid>, abs: List<Laid>): List<AbsSlot> {
|
|
275
|
+
val lastFlow = flow.maxOfOrNull { it.index } ?: -1
|
|
276
|
+
return abs.map { c ->
|
|
277
|
+
val plan = absolutePlanOf(c.pre.sty)
|
|
278
|
+
AbsSlot(cornerAlignment(plan.corner), plan.stretchW, plan.stretchH, below = c.index < lastFlow)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** [n]'s resolved props; failures are reported on [path], or dropped when [path] is null. */
|
|
283
|
+
internal fun propsOf(n: Node, scope: SduiScope, ctx: SduiCtx, path: String?): Map<String, Any?> =
|
|
284
|
+
scope.nodeErrors.forNode(n, path) { resolveValue(n.props(), scope, ctx.theme) }.asMap() ?: emptyMap()
|
|
285
|
+
|
|
286
|
+
internal fun imageUrl(v: Any?): String? = when (v) {
|
|
287
|
+
is String -> v.takeIf { it.isNotBlank() }
|
|
288
|
+
is Map<*, *> -> (v["uri"] as? String)?.takeIf { it.isNotBlank() }
|
|
289
|
+
else -> null
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
internal fun contentScale(mode: Any?) = when (mode) {
|
|
293
|
+
"contain" -> ContentScale.Fit
|
|
294
|
+
"stretch" -> ContentScale.FillBounds
|
|
295
|
+
else -> ContentScale.Crop
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Which drawing branch a node `type` takes; the first matching branch wins (a name in both a branch and KIT_NODE_TYPES is drawn by the branch). */
|
|
299
|
+
internal enum class NodeKind {
|
|
300
|
+
VIEW, IMAGE_BACKGROUND, SCREEN, GRID, TEXT, TITLE, IMAGE, BADGE, BADGE_RIBBON, TAG, ICON, BUTTON, TAB_VIEW, CAROUSEL,
|
|
301
|
+
PAGINATION, CHIP, SCROLL_VIEW, INPUT_SEARCH, KIT, UNSUPPORTED,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
internal fun nodeKindOf(type: String?): NodeKind = when (type) {
|
|
305
|
+
"View", "TouchableOpacity", "Item" -> NodeKind.VIEW
|
|
306
|
+
"ImageBackground" -> NodeKind.IMAGE_BACKGROUND
|
|
307
|
+
"Screen" -> NodeKind.SCREEN
|
|
308
|
+
"Section", "Card" -> NodeKind.GRID
|
|
309
|
+
"Text" -> NodeKind.TEXT
|
|
310
|
+
"Title" -> NodeKind.TITLE
|
|
311
|
+
"Image" -> NodeKind.IMAGE
|
|
312
|
+
"Badge" -> NodeKind.BADGE
|
|
313
|
+
"BadgeRibbon" -> NodeKind.BADGE_RIBBON
|
|
314
|
+
"Tag" -> NodeKind.TAG
|
|
315
|
+
"Icon" -> NodeKind.ICON
|
|
316
|
+
"Button" -> NodeKind.BUTTON
|
|
317
|
+
"TabView" -> NodeKind.TAB_VIEW
|
|
318
|
+
"Carousel" -> NodeKind.CAROUSEL
|
|
319
|
+
"Pagination" -> NodeKind.PAGINATION
|
|
320
|
+
"Chip" -> NodeKind.CHIP
|
|
321
|
+
"ScrollView" -> NodeKind.SCROLL_VIEW
|
|
322
|
+
"InputSearch" -> NodeKind.INPUT_SEARCH
|
|
323
|
+
in KIT_NODE_TYPES -> NodeKind.KIT
|
|
324
|
+
else -> NodeKind.UNSUPPORTED
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** ViewLike's layout decisions: modifier flags for [toModifier], whether the content needs a Box, whether the main axis fills. */
|
|
328
|
+
internal data class ViewPlan(
|
|
329
|
+
val stretchH: Boolean, val stretch: Boolean, val weight: Boolean, val sized: Boolean, val fillMain: Boolean, val wrapBox: Boolean,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
internal fun viewPlanOf(sty: Sty, parent: Parent, hasBgImage: Boolean, hasAbsolute: Boolean): ViewPlan {
|
|
333
|
+
// row with alignItems:stretch (default): every child is as tall as the tallest one
|
|
334
|
+
val stretchH = parent.fillHeight && !sty.hasHeight && !sty.isAbsolute
|
|
335
|
+
val sized = sty.hasHeight || sty.aspect != null || sty.isFlexOne || parent.fillHeight
|
|
336
|
+
val justify = sty.str("justifyContent")
|
|
337
|
+
val fillMain = sized && justify in setOf("center", "flex-end", "space-between")
|
|
338
|
+
return ViewPlan(
|
|
339
|
+
stretchH = stretchH,
|
|
340
|
+
stretch = parent.stretch && !sty.isAbsolute,
|
|
341
|
+
weight = sty.isFlexOne,
|
|
342
|
+
sized = sized,
|
|
343
|
+
fillMain = fillMain,
|
|
344
|
+
wrapBox = hasBgImage || hasAbsolute,
|
|
345
|
+
)
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
internal enum class FlexKind { ROW, WRAP, COLUMN }
|
|
349
|
+
internal enum class Justify { START, CENTER, END, SPACE_BETWEEN }
|
|
350
|
+
internal enum class Cross { START, CENTER, END }
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* flexDirection/justifyContent/alignItems/gap -> Row / FlowRow / Column. [fillMain]: the container fills its main axis
|
|
354
|
+
* (fillMaxWidth for Row / FlowRow, fillMaxSize for Column). [intrinsicHeight]: a Row (not wrapping) gets height(IntrinsicSize.Max).
|
|
355
|
+
*/
|
|
356
|
+
internal data class FlexPlan(
|
|
357
|
+
val kind: FlexKind, val justify: Justify, val cross: Cross, val gap: Dp, val rowGap: Dp, val stretch: Boolean,
|
|
358
|
+
val intrinsicHeight: Boolean, val fillMain: Boolean,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
internal fun flexPlanOf(sty: Sty, fillMain: Boolean): FlexPlan {
|
|
362
|
+
val gap = (sty.dp("gap") ?: sty.dp("rowGap") ?: 0.dp).coerceAtLeast(0.dp)
|
|
363
|
+
val justify = sty.str("justifyContent")
|
|
364
|
+
val align = sty.str("alignItems")
|
|
365
|
+
val stretch = align == null || align == "stretch"
|
|
366
|
+
return FlexPlan(
|
|
367
|
+
kind = if (!sty.isRow) FlexKind.COLUMN else if (sty.str("flexWrap") == "wrap") FlexKind.WRAP else FlexKind.ROW,
|
|
368
|
+
justify = when (justify) {
|
|
369
|
+
"center" -> Justify.CENTER
|
|
370
|
+
"flex-end" -> Justify.END
|
|
371
|
+
"space-between" -> Justify.SPACE_BETWEEN
|
|
372
|
+
else -> Justify.START
|
|
373
|
+
},
|
|
374
|
+
cross = when (align) {
|
|
375
|
+
"center" -> Cross.CENTER
|
|
376
|
+
"flex-end" -> Cross.END
|
|
377
|
+
else -> Cross.START
|
|
378
|
+
},
|
|
379
|
+
gap = gap,
|
|
380
|
+
rowGap = (sty.dp("rowGap") ?: gap).coerceAtLeast(0.dp),
|
|
381
|
+
stretch = stretch,
|
|
382
|
+
intrinsicHeight = stretch && !sty.hasHeight,
|
|
383
|
+
fillMain = fillMain,
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** How one flex child is rendered: the [Parent] it is told about and whether it gets `weight(1f)` (flex: 1 in a Row / Column). */
|
|
388
|
+
internal data class FlexChild(val parent: Parent, val weight: Boolean)
|
|
389
|
+
|
|
390
|
+
internal fun flexChildOf(plan: FlexPlan, childSty: Sty): FlexChild = when (plan.kind) {
|
|
391
|
+
FlexKind.WRAP -> FlexChild(Parent(stretch = false), false)
|
|
392
|
+
FlexKind.ROW -> FlexChild(Parent(stretch = false, fillHeight = plan.stretch), childSty.isFlexOne)
|
|
393
|
+
FlexKind.COLUMN -> FlexChild(Parent(stretch = plan.stretch), childSty.isFlexOne)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
internal enum class Corner { TOP_START, TOP_END, BOTTOM_START, BOTTOM_END }
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Where an absolute child sits: the Box corner and the offset from it. `left` wins over `right` and `top` over `bottom`
|
|
400
|
+
* (CSS). [stretchW] / [stretchH] (non-null) = both opposite edges are set and the size on that axis is not: the child is
|
|
401
|
+
* as wide (tall) as the parent minus that total inset, as in CSS / React Native (`left: 0, right: 0` = full width).
|
|
402
|
+
*/
|
|
403
|
+
internal data class AbsolutePlan(val corner: Corner, val dx: Dp, val dy: Dp, val stretchW: Dp? = null, val stretchH: Dp? = null)
|
|
404
|
+
|
|
405
|
+
internal fun absolutePlanOf(s: Sty): AbsolutePlan {
|
|
406
|
+
val left = s.dp("left"); val right = s.dp("right"); val top = s.dp("top"); val bottom = s.dp("bottom")
|
|
407
|
+
val end = left == null && right != null
|
|
408
|
+
val low = top == null && bottom != null
|
|
409
|
+
val corner = when {
|
|
410
|
+
end && low -> Corner.BOTTOM_END
|
|
411
|
+
end -> Corner.TOP_END
|
|
412
|
+
low -> Corner.BOTTOM_START
|
|
413
|
+
else -> Corner.TOP_START
|
|
414
|
+
}
|
|
415
|
+
val dx = if (end) -right!! else (left ?: 0.dp)
|
|
416
|
+
val dy = if (low) -bottom!! else (top ?: 0.dp)
|
|
417
|
+
// only a node whose size on that axis is fully free stretches: a width / min / max keeps the left (top) anchoring,
|
|
418
|
+
// where the bounds still apply ("auto" counts as free)
|
|
419
|
+
fun free(vararg keys: String) = keys.all { k -> s.m[k].let { it == null || it == "auto" } }
|
|
420
|
+
val stretchW = if (left != null && right != null && free("width", "minWidth", "maxWidth")) left + right else null
|
|
421
|
+
val stretchH = if (top != null && bottom != null && free("height", "minHeight", "maxHeight")) top + bottom else null
|
|
422
|
+
return AbsolutePlan(corner, dx, dy, stretchW, stretchH)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Width of a card spanning [span] 12-column spans (never negative). */
|
|
426
|
+
internal fun gridSpanWidth(sizePerSpan: Dp, gutter: Dp, span: Int): Dp = (sizePerSpan * span + gutter * (span - 1)).coerceAtLeast(0.dp)
|
|
427
|
+
|
|
428
|
+
/** A grid `Item`'s size: [height] only when heightSpan > 0. */
|
|
429
|
+
internal data class ItemSize(val width: Dp, val height: Dp?)
|
|
430
|
+
|
|
431
|
+
internal fun itemSizeOf(a: ItemArgs, sizePerSpan: Dp, gutter: Dp) =
|
|
432
|
+
ItemSize(gridSpanWidth(sizePerSpan, gutter, a.widthSpan), if (a.heightSpan > 0) gridSpanWidth(sizePerSpan, gutter, a.heightSpan) else null)
|
|
433
|
+
|
|
434
|
+
internal fun isGridItem(n: Node) = n.type() == "Item"
|
|
435
|
+
|
|
436
|
+
@Composable
|
|
437
|
+
internal fun RenderNode(
|
|
438
|
+
node: Node,
|
|
439
|
+
scope: SduiScope,
|
|
440
|
+
ctx: SduiCtx,
|
|
441
|
+
parent: Parent = Parent(),
|
|
442
|
+
extra: Modifier = Modifier,
|
|
443
|
+
path: String = "",
|
|
444
|
+
/** The node's styles when its parent already resolved them for layout. */
|
|
445
|
+
pre: PreSty? = null,
|
|
446
|
+
) {
|
|
447
|
+
CompositionLocalProvider(LocalNodePath provides path) { RenderNodeBody(node, scope, ctx, parent, extra, pre) }
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
@Composable
|
|
451
|
+
private fun RenderNodeBody(
|
|
452
|
+
node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?,
|
|
453
|
+
) {
|
|
454
|
+
val type = node.type()
|
|
455
|
+
when (nodeKindOf(type)) {
|
|
456
|
+
NodeKind.VIEW -> ViewLike(node, scope, ctx, parent, extra, pre, bgImage = null)
|
|
457
|
+
NodeKind.IMAGE_BACKGROUND -> {
|
|
458
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
459
|
+
ViewLike(node, scope, ctx, parent, extra, pre, bgImage = imageUrl(p["source"]) ?: "", bgMode = p["resizeMode"])
|
|
460
|
+
}
|
|
461
|
+
NodeKind.SCREEN -> ScreenRegion(node, scope, ctx, parent, extra, pre)
|
|
462
|
+
NodeKind.GRID -> GridContainer(node, scope, ctx, extra, card = type == "Card")
|
|
463
|
+
NodeKind.TEXT -> TextNode(node, scope, ctx, parent, extra, pre)
|
|
464
|
+
NodeKind.TITLE -> TitleNode(node, scope, ctx, extra)
|
|
465
|
+
NodeKind.IMAGE -> ImageNode(node, scope, ctx, parent, extra, pre)
|
|
466
|
+
NodeKind.BADGE -> {
|
|
467
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
468
|
+
val a = badgeArgsOf(p)
|
|
469
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
470
|
+
Badge(label = a.label, backgroundColor = a.backgroundColor, modifier = extra.then(sty.toModifier(false, base = parent.percentBase)))
|
|
471
|
+
}
|
|
472
|
+
NodeKind.BADGE_RIBBON -> {
|
|
473
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
474
|
+
val a = ribbonArgsOf(p)
|
|
475
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
476
|
+
BadgeRibbon(
|
|
477
|
+
position = a.position,
|
|
478
|
+
label = a.label,
|
|
479
|
+
isRound = a.isRound,
|
|
480
|
+
modifier = extra.then(sty.toModifier(false, base = parent.percentBase)),
|
|
481
|
+
)
|
|
482
|
+
}
|
|
483
|
+
NodeKind.TAG -> TagNode(node, scope, ctx, extra)
|
|
484
|
+
NodeKind.ICON -> {
|
|
485
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
486
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
487
|
+
val a = iconArgsOf(p, ctx.theme.colors.text.default)
|
|
488
|
+
Icon(
|
|
489
|
+
source = a.source,
|
|
490
|
+
size = a.size,
|
|
491
|
+
color = a.color,
|
|
492
|
+
modifier = extra.then(sty.toModifier(false, base = parent.percentBase)),
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
NodeKind.BUTTON -> ButtonNode(node, scope, ctx, parent, extra)
|
|
496
|
+
NodeKind.TAB_VIEW -> TabViewNode(node, scope, ctx, extra)
|
|
497
|
+
NodeKind.CAROUSEL -> CarouselNode(node, scope, ctx, extra)
|
|
498
|
+
NodeKind.PAGINATION -> {
|
|
499
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
500
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
501
|
+
Box(extra.then(sty.toModifier(false, base = parent.percentBase)), contentAlignment = Alignment.Center) {
|
|
502
|
+
val a = paginationArgsOf(p)
|
|
503
|
+
when (a.kind) {
|
|
504
|
+
PaginationKind.DOT -> PaginationDot(activeIndex = a.active, dataLength = a.length)
|
|
505
|
+
PaginationKind.WHITE_DOT -> PaginationWhiteDot(activeIndex = a.active, dataLength = a.length)
|
|
506
|
+
PaginationKind.NUMBER -> PaginationNumber(activeIndex = a.active, dataLength = a.numberLength)
|
|
507
|
+
PaginationKind.SCROLL -> {
|
|
508
|
+
val items = rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current)
|
|
509
|
+
val base = LocalNodePath.current
|
|
510
|
+
// inside the kit's scrolling row a child's width is unbounded: its percents resolve against the
|
|
511
|
+
// viewport, recorded by the kit's `modifier` (it sits before the kit's horizontalScroll). Only
|
|
512
|
+
// installed when a child sizes in percents; the styles are resolved once here and handed on (the
|
|
513
|
+
// child reports their failures when it renders).
|
|
514
|
+
val pres = items.map { preStyOf(it.node, it.scope, ctx) }
|
|
515
|
+
val pb = rememberPercentBase(pres.map { it.sty })
|
|
516
|
+
PaginationScroll(modifier = Modifier.percentBase(pb)) {
|
|
517
|
+
Row {
|
|
518
|
+
items.forEachIndexed { i, e ->
|
|
519
|
+
RenderNode(e.node, e.scope, ctx, Parent(stretch = false, percentBase = pb), path = childPath(base, e), pre = pres[i])
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
NodeKind.CHIP -> ChipNode(node, scope, ctx, extra)
|
|
528
|
+
NodeKind.SCROLL_VIEW -> ScrollNode(node, scope, ctx, parent, extra, pre)
|
|
529
|
+
NodeKind.INPUT_SEARCH -> SearchNode(node, scope, ctx, extra)
|
|
530
|
+
NodeKind.KIT -> KitNode(type!!, node, scope, ctx, parent, extra, pre)
|
|
531
|
+
NodeKind.UNSUPPORTED -> UnsupportedNode(type, node, ctx)
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** A node type the renderer does not draw (CornerStone, PlatformWidget, anything unknown): nothing is drawn, a warning is logged and `sdui_node_error` (`unsupported_type`) is reported once per path. */
|
|
536
|
+
@Composable
|
|
537
|
+
private fun UnsupportedNode(type: String?, node: Node, ctx: SduiCtx) {
|
|
538
|
+
val path = LocalNodePath.current
|
|
539
|
+
val id = node["id"] as? String
|
|
540
|
+
ctx.log.w("$path: skipped unsupported node type: $type")
|
|
541
|
+
LaunchedEffect(path) { ctx.session.nodeError("unsupported_type", "unsupported_type", path, type, id) }
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private fun Modifier.tap(ctx: SduiCtx, node: Node, scope: SduiScope, nodePath: String, activeOpacity: Float = 0.2f): Modifier {
|
|
545
|
+
val actions = node["actions"].asList()
|
|
546
|
+
if (actions.isNullOrEmpty()) return this
|
|
547
|
+
// kit Clickable modifier: opacity feedback on press
|
|
548
|
+
return activeOpacityClickable(activeOpacity = activeOpacity) { ctx.dispatch(actions, "onPress", scope, emptyList(), nodePath, node["id"] as? String, node.type()) }
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
@Composable
|
|
552
|
+
private fun ViewLike(
|
|
553
|
+
node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?,
|
|
554
|
+
bgImage: String?, bgMode: Any? = null,
|
|
555
|
+
) {
|
|
556
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
557
|
+
val all = rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current)
|
|
558
|
+
// each child's styles are resolved once here (layout needs them); the child reports their failures when it renders
|
|
559
|
+
val (flow, abs) = layChildren(all) { preStyOf(it.node, it.scope, ctx) }
|
|
560
|
+
val base = LocalNodePath.current
|
|
561
|
+
val plan = viewPlanOf(sty, parent, hasBgImage = bgImage != null, hasAbsolute = abs.isNotEmpty())
|
|
562
|
+
val shrink = shrinkWrapsColumn(sty, plan, flow.map { it.pre.sty }, node)
|
|
563
|
+
// with a background image / absolute children the padding goes on the in-flow layer: like CSS, those are laid out
|
|
564
|
+
// against the padding box (a `left/top/right/bottom: 0` background covers the padding too)
|
|
565
|
+
val mod = extra.then(sty.toModifier(plan.stretch, weight = plan.weight, base = parent.percentBase, padding = !plan.wrapBox))
|
|
566
|
+
.let { if (shrink) it.width(IntrinsicSize.Max) else it }
|
|
567
|
+
.let { if (plan.stretchH) it.fillMaxHeight() else it }
|
|
568
|
+
.tap(ctx, node, scope, LocalNodePath.current, (node.props()["activeOpacity"] as? Number)?.toFloat() ?: 0.2f)
|
|
569
|
+
val content: @Composable (Modifier) -> Unit = { inner ->
|
|
570
|
+
FlexLayout(sty, flow, ctx, inner, plan.fillMain)
|
|
571
|
+
}
|
|
572
|
+
if (!plan.wrapBox) {
|
|
573
|
+
content(mod)
|
|
574
|
+
return
|
|
575
|
+
}
|
|
576
|
+
// CSS: the in-flow content sizes the view; the background image fills it and the absolute children are laid over it
|
|
577
|
+
// without changing its size (a Box would size itself by the absolute children and squeeze the content into that)
|
|
578
|
+
val slots = absSlotsOf(flow, abs)
|
|
579
|
+
Layout(
|
|
580
|
+
contents = listOf(
|
|
581
|
+
{
|
|
582
|
+
if (!bgImage.isNullOrEmpty()) {
|
|
583
|
+
Image(source = bgImage, modifier = Modifier,
|
|
584
|
+
options = Options(alignment = Alignment.Center, contentScale = contentScale(bgMode)), loading = false)
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
{ content(sty.paddingModifier()) },
|
|
588
|
+
{ abs.forEach { c -> AbsoluteChild(c.e.node, c.e.scope, ctx, childPath(base, c.e), c.pre) } },
|
|
589
|
+
),
|
|
590
|
+
modifier = mod,
|
|
591
|
+
measurePolicy = remember(slots) { OverlayMeasurePolicy(slots) },
|
|
592
|
+
)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** Box corner of an absolute child. */
|
|
596
|
+
internal fun cornerAlignment(c: Corner): Alignment = when (c) {
|
|
597
|
+
Corner.TOP_END -> Alignment.TopEnd
|
|
598
|
+
Corner.BOTTOM_END -> Alignment.BottomEnd
|
|
599
|
+
Corner.BOTTOM_START -> Alignment.BottomStart
|
|
600
|
+
Corner.TOP_START -> Alignment.TopStart
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* [ViewLike]'s box: slot 0 = background image, 1 = the in-flow content, 2 = the absolute children (one layout each, in
|
|
605
|
+
* [slots] order). The size (and the intrinsics) come from the in-flow content alone; the background is measured at that
|
|
606
|
+
* size; each absolute child gets the incoming constraints (min 0, as a Box gives), or exactly the parent size minus its
|
|
607
|
+
* insets on a stretched axis, and sits at its corner of that size. Paint order: background, the absolute children marked
|
|
608
|
+
* [AbsSlot.below], the content, the other absolute children.
|
|
609
|
+
*/
|
|
610
|
+
private class OverlayMeasurePolicy(private val slots: List<AbsSlot>) : MultiContentMeasurePolicy {
|
|
611
|
+
override fun MeasureScope.measure(measurables: List<List<Measurable>>, constraints: Constraints): MeasureResult {
|
|
612
|
+
val (bgs, flows, abss) = measurables
|
|
613
|
+
val flow = flows.map { it.measure(constraints) }
|
|
614
|
+
val w = constraints.constrainWidth(flow.maxOfOrNull { it.width } ?: 0)
|
|
615
|
+
val h = constraints.constrainHeight(flow.maxOfOrNull { it.height } ?: 0)
|
|
616
|
+
val bg = bgs.map { it.measure(Constraints.fixed(w, h)) }
|
|
617
|
+
val ab = abss.mapIndexed { i, m ->
|
|
618
|
+
val s = slots.getOrNull(i)
|
|
619
|
+
val sw = s?.stretchW?.let { (w - it.roundToPx()).coerceAtLeast(0) }
|
|
620
|
+
val sh = s?.stretchH?.let { (h - it.roundToPx()).coerceAtLeast(0) }
|
|
621
|
+
m.measure(
|
|
622
|
+
Constraints(
|
|
623
|
+
minWidth = sw ?: 0, maxWidth = sw ?: constraints.maxWidth,
|
|
624
|
+
minHeight = sh ?: 0, maxHeight = sh ?: constraints.maxHeight,
|
|
625
|
+
),
|
|
626
|
+
)
|
|
627
|
+
}
|
|
628
|
+
fun Placeable.PlacementScope.placeAbs(under: Boolean) = ab.forEachIndexed { i, p ->
|
|
629
|
+
val s = slots.getOrNull(i)
|
|
630
|
+
if ((s?.below == true) != under) return@forEachIndexed
|
|
631
|
+
val a = s?.align ?: Alignment.TopStart
|
|
632
|
+
p.place(a.align(IntSize(p.width, p.height), IntSize(w, h), layoutDirection))
|
|
633
|
+
}
|
|
634
|
+
return layout(w, h) {
|
|
635
|
+
bg.forEach { it.place(0, 0) }
|
|
636
|
+
placeAbs(under = true)
|
|
637
|
+
flow.forEach { it.place(0, 0) }
|
|
638
|
+
placeAbs(under = false)
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
override fun IntrinsicMeasureScope.minIntrinsicWidth(measurables: List<List<IntrinsicMeasurable>>, height: Int) =
|
|
642
|
+
measurables[1].maxOfOrNull { it.minIntrinsicWidth(height) } ?: 0
|
|
643
|
+
override fun IntrinsicMeasureScope.maxIntrinsicWidth(measurables: List<List<IntrinsicMeasurable>>, height: Int) =
|
|
644
|
+
measurables[1].maxOfOrNull { it.maxIntrinsicWidth(height) } ?: 0
|
|
645
|
+
override fun IntrinsicMeasureScope.minIntrinsicHeight(measurables: List<List<IntrinsicMeasurable>>, width: Int) =
|
|
646
|
+
measurables[1].maxOfOrNull { it.minIntrinsicHeight(width) } ?: 0
|
|
647
|
+
override fun IntrinsicMeasureScope.maxIntrinsicHeight(measurables: List<List<IntrinsicMeasurable>>, width: Int) =
|
|
648
|
+
measurables[1].maxOfOrNull { it.maxIntrinsicHeight(width) } ?: 0
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
@Composable
|
|
652
|
+
private fun AbsoluteChild(n: Node, sc: SduiScope, ctx: SduiCtx, path: String, pre: PreSty) {
|
|
653
|
+
val s = pre.sty // position: the child reports its styles itself
|
|
654
|
+
val plan = absolutePlanOf(s)
|
|
655
|
+
// this wrapper (not the node) is the overlay's direct child, so it carries the node's zIndex (a badge over an image);
|
|
656
|
+
// on a stretched axis the parent measures the wrapper at exactly the spanned size and the node fills it
|
|
657
|
+
val fill = Modifier
|
|
658
|
+
.let { if (plan.stretchW != null) it.fillMaxWidth() else it }
|
|
659
|
+
.let { if (plan.stretchH != null) it.fillMaxHeight() else it }
|
|
660
|
+
Box(Modifier.specZIndex(s).offset(plan.dx, plan.dy)) {
|
|
661
|
+
RenderNode(n, sc, ctx, Parent(stretch = false), fill, path = path, pre = pre)
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Node types whose intrinsic size can be asked for: the kit Image is a BoxWithConstraints (a SubcomposeLayout, which
|
|
667
|
+
* throws on intrinsics) unless both its width and height are fixed numbers; everything else outside this list is not checked.
|
|
668
|
+
* A percent style anywhere in the subtree also makes it unsafe.
|
|
669
|
+
*/
|
|
670
|
+
private val SIZE_KEYS = setOf("width", "height", "minWidth", "maxWidth", "minHeight", "maxHeight", "flexBasis")
|
|
671
|
+
|
|
672
|
+
internal fun intrinsicSafe(n: Node): Boolean {
|
|
673
|
+
val ok = when (nodeKindOf(n.type())) {
|
|
674
|
+
NodeKind.VIEW, NodeKind.TEXT, NodeKind.ICON, NodeKind.BADGE, NodeKind.TAG -> true
|
|
675
|
+
NodeKind.IMAGE -> n["styles"].asMap().let { s -> fixedSide(s?.get("width")) && fixedSide(s?.get("height")) }
|
|
676
|
+
else -> false
|
|
677
|
+
}
|
|
678
|
+
// a percent size anywhere below would record its base inside the intrinsic width it feeds (shrinks frame after frame)
|
|
679
|
+
// ...and a size bound to data might resolve to a percent at runtime: count a binding on a size key as one too
|
|
680
|
+
val percent = n["styles"].asMap()?.any { (k, v) ->
|
|
681
|
+
v is String && (v.trim().endsWith("%") || (k in SIZE_KEYS && v.contains('{')))
|
|
682
|
+
} == true
|
|
683
|
+
return ok && !percent && n.children().all { c -> c.asMap()?.let(::intrinsicSafe) ?: true }
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* CSS shrink-to-fit: a column its parent does not stretch, with no width of its own, is as wide as its widest child and
|
|
688
|
+
* its stretching children fill THAT width. Compose's fillMaxWidth would instead grow it to all the room left (a pill in a
|
|
689
|
+
* row of tabs eats the row). Only when a child would stretch and the subtree can be measured intrinsically.
|
|
690
|
+
*/
|
|
691
|
+
internal fun shrinkWrapsColumn(sty: Sty, plan: ViewPlan, flowStys: List<Sty>, node: Node): Boolean =
|
|
692
|
+
!sty.isRow && (sty.str("alignItems") ?: "stretch") == "stretch" && !plan.stretch && !plan.weight &&
|
|
693
|
+
// a growing column (any flex / flexGrow), an absolute one (left+right spans it) or one asking to stretch keeps filling
|
|
694
|
+
!grows(sty) && !sty.isAbsolute && sty.str("alignSelf") != "stretch" &&
|
|
695
|
+
!sty.hasWidth && sty.m["minWidth"] == null && sty.m["maxWidth"] == null &&
|
|
696
|
+
flowStys.any { !it.hasWidth && !it.isAbsolute } &&
|
|
697
|
+
// a percent child would measure against the intrinsic width it feeds (it shrinks frame after frame)
|
|
698
|
+
flowStys.none { it.needsPercentBase() } && intrinsicSafe(node)
|
|
699
|
+
|
|
700
|
+
private fun grows(sty: Sty): Boolean =
|
|
701
|
+
((sty.m["flex"] as? Number)?.toDouble() ?: 0.0) > 0.0 || ((sty.m["flexGrow"] as? Number)?.toDouble() ?: 0.0) > 0.0
|
|
702
|
+
|
|
703
|
+
/** A size the renderer applies as a fixed modifier: a finite number from 0 up (a negative one is dropped by the style plan). */
|
|
704
|
+
private fun fixedSide(v: Any?): Boolean = (v as? Number)?.toDouble()?.let { it.isFinite() && it >= 0.0 } == true
|
|
705
|
+
|
|
706
|
+
/** flexDirection/justifyContent/alignItems/gap -> Row or Column. */
|
|
707
|
+
@OptIn(ExperimentalLayoutApi::class)
|
|
708
|
+
@Composable
|
|
709
|
+
private fun FlexLayout(sty: Sty, items: List<Laid>, ctx: SduiCtx, mod: Modifier, fillMain: Boolean) {
|
|
710
|
+
val base = LocalNodePath.current
|
|
711
|
+
val plan = flexPlanOf(sty, fillMain)
|
|
712
|
+
val gap = plan.gap
|
|
713
|
+
// only when a child sizes in percents: the layout's own size becomes their base (a Row child is otherwise measured
|
|
714
|
+
// against what is left of the row, so two 50% children would come out 50% and 25%); else nothing changes
|
|
715
|
+
val pb = rememberPercentBase(items.map { it.pre.sty })
|
|
716
|
+
fun parentOf(ch: FlexChild) = if (pb == null) ch.parent else ch.parent.copy(percentBase = pb)
|
|
717
|
+
when (plan.kind) {
|
|
718
|
+
FlexKind.WRAP -> {
|
|
719
|
+
FlowRow(
|
|
720
|
+
(if (plan.fillMain) mod.fillMaxWidth() else mod).percentBase(pb),
|
|
721
|
+
horizontalArrangement = Arrangement.spacedBy(gap),
|
|
722
|
+
verticalArrangement = Arrangement.spacedBy(plan.rowGap),
|
|
723
|
+
) {
|
|
724
|
+
items.forEach { c ->
|
|
725
|
+
val ch = flexChildOf(plan, c.pre.sty)
|
|
726
|
+
RenderNode(c.e.node, c.e.scope, ctx, parentOf(ch), Modifier, path = childPath(base, c.e), pre = c.pre)
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
FlexKind.ROW -> {
|
|
731
|
+
val h = when (plan.justify) {
|
|
732
|
+
Justify.CENTER -> Arrangement.spacedBy(gap, Alignment.CenterHorizontally)
|
|
733
|
+
Justify.END -> Arrangement.spacedBy(gap, Alignment.End)
|
|
734
|
+
Justify.SPACE_BETWEEN -> Arrangement.SpaceBetween
|
|
735
|
+
Justify.START -> Arrangement.spacedBy(gap)
|
|
736
|
+
}
|
|
737
|
+
val v = when (plan.cross) {
|
|
738
|
+
Cross.CENTER -> Alignment.CenterVertically
|
|
739
|
+
Cross.END -> Alignment.Bottom
|
|
740
|
+
Cross.START -> Alignment.Top
|
|
741
|
+
}
|
|
742
|
+
// the base sits before the intrinsic height, so the children's intrinsics already see the row's width
|
|
743
|
+
val rowMod = (if (plan.fillMain) mod.fillMaxWidth() else mod).percentBase(pb)
|
|
744
|
+
.let { if (plan.intrinsicHeight) it.height(IntrinsicSize.Max) else it }
|
|
745
|
+
Row(rowMod, horizontalArrangement = h, verticalAlignment = v) {
|
|
746
|
+
items.forEach { c ->
|
|
747
|
+
val ch = flexChildOf(plan, c.pre.sty)
|
|
748
|
+
RenderNode(c.e.node, c.e.scope, ctx, parentOf(ch), if (ch.weight) Modifier.weight(1f) else Modifier, path = childPath(base, c.e), pre = c.pre)
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
FlexKind.COLUMN -> {
|
|
753
|
+
val v = when (plan.justify) {
|
|
754
|
+
Justify.CENTER -> Arrangement.spacedBy(gap, Alignment.CenterVertically)
|
|
755
|
+
Justify.END -> Arrangement.spacedBy(gap, Alignment.Bottom)
|
|
756
|
+
Justify.SPACE_BETWEEN -> Arrangement.SpaceBetween
|
|
757
|
+
Justify.START -> Arrangement.spacedBy(gap)
|
|
758
|
+
}
|
|
759
|
+
val h = when (plan.cross) {
|
|
760
|
+
Cross.CENTER -> Alignment.CenterHorizontally
|
|
761
|
+
Cross.END -> Alignment.End
|
|
762
|
+
Cross.START -> Alignment.Start
|
|
763
|
+
}
|
|
764
|
+
// a Column child's incoming height is what is left of the column: percent heights need the column's height
|
|
765
|
+
Column((if (plan.fillMain) mod.fillMaxSize() else mod).percentBase(pb), verticalArrangement = v, horizontalAlignment = h) {
|
|
766
|
+
items.forEach { c ->
|
|
767
|
+
val ch = flexChildOf(plan, c.pre.sty)
|
|
768
|
+
RenderNode(c.e.node, c.e.scope, ctx, parentOf(ch), if (ch.weight) Modifier.weight(1f) else Modifier,
|
|
769
|
+
path = childPath(base, c.e), pre = c.pre)
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Top gap of one child of a nested `Screen` (grid region): Spacing.M unless the screen's `useGridLayout` or the child's
|
|
778
|
+
* `useMargin` is `false` (any other value, missing included, keeps the gap). Both are RAW props (not resolved).
|
|
779
|
+
*/
|
|
780
|
+
internal fun screenChildTopOf(screenProps: Map<String, Any?>, childProps: Map<String, Any?>): Dp =
|
|
781
|
+
if (screenProps["useGridLayout"] != false && childProps["useMargin"] != false) Spacing.M else 0.dp
|
|
782
|
+
|
|
783
|
+
/** Nested `Screen` = grid region: each child gets a top gap of Spacing.M unless its props.useMargin == false. */
|
|
784
|
+
@Composable
|
|
785
|
+
private fun ScreenRegion(node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?) {
|
|
786
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
787
|
+
val screenProps = node.props()
|
|
788
|
+
val base = LocalNodePath.current
|
|
789
|
+
Column(extra.then(sty.toModifier(stretch = true, base = parent.percentBase))) {
|
|
790
|
+
rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current).forEach { e ->
|
|
791
|
+
val top = screenChildTopOf(screenProps, e.node.props())
|
|
792
|
+
// resolved once here for the wrapper's zIndex; the child reports their failures when it renders
|
|
793
|
+
val pre = preStyOf(e.node, e.scope, ctx)
|
|
794
|
+
Box(Modifier.specZIndex(pre.sty).padding(top = top)) { RenderNode(e.node, e.scope, ctx, path = childPath(base, e), pre = pre) }
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Section/Card -> the kit's layout.Section / layout.Card; Item -> layout.Item (12-column grid: widthSpan). The kit Section
|
|
801
|
+
* lays its content out in its own FlowRow; the kit Card is a padded Box, so its Items sit in a FlowRow (plain layout).
|
|
802
|
+
* The grid context (columns / gap / width) is provided to the grid children (gutter 12 / 8).
|
|
803
|
+
*/
|
|
804
|
+
@OptIn(ExperimentalLayoutApi::class)
|
|
805
|
+
@Composable
|
|
806
|
+
private fun GridContainer(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier, card: Boolean) {
|
|
807
|
+
val items = rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current)
|
|
808
|
+
val base = LocalNodePath.current
|
|
809
|
+
val props = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
810
|
+
BoxWithConstraints(extra.fillMaxWidth()) {
|
|
811
|
+
// sizePerSpan / getSizeSpan: width of one 12-column span and of a card spanning n columns
|
|
812
|
+
val cols = GRID_COLS
|
|
813
|
+
val args = gridArgsOf(props, card)
|
|
814
|
+
val gutter = gridGutter(card)
|
|
815
|
+
val sizePerSpan = gridSizePerSpan(maxWidth, args.useMargin, card, args.contentPadding.horizontal())
|
|
816
|
+
val content: @Composable () -> Unit = {
|
|
817
|
+
items.forEach { e ->
|
|
818
|
+
val n = e.node
|
|
819
|
+
// the per-child wrapper is the grid row's direct child, so it carries the child's zIndex; the styles are
|
|
820
|
+
// resolved once here and handed on (the child reports their failures when it renders)
|
|
821
|
+
val pre = preStyOf(n, e.scope, ctx)
|
|
822
|
+
if (isGridItem(n)) {
|
|
823
|
+
// the Item's props are only resolved here (its RenderNode draws a View): report on the Item's path
|
|
824
|
+
val ip = propsOf(n, e.scope, ctx, childPath(base, e))
|
|
825
|
+
val (span, hSpan) = itemArgsOf(ip)
|
|
826
|
+
val size = itemSizeOf(ItemArgs(span, hSpan), sizePerSpan, gutter)
|
|
827
|
+
KitItem(
|
|
828
|
+
widthSpan = span, heightSpan = hSpan,
|
|
829
|
+
modifier = Modifier.specZIndex(pre.sty).width(size.width).let { if (size.height != null) it.height(size.height) else it },
|
|
830
|
+
) {
|
|
831
|
+
RenderNode(n, e.scope, ctx, Parent(stretch = true), path = childPath(base, e), pre = pre)
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
Box(Modifier.specZIndex(pre.sty).fillMaxWidth()) { RenderNode(n, e.scope, ctx, path = childPath(base, e), pre = pre) }
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
if (card) {
|
|
839
|
+
KitCard(
|
|
840
|
+
useShadow = args.useShadow,
|
|
841
|
+
backgroundImage = args.backgroundImage,
|
|
842
|
+
backgroundColor = args.backgroundColor,
|
|
843
|
+
contentPadding = args.contentPadding,
|
|
844
|
+
) {
|
|
845
|
+
FlowRow(
|
|
846
|
+
Modifier.fillMaxWidth(),
|
|
847
|
+
horizontalArrangement = Arrangement.spacedBy(gutter),
|
|
848
|
+
verticalArrangement = Arrangement.spacedBy(gutter),
|
|
849
|
+
) { content() }
|
|
850
|
+
}
|
|
851
|
+
} else {
|
|
852
|
+
KitSection(useMargin = args.useMargin, backgroundImage = args.backgroundImage) { content() }
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
@Composable
|
|
858
|
+
private fun TextNode(node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?) {
|
|
859
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
860
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
861
|
+
val a = textArgsOf(p, sty, ctx.theme.colors.text.default, getScreenDimensions().width.toFloat())
|
|
862
|
+
Text(
|
|
863
|
+
text = a.text,
|
|
864
|
+
color = a.color,
|
|
865
|
+
style = typographyOf(a.typography).let { st ->
|
|
866
|
+
a.lineHeightSp?.let { lh -> st.copy(lineHeight = lh.sp) } ?: st
|
|
867
|
+
},
|
|
868
|
+
textAlign = a.align,
|
|
869
|
+
modifier = extra.then(sty.toModifier(parent.stretch, base = parent.percentBase)),
|
|
870
|
+
maxLines = a.maxLines,
|
|
871
|
+
overflow = a.overflow,
|
|
872
|
+
textDecoration = a.decoration,
|
|
873
|
+
fontFamily = a.fontFamily,
|
|
874
|
+
minLines = a.minLines,
|
|
875
|
+
letterSpacing = a.letterSpacing,
|
|
876
|
+
softWrap = a.softWrap,
|
|
877
|
+
accessibilityId = a.accessibilityId,
|
|
878
|
+
)
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
@Composable
|
|
882
|
+
private fun TitleNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
883
|
+
val nodePath = LocalNodePath.current
|
|
884
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
885
|
+
val a = titleArgsOf(p)
|
|
886
|
+
Title(
|
|
887
|
+
title = a.title,
|
|
888
|
+
type = a.type,
|
|
889
|
+
size = a.size,
|
|
890
|
+
icon = a.icon,
|
|
891
|
+
iconColor = a.iconColor,
|
|
892
|
+
iconAlign = a.iconAlign,
|
|
893
|
+
showRightAction = a.showRightAction,
|
|
894
|
+
showTrailingAction = a.showTrailingAction,
|
|
895
|
+
badgeLabel = a.badgeLabel,
|
|
896
|
+
buttonTitle = a.buttonTitle,
|
|
897
|
+
buttonSize = a.buttonSize,
|
|
898
|
+
onPressRightAction = { ctx.dispatch(node["actions"].asList(), "onPressRightAction", scope, emptyList(), nodePath, node["id"] as? String, node.type()) },
|
|
899
|
+
onPressTrailingAction = { ctx.dispatch(node["actions"].asList(), "onPressTrailingAction", scope, emptyList(), nodePath, node["id"] as? String, node.type()) },
|
|
900
|
+
textOnly = a.textOnly,
|
|
901
|
+
description = a.description,
|
|
902
|
+
modifier = extra,
|
|
903
|
+
)
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
@Composable
|
|
907
|
+
private fun ImageNode(node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?) {
|
|
908
|
+
val nodePath = LocalNodePath.current
|
|
909
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
910
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
911
|
+
val a = imageArgsOf(p) ?: return
|
|
912
|
+
Image(
|
|
913
|
+
source = a.url,
|
|
914
|
+
modifier = extra.then(sty.toModifier(parent.stretch, isImage = true, base = parent.percentBase)),
|
|
915
|
+
options = Options(
|
|
916
|
+
alignment = a.alignment,
|
|
917
|
+
contentScale = a.contentScale,
|
|
918
|
+
colorFilter = a.colorFilter,
|
|
919
|
+
alpha = a.alpha,
|
|
920
|
+
),
|
|
921
|
+
loading = a.loading,
|
|
922
|
+
onStateChanged = { st -> ctx.dispatch(node["actions"].asList(), "onStateChanged", scope, listOf(imageStateName(st)), nodePath, node["id"] as? String, node.type()) },
|
|
923
|
+
)
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
@Composable
|
|
927
|
+
private fun ChipNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
928
|
+
val nodePath = LocalNodePath.current
|
|
929
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
930
|
+
val a = chipArgsOf(p)
|
|
931
|
+
Chip(
|
|
932
|
+
// Intrinsic width: the kit label sits in a weighted row, which collapses to 0 under an unbounded scroll.
|
|
933
|
+
modifier = extra.width(IntrinsicSize.Max),
|
|
934
|
+
label = a.label,
|
|
935
|
+
iconLeft = a.iconLeft,
|
|
936
|
+
iconRight = a.iconRight,
|
|
937
|
+
iconLeftTint = a.iconLeftTint,
|
|
938
|
+
iconRightTint = a.iconRightTint,
|
|
939
|
+
backgroundColor = a.backgroundColor,
|
|
940
|
+
selected = a.selected,
|
|
941
|
+
onClick = { ctx.dispatch(node["actions"].asList(), "onPress", scope, emptyList(), nodePath, node["id"] as? String, node.type()) },
|
|
942
|
+
size = a.size,
|
|
943
|
+
accessibilityLabel = a.accessibilityLabel,
|
|
944
|
+
)
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
@Composable
|
|
948
|
+
private fun ScrollNode(node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier, pre: PreSty?) {
|
|
949
|
+
val sty = styOf(node, scope, ctx, LocalNodePath.current, pre)
|
|
950
|
+
val items = rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current)
|
|
951
|
+
val base = LocalNodePath.current
|
|
952
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
953
|
+
val a = scrollArgsOf(p)
|
|
954
|
+
if (a.horizontal) {
|
|
955
|
+
// inside the scroll a child's width is unbounded: its percents resolve against the viewport (the base sits before
|
|
956
|
+
// horizontalScroll); only installed when a child sizes in percents. Styles are resolved once here and handed on.
|
|
957
|
+
val pres = items.map { preStyOf(it.node, it.scope, ctx) }
|
|
958
|
+
val pb = rememberPercentBase(pres.map { it.sty })
|
|
959
|
+
Row(extra.then(sty.toModifier(true, base = parent.percentBase)).percentBase(pb)
|
|
960
|
+
.horizontalScroll(rememberScrollState(), enabled = a.enabled, reverseScrolling = a.reverse),
|
|
961
|
+
horizontalArrangement = a.horizontalArrangement) {
|
|
962
|
+
items.forEachIndexed { i, e ->
|
|
963
|
+
RenderNode(e.node, e.scope, ctx, Parent(stretch = false, percentBase = pb), path = childPath(base, e), pre = pres[i])
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
} else {
|
|
967
|
+
Column(extra.then(sty.toModifier(true, base = parent.percentBase)).verticalScroll(rememberScrollState(), enabled = a.enabled, reverseScrolling = a.reverse),
|
|
968
|
+
verticalArrangement = a.verticalArrangement) {
|
|
969
|
+
items.forEach { e -> RenderNode(e.node, e.scope, ctx, path = childPath(base, e)) }
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
@Composable
|
|
975
|
+
private fun SearchNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
976
|
+
val nodePath = LocalNodePath.current
|
|
977
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
978
|
+
// `a` and `fire` are remembered (keyed on all they read / capture) so the callbacks below, which capture them, keep their
|
|
979
|
+
// instances across recompositions of an unchanged node (see the note in KitNode).
|
|
980
|
+
val a = remember(node, p) { searchArgsOf(node, p) }
|
|
981
|
+
val text = remember { mutableStateOf("") }
|
|
982
|
+
// actionsFor also reads callbacks placed in props (KB form), not only node["actions"]
|
|
983
|
+
val fire: (String, List<Any?>) -> Unit = remember(node, scope, ctx, nodePath) {
|
|
984
|
+
{ name, args -> ctx.dispatch(actionsFor(node, name), name, scope, args, nodePath, node["id"] as? String, node.type()) }
|
|
985
|
+
}
|
|
986
|
+
Box(extra) {
|
|
987
|
+
InputSearch(
|
|
988
|
+
InputSearchProps(
|
|
989
|
+
text = text,
|
|
990
|
+
buttonText = a.buttonText,
|
|
991
|
+
showButtonText = a.showButtonText,
|
|
992
|
+
placeholder = a.placeholder,
|
|
993
|
+
// the kit InputSearch only reports keystrokes; it never writes its own `text`, so keep it here (works without actions too)
|
|
994
|
+
onChangeText = { t -> text.value = t; fire("onChangeText", listOf(t)) },
|
|
995
|
+
onPressButtonText = { fire("onPressButtonText", emptyList()) },
|
|
996
|
+
disabled = a.disabled,
|
|
997
|
+
icon = a.icon,
|
|
998
|
+
iconColor = a.iconColor,
|
|
999
|
+
onRightIconPressed = { fire("onRightIconPressed", emptyList()) },
|
|
1000
|
+
onFocus = { a.focusEvents.forEach { fire(it, emptyList()) } },
|
|
1001
|
+
onBlur = { fire("onBlur", emptyList()) },
|
|
1002
|
+
loading = a.loading,
|
|
1003
|
+
fontWeight = a.fontWeight,
|
|
1004
|
+
keyboardType = a.keyboardType,
|
|
1005
|
+
backgroundColor = a.backgroundColor,
|
|
1006
|
+
onClearPress = { fire("onClearPress", emptyList()) },
|
|
1007
|
+
leftPosition = a.leftPosition,
|
|
1008
|
+
)
|
|
1009
|
+
)
|
|
1010
|
+
// The node is a pressable that navigates. A pure pressable (onPress, no typing callbacks): overlay swallows typing
|
|
1011
|
+
// and fires onPress. With typing callbacks too there is no overlay (it would block typing); onPress fires on focus.
|
|
1012
|
+
if (a.overlay) {
|
|
1013
|
+
Box(Modifier.matchParentSize().activeOpacityClickable(activeOpacity = 0.2f) { fire("onPress", emptyList()) })
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
@Composable
|
|
1019
|
+
private fun TagNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
1020
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
1021
|
+
val a = tagArgsOf(p)
|
|
1022
|
+
Box(extra) {
|
|
1023
|
+
Tag(label = a.label, icon = a.icon, customColor = a.customColor, color = a.color, size = a.size)
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
@Composable
|
|
1028
|
+
private fun ButtonNode(node: Node, scope: SduiScope, ctx: SduiCtx, parent: Parent, extra: Modifier) {
|
|
1029
|
+
val nodePath = LocalNodePath.current
|
|
1030
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
1031
|
+
val a = buttonArgsOf(p)
|
|
1032
|
+
Button(
|
|
1033
|
+
onClick = { ctx.dispatch(node["actions"].asList(), "onPress", scope, emptyList(), nodePath, node["id"] as? String, node.type()) },
|
|
1034
|
+
type = a.type,
|
|
1035
|
+
size = a.size,
|
|
1036
|
+
title = a.title,
|
|
1037
|
+
iconLeft = a.iconLeft,
|
|
1038
|
+
iconRight = a.iconRight,
|
|
1039
|
+
loading = a.loading,
|
|
1040
|
+
useTintColor = a.useTintColor,
|
|
1041
|
+
isFull = a.isFull,
|
|
1042
|
+
// A column's default alignItems:stretch also stretches a Button's touchable
|
|
1043
|
+
modifier = if (parent.stretch) extra.fillMaxWidth() else extra,
|
|
1044
|
+
)
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* TabView node -> kit TabView used as the STRIP only (pages stay empty, content lives in sibling nodes bound to
|
|
1049
|
+
* state). Reads tabs[{title, icon}], scrollable, direction (default column), selectedIndex.
|
|
1050
|
+
* The kit TabView has no controlled index (initialPage only seeds it), so selection changes that do not come from a tap
|
|
1051
|
+
* on the strip are not pushed into it (documented limitation); a tap reports through onPressTabItem.
|
|
1052
|
+
*/
|
|
1053
|
+
@Composable
|
|
1054
|
+
private fun TabViewNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
1055
|
+
val nodePath = LocalNodePath.current
|
|
1056
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
1057
|
+
val a = tabViewArgsOf(p) ?: return
|
|
1058
|
+
val selected = a.selected
|
|
1059
|
+
val items = a.tabs.map { t ->
|
|
1060
|
+
// a CDN picture is drawn as a 24x24 untinted image, a glyph name through `icon`
|
|
1061
|
+
if (t.isUrl) {
|
|
1062
|
+
TabViewItem(title = t.title, renderIcon = { _ ->
|
|
1063
|
+
Image(source = t.icon, modifier = Modifier.size(24.dp), options = Options(contentScale = ContentScale.Fit), loading = false)
|
|
1064
|
+
}, showDot = t.showDot, dotSize = t.dotSize, badgeValue = t.badge, accessibilityLabel = t.accessibilityLabel)
|
|
1065
|
+
} else TabViewItem(title = t.title, icon = t.icon, showDot = t.showDot, dotSize = t.dotSize, badgeValue = t.badge, accessibilityLabel = t.accessibilityLabel)
|
|
1066
|
+
}
|
|
1067
|
+
// `initialPage` only seeds the kit TabView. When the selection changes from somewhere else
|
|
1068
|
+
// (a `setState` elsewhere) re-seed it; a tap records its own index first, so its state echo does not remount.
|
|
1069
|
+
var shown by remember { mutableIntStateOf(selected) }
|
|
1070
|
+
var seed by remember { mutableIntStateOf(0) }
|
|
1071
|
+
LaunchedEffect(selected) {
|
|
1072
|
+
if (selected != shown) { shown = selected; seed++ }
|
|
1073
|
+
}
|
|
1074
|
+
key(seed) {
|
|
1075
|
+
TabView(
|
|
1076
|
+
modifier = extra,
|
|
1077
|
+
tabs = items,
|
|
1078
|
+
initialPage = selected,
|
|
1079
|
+
type = a.type,
|
|
1080
|
+
scrollable = a.scrollable,
|
|
1081
|
+
fitContent = a.fitContent,
|
|
1082
|
+
selectedColor = a.selectedColor,
|
|
1083
|
+
unselectedColor = a.unselectedColor,
|
|
1084
|
+
direction = a.direction,
|
|
1085
|
+
userScrollEnabled = a.userScrollEnabled,
|
|
1086
|
+
onPageSelected = { i ->
|
|
1087
|
+
ctx.dispatch(node["actions"].asList(), "onPageSelected", scope, listOf(i.toLong()), nodePath, node["id"] as? String, node.type())
|
|
1088
|
+
},
|
|
1089
|
+
onPressTabItem = { i ->
|
|
1090
|
+
shown = i
|
|
1091
|
+
ctx.dispatch(node["actions"].asList(), "onPressTabItem", scope, listOf(i.toLong()), nodePath, node["id"] as? String, node.type())
|
|
1092
|
+
},
|
|
1093
|
+
)
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* Carousel node -> kit Carousel (slides = the node's children). `index` is controlled; the kit Carousel exposes no
|
|
1099
|
+
* pager state / scrollTo, so it stays uncontrolled: swipes report onSnapToItem(i); a state change of `index` made
|
|
1100
|
+
* elsewhere (e.g. the onboarding "Tiếp tục" button) does not move it. Documented limitation. `autoplayInterval` is clamped
|
|
1101
|
+
* to >= 1000 ms. `loop` + a re-seeded `index` only cycles the slides from that index on (earlier ones are dropped).
|
|
1102
|
+
*/
|
|
1103
|
+
@Composable
|
|
1104
|
+
private fun CarouselNode(node: Node, scope: SduiScope, ctx: SduiCtx, extra: Modifier) {
|
|
1105
|
+
val nodePath = LocalNodePath.current
|
|
1106
|
+
val p = propsOf(node, scope, ctx, LocalNodePath.current)
|
|
1107
|
+
val items = rememberExpand(node.children(), scope, ctx.theme, LocalNodePath.current)
|
|
1108
|
+
val a = carouselArgsOf(p, items.size) ?: return
|
|
1109
|
+
val target = a.target
|
|
1110
|
+
// The kit Carousel has no initial page or scrollTo (its PagerState is private). `index` is controlled, so when it
|
|
1111
|
+
// changes from OUTSIDE a swipe (onboarding "Tiếp tục") the Carousel is re-created starting AT that slide: slides before
|
|
1112
|
+
// it are dropped from the pager (offset), and swipes report absolute indexes (page + offset). Swiping back past the
|
|
1113
|
+
// re-seed point is therefore not possible - documented limitation of the kit component.
|
|
1114
|
+
var shown by remember { mutableIntStateOf(target) }
|
|
1115
|
+
var offset by remember { mutableIntStateOf(0) }
|
|
1116
|
+
var seed by remember { mutableIntStateOf(0) }
|
|
1117
|
+
LaunchedEffect(target) {
|
|
1118
|
+
if (target != shown) { shown = target; offset = target; seed++ }
|
|
1119
|
+
}
|
|
1120
|
+
val visible = items.drop(offset)
|
|
1121
|
+
key(seed) {
|
|
1122
|
+
Carousel(
|
|
1123
|
+
itemCount = visible.size,
|
|
1124
|
+
modifier = extra.fillMaxWidth(),
|
|
1125
|
+
loop = a.loop,
|
|
1126
|
+
autoplay = a.autoplay,
|
|
1127
|
+
autoplayInterval = a.autoplayInterval,
|
|
1128
|
+
scrollEnabled = a.scrollEnabled,
|
|
1129
|
+
inactiveSlideOpacity = a.inactiveSlideOpacity,
|
|
1130
|
+
inactiveSlideScale = a.inactiveSlideScale,
|
|
1131
|
+
contentPadding = a.contentPadding,
|
|
1132
|
+
onScrollIndexChanged = { i ->
|
|
1133
|
+
ctx.dispatch(node["actions"].asList(), "onScrollIndexChanged", scope, listOf((i + offset).toLong()), nodePath, node["id"] as? String, node.type())
|
|
1134
|
+
},
|
|
1135
|
+
onSnapToItem = { i ->
|
|
1136
|
+
shown = i + offset
|
|
1137
|
+
ctx.dispatch(node["actions"].asList(), "onSnapToItem", scope, listOf((i + offset).toLong()), nodePath, node["id"] as? String, node.type())
|
|
1138
|
+
},
|
|
1139
|
+
) { page ->
|
|
1140
|
+
val e = visible[page]
|
|
1141
|
+
RenderNode(e.node, e.scope, ctx, Parent(stretch = true), path = childPath(nodePath, e))
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// AI-GENERATED END: SDUI node renderer
|