@momo-kits/native-kits 0.169.13-beta.3-debug → 0.169.13-beta.4
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/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/package.json +1 -1
- package/build.gradle.kts +0 -11
- package/compose/build.gradle.kts +0 -202
- package/compose/compose.podspec +0 -47
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +0 -647
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +0 -1411
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +0 -130
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +0 -524
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +0 -559
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +0 -741
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +0 -221
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +0 -270
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +0 -849
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +0 -212
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +0 -239
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +0 -252
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -206
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -421
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -750
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -398
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -103
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -400
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +0 -154
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +0 -1038
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +0 -848
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +0 -47
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +0 -463
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +0 -1146
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +0 -667
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +0 -240
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +0 -185
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +0 -200
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
- package/gradle/libs.versions.toml +0 -69
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +0 -8
- package/gradle.properties +0 -24
- package/gradlew +0 -252
- package/gradlew.bat +0 -94
- package/ios-demo/README.md +0 -120
- package/scripts/sdui-visual/README.md +0 -64
- package/settings.gradle.kts +0 -64
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
// File: compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt
|
|
2
|
-
// Created At: 2026-10-29 10:30: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 org.junit.Assert.assertEquals
|
|
10
|
-
import org.junit.Assert.assertNull
|
|
11
|
-
import org.junit.Assert.assertTrue
|
|
12
|
-
import org.junit.Test
|
|
13
|
-
import java.io.File
|
|
14
|
-
|
|
15
|
-
// AI-GENERATED START: unit tests for SduiView's pure part (prepareSduiView) and structure validation
|
|
16
|
-
class SduiViewTest {
|
|
17
|
-
@Test fun errorLogLineCarriesCodeStageAndDetail() {
|
|
18
|
-
assertEquals("[SDUI] block: PARSE parse - spec is not a JSON object", errorLogLine(SduiError("parse", "PARSE", false, "spec is not a JSON object")))
|
|
19
|
-
assertEquals("[SDUI] block: UNSUPPORTED_VERSION validate", errorLogLine(SduiError("validate", "UNSUPPORTED_VERSION", false)))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private fun prep(json: String, v: Int = 1) = prepareSduiView(json, v)
|
|
23
|
-
private fun codeOf(r: SduiResult<*>) = (r as SduiResult.Err).error.code
|
|
24
|
-
private fun ok(r: SduiResult<PreparedView>) = (r as SduiResult.Ok).value
|
|
25
|
-
|
|
26
|
-
private val body = """{"type":"View","children":[{"type":"Text","props":{"children":"x"}}]}"""
|
|
27
|
-
private fun spec(meta: String = """{"screenName":"S"}""", extra: String = "") = """{"meta":$meta,"body":$body$extra}"""
|
|
28
|
-
|
|
29
|
-
// ---- error codes -----------------------------------------------------------------------------------------------
|
|
30
|
-
@Test fun tooLargeIsRejectedBeforeParsing() {
|
|
31
|
-
assertEquals(ErrorCode.PAYLOAD_TOO_LARGE, codeOf(prep(" ".repeat(MAX_PAYLOAD_BYTES + 1))))
|
|
32
|
-
// the gate counts UTF-8 bytes, not chars: 3-byte chars overflow earlier
|
|
33
|
-
assertEquals(ErrorCode.PAYLOAD_TOO_LARGE, codeOf(prep("€".repeat(MAX_PAYLOAD_BYTES / 3 + 1))))
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@Test fun invalidJsonAndNonObjectAreParseErrors() {
|
|
37
|
-
assertEquals(ErrorCode.PARSE, codeOf(prep("{")))
|
|
38
|
-
assertEquals(ErrorCode.PARSE, codeOf(prep("")))
|
|
39
|
-
assertEquals(ErrorCode.PARSE, codeOf(prep("[1,2]")))
|
|
40
|
-
assertEquals(ErrorCode.PARSE, codeOf(prep("\"str\"")))
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Test fun minRenderVersionAboveRendererIsUnsupported() {
|
|
44
|
-
assertEquals(ErrorCode.UNSUPPORTED_VERSION, codeOf(prep(spec("""{"minRenderVersion":2}"""))))
|
|
45
|
-
assertTrue(prep(spec("""{"minRenderVersion":1}""")) is SduiResult.Ok)
|
|
46
|
-
assertEquals(ErrorCode.UNSUPPORTED_VERSION, codeOf(prep(spec("""{"minRenderVersion":3}"""), v = 2)))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Test fun modeSectionOrAbsentIsOkScreenIsUnsupportedOtherIsShape() {
|
|
50
|
-
assertTrue(prep(spec("""{"mode":"section"}""")) is SduiResult.Ok)
|
|
51
|
-
assertTrue(prep(spec("""{}""")) is SduiResult.Ok)
|
|
52
|
-
assertEquals(ErrorCode.UNSUPPORTED_MODE, codeOf(prep(spec("""{"mode":"screen"}"""))))
|
|
53
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep(spec("""{"mode":"wat"}"""))))
|
|
54
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep(spec("""{"mode":5}"""))))
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
@Test fun bodyMustBeANode() {
|
|
58
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{},"body":{"children":[]}}""")))
|
|
59
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{},"body":"x"}""")))
|
|
60
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(prep("""{"meta":{}}""")))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ---- shapes ----------------------------------------------------------------------------------------------------
|
|
64
|
-
@Test fun bareSpecIsReadyWithDataAndStateSeed() {
|
|
65
|
-
val v = ok(prep("""{"meta":{"screenName":"Blk"},"data":{"a":1},"state":{"s":true},"body":$body}"""))
|
|
66
|
-
assertEquals("Blk", v.screenName)
|
|
67
|
-
assertEquals(mapOf<String, Any?>("a" to 1L), v.data)
|
|
68
|
-
assertEquals(mapOf<String, Any?>("s" to true), v.initialState)
|
|
69
|
-
assertEquals("View", v.body["type"])
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Test fun screenNameIsOptionalAndMetaMayBeAbsent() {
|
|
73
|
-
assertNull(ok(prep("""{"body":$body}""")).screenName)
|
|
74
|
-
assertTrue(ok(prep("""{"body":$body}""")).data.isEmpty())
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@Test fun envelopeShapedInputIsRejectedAsSpecShape() {
|
|
78
|
-
val events = mutableListOf<String>()
|
|
79
|
-
var errorCode: Any? = null
|
|
80
|
-
val sink = object : TrackSink {
|
|
81
|
-
override val id = "rec"
|
|
82
|
-
override fun write(record: TrackRecord) {
|
|
83
|
-
events += "${record.event.name}:${record.event.step}"
|
|
84
|
-
if (record.event.step == "sdui_error") errorCode = record.event.fields["code"]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
val tracker = Tracker(listOf(sink), "s")
|
|
88
|
-
var label: String? = "unset"
|
|
89
|
-
val r = prepareSduiView("""{"v":1,"status":"ok","spec":${spec()}}""", 1) { name -> label = name; tracker.begin(SessionCtx("sdui:view:block")) }
|
|
90
|
-
assertEquals(ErrorCode.SPEC_SHAPE, codeOf(r))
|
|
91
|
-
assertEquals(null, label) // no top-level meta: the session gets no block name
|
|
92
|
-
assertEquals(ErrorCode.SPEC_SHAPE, errorCode) // tracking reports the same code as onError
|
|
93
|
-
assertEquals(listOf("ops_info_checked:sdui_error"), events.takeLast(1))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Test fun actionTypeIsAllowedAndUnknownTypeIsNotAValidationError() {
|
|
97
|
-
val a = """{"type":"View","actions":[{"name":"onPress","type":"startFeatureCode","params":{"featureCode":"f"}},{"name":"onPress","type":"future"}]}"""
|
|
98
|
-
assertTrue(prep("""{"meta":{},"body":$a}""") is SduiResult.Ok)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@Test fun errorsAreReportedToTheSessionOnce() {
|
|
102
|
-
val events = mutableListOf<String>()
|
|
103
|
-
val sink = object : TrackSink {
|
|
104
|
-
override val id = "rec"
|
|
105
|
-
override fun write(record: TrackRecord) { events += "${record.event.name}:${record.event.step}" }
|
|
106
|
-
}
|
|
107
|
-
val tracker = Tracker(listOf(sink), "s")
|
|
108
|
-
var begun = 0
|
|
109
|
-
var session: RenderSession? = null
|
|
110
|
-
prepareSduiView("{", 1) { begun++; tracker.begin(SessionCtx("sdui:view:block")).also { session = it } }
|
|
111
|
-
assertEquals(1, begun)
|
|
112
|
-
assertEquals(listOf("ops_info_checked:sdui_error"), events)
|
|
113
|
-
session!!.mark("render_done") // the failed prepare ended the session: a late step is dropped
|
|
114
|
-
assertEquals(listOf("ops_info_checked:sdui_error"), events)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// ---- the bundled blocks must be drawable ---------------------------------------------------------------------------
|
|
118
|
-
@Test fun bundledBlocksPrepareOk() {
|
|
119
|
-
val dir = File("../sample/shared/src/commonMain/composeResources/files/sdui/blocks")
|
|
120
|
-
val files = listOf("buy_insurance", "pay_premium", "community").map { File(dir, "$it.json") }
|
|
121
|
-
files.forEach { assertTrue("missing ${it.absolutePath}", it.exists()) }
|
|
122
|
-
files.forEach { f ->
|
|
123
|
-
val r = prep(f.readText())
|
|
124
|
-
assertTrue("${f.name}: ${(r as? SduiResult.Err)?.error}", r is SduiResult.Ok)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private val goodSpec = mapOf(
|
|
129
|
-
"meta" to mapOf("screenName" to "S"),
|
|
130
|
-
"body" to mapOf("type" to "View", "children" to listOf(mapOf("type" to "Text", "props" to mapOf("children" to "x")))),
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
// ---- structure validation ----------------------------------------------------------------------------------------------
|
|
134
|
-
@Test fun structureValidationRejectsBadSpecs() {
|
|
135
|
-
assertTrue(validateStructure(goodSpec).errors.isEmpty())
|
|
136
|
-
assertTrue(validateStructure("x").errors.isNotEmpty())
|
|
137
|
-
assertTrue(validateStructure(goodSpec + ("bogus" to 1L)).errors.any { "unknown top-level key" in it })
|
|
138
|
-
// screen-level keys SduiView would silently drop are rejected
|
|
139
|
-
listOf("header", "footer", "tabs", "onMount", "actions", "overlays", "components", "tracking", "localization").forEach { k ->
|
|
140
|
-
assertTrue(k, validateStructure(goodSpec + (k to emptyMap<String, Any?>())).errors.any { "\"$k\" is not supported in a section" in it })
|
|
141
|
-
}
|
|
142
|
-
assertTrue(validateStructure(goodSpec + ("data" to emptyMap<String, Any?>()) + ("state" to emptyMap<String, Any?>()) + ("\$schema" to "x") + ("__od" to 1L)).errors.isEmpty())
|
|
143
|
-
val noType = goodSpec + ("body" to mapOf("type" to "View", "children" to listOf(mapOf("props" to emptyMap<String, Any?>()))))
|
|
144
|
-
assertTrue(validateStructure(noType).errors.any { "without a \"type\"" in it })
|
|
145
|
-
fun withAction(a: Map<String, Any?>) = goodSpec + ("body" to mapOf("type" to "View", "children" to listOf(mapOf("type" to "View", "actions" to listOf(a)))))
|
|
146
|
-
fun actionErrors(a: Map<String, Any?>) = validateStructure(withAction(a)).errors
|
|
147
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "set" to mapOf("a" to 1L))).any { "unknown field \"set\"" in it })
|
|
148
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "navigate" to "push")).any { "unknown field \"navigate\"" in it })
|
|
149
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "tab" to "t")).any { "unknown field \"tab\"" in it })
|
|
150
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "params" to mapOf("featureCode" to "f"))).any { "actions[0].type is required" in it })
|
|
151
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "type" to 5L)).any { "type is required" in it })
|
|
152
|
-
assertTrue(validateStructure(withAction(mapOf("name" to "onPress", "storage" to "get", "key" to "k", "to" to "x"))).errors.any { "unknown field" in it })
|
|
153
|
-
assertTrue(actionErrors(mapOf("name" to "onPress", "type" to "startFeatureCode", "params" to mapOf("featureCode" to "f"))).isEmpty())
|
|
154
|
-
// fields the runtime never reads
|
|
155
|
-
listOf("code", "overlay", "trackOn").forEach { k ->
|
|
156
|
-
assertTrue(k, actionErrors(mapOf("name" to "onPress", "type" to "setState", k to "x")).any { "unknown field \"$k\"" in it })
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@Test fun structureValidationChecksShapesTheRendererSilentlyIgnores() {
|
|
161
|
-
fun body(vararg kv: Pair<String, Any?>) = goodSpec + ("body" to mapOf("type" to "View", *kv))
|
|
162
|
-
fun child(vararg kv: Pair<String, Any?>) = body("children" to listOf(mapOf("type" to "View", *kv)))
|
|
163
|
-
val press = mapOf("name" to "onPress", "type" to "setState", "params" to mapOf("a" to 1L))
|
|
164
|
-
// actions must be a list
|
|
165
|
-
assertTrue(validateStructure(child("actions" to press)).errors.any { "body.children[0].actions must be a list of actions" in it })
|
|
166
|
-
assertTrue(validateStructure(body("actions" to press)).errors.any { "body.actions must be a list of actions" in it })
|
|
167
|
-
assertTrue(validateStructure(child("actions" to listOf(press))).errors.isEmpty())
|
|
168
|
-
// children must be a list of nodes
|
|
169
|
-
val textChildren = "children must be a list of nodes; put text in props.children"
|
|
170
|
-
assertTrue(validateStructure(child("children" to "hello")).errors.any { "body.children[0].$textChildren" in it })
|
|
171
|
-
assertTrue(validateStructure(body("children" to mapOf("type" to "Text"))).errors.any { "body.$textChildren" in it })
|
|
172
|
-
// repeat: `as` names the item, `item` is not read
|
|
173
|
-
val rep = mapOf("source" to "{xs}", "as" to "x", "index" to "i")
|
|
174
|
-
assertTrue(validateStructure(child("repeat" to rep)).errors.isEmpty())
|
|
175
|
-
assertTrue(validateStructure(child("repeat" to mapOf("source" to "{xs}", "item" to "x"))).errors.any { "unknown field \"item\" at body.children[0].repeat" in it })
|
|
176
|
-
// styles only: a singular `style` is unknown on nodes and on body
|
|
177
|
-
assertTrue(validateStructure(child("styles" to mapOf("flex" to 1L))).errors.isEmpty())
|
|
178
|
-
assertTrue(validateStructure(child("style" to mapOf("flex" to 1L))).errors.any { "unknown field \"style\"" in it })
|
|
179
|
-
assertTrue(validateStructure(body("style" to mapOf("flex" to 1L))).errors.any { "unknown field \"style\" at body" in it })
|
|
180
|
-
// body is drawn once, directly: repeat / visible / visibleWhen / scrollable would be silently ignored, so they are rejected there only
|
|
181
|
-
listOf("repeat" to mapOf("source" to "{xs}", "as" to "x"), "visible" to false, "visibleWhen" to "{a}").forEach { (k, v) ->
|
|
182
|
-
assertEquals(k, listOf("body.$k is not supported: the block body is always drawn once"), validateStructure(body(k to v)).errors)
|
|
183
|
-
assertTrue(k, validateStructure(child(k to v)).errors.isEmpty())
|
|
184
|
-
}
|
|
185
|
-
assertEquals(listOf("unknown field \"scrollable\" at body"), validateStructure(body("scrollable" to true)).errors)
|
|
186
|
-
// meta: stamp / autoShow are not read by SduiView; root (editor marker) / version / description are accepted and ignored
|
|
187
|
-
fun withMeta(k: String) = goodSpec + ("meta" to mapOf(k to true))
|
|
188
|
-
listOf("stamp", "autoShow").forEach { k ->
|
|
189
|
-
assertTrue(k, validateStructure(withMeta(k)).errors.any { "unknown field \"$k\" at meta" in it })
|
|
190
|
-
}
|
|
191
|
-
listOf("root", "version", "description").forEach { k -> assertTrue(k, validateStructure(withMeta(k)).errors.isEmpty()) }
|
|
192
|
-
// nesting depth: 100 levels below body pass, 101 fail with one error
|
|
193
|
-
fun nested(levels: Int): Map<String, Any?> {
|
|
194
|
-
var n: Map<String, Any?> = mapOf("type" to "View")
|
|
195
|
-
repeat(levels - 1) { n = mapOf("type" to "View", "children" to listOf(n)) }
|
|
196
|
-
return n
|
|
197
|
-
}
|
|
198
|
-
assertTrue(validateStructure(body("children" to listOf(nested(100)))).errors.isEmpty())
|
|
199
|
-
val deep = validateStructure(body("children" to listOf(nested(5000)))).errors
|
|
200
|
-
assertEquals(1, deep.count { "spec nested too deeply" in it })
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// ---- utf8Length / parse timing ---------------------------------------------------------------------------------------
|
|
204
|
-
@Test fun deeplyNestedJsonIsRejectedBeforeParsing() {
|
|
205
|
-
assertEquals(3, jsonNestingDepth("""{"a":[{"b":1}]}"""))
|
|
206
|
-
assertEquals(1, jsonNestingDepth("""{"a":"[[[{{{\"]]]"}""")) // brackets inside strings (and escaped quotes) don't count
|
|
207
|
-
assertEquals(0, jsonNestingDepth("""]]]}}"""))
|
|
208
|
-
// 120k levels fits the size gate but would overflow the parser's stack (fatal on iOS): rejected as PARSE without parsing
|
|
209
|
-
val deep = "[".repeat(120_000) + "]".repeat(120_000)
|
|
210
|
-
assertEquals(ErrorCode.PARSE, codeOf(prep(deep)))
|
|
211
|
-
val ok = """{"meta":{},"body":{"type":"View","props":{"d":""" + "[".repeat(200) + "]".repeat(200) + "}}}"
|
|
212
|
-
assertTrue(prep(ok) is SduiResult.Ok)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
@Test fun utf8LengthMatchesEncodeToByteArray() {
|
|
216
|
-
val cases = listOf("", "plain ascii {\"a\":1}", "Phí bảo hiểm sức khỏe Việt Nam đ", "emoji \uD83D\uDE00 \uD83C\uDDFB\uD83C\uDDF3 end", "中文 \u20AC")
|
|
217
|
-
cases.forEach { assertEquals(it, it.encodeToByteArray().size, utf8Length(it)) }
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// An unpaired surrogate counts 3 bytes (U+FFFD, what Kotlin/Native's encoder writes); the JVM encoder writes 1 ('?').
|
|
221
|
-
@Test fun utf8LengthCountsAnUnpairedSurrogateAsThree() {
|
|
222
|
-
assertEquals(3, utf8Length("\uD83D")); assertEquals(3, utf8Length("\uDE00"))
|
|
223
|
-
assertEquals(3 + 1, utf8Length("\uD83Dx")); assertEquals(3 + 3, utf8Length("\uDE00\uD83D"))
|
|
224
|
-
assertEquals(4, utf8Length("\uD83D\uDE00"))
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
@Test fun parseDurationIsMeasuredAroundParsingAndPassedToTheSession() {
|
|
228
|
-
var t = 100L
|
|
229
|
-
val clock = { val v = t; t += 7; v }
|
|
230
|
-
val marks = ArrayList<Triple<String, Map<String, Any?>?, Long?>>()
|
|
231
|
-
val rec = object : RenderSession by RenderSession.NOOP {
|
|
232
|
-
override fun mark(step: String, extra: Map<String, Any?>?, durationMs: Long?) { marks += Triple(step, extra, durationMs) }
|
|
233
|
-
}
|
|
234
|
-
val r = prepareSduiView(spec(), 1, nowMs = clock) { rec }
|
|
235
|
-
assertTrue(r is SduiResult.Ok)
|
|
236
|
-
val parse = marks.single { it.first == "sdui_parse" }
|
|
237
|
-
assertEquals(7L, parse.third)
|
|
238
|
-
assertEquals(true, parse.second!!["ok"])
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
@Test fun realSessionUsesTheSuppliedParseDuration() {
|
|
242
|
-
val sink = object : TrackSink {
|
|
243
|
-
override val id = "rec"
|
|
244
|
-
val records = ArrayList<TrackRecord>()
|
|
245
|
-
override fun write(record: TrackRecord) { records += record }
|
|
246
|
-
}
|
|
247
|
-
val s = Tracker(listOf(sink), "sess").begin(SessionCtx("sdui:view:t"))
|
|
248
|
-
s.mark("sdui_parse", mapOf("ok" to true), durationMs = 42L)
|
|
249
|
-
assertEquals(42L, sink.records.single().event.fields["duration"])
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
// AI-GENERATED END: unit tests for SduiView's pure part
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.application
|
|
2
|
-
|
|
3
|
-
import androidx.compose.runtime.Immutable
|
|
4
|
-
import androidx.compose.runtime.staticCompositionLocalOf
|
|
5
|
-
import vn.momo.kits.components.TrustBannerData
|
|
6
|
-
|
|
7
|
-
@Immutable
|
|
8
|
-
data class FeatureFlags(
|
|
9
|
-
val showBaseLineDebug: Boolean? = false,
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
@Immutable
|
|
13
|
-
data class DesignSystemConfig(
|
|
14
|
-
val trustBanner: TrustBannerData? = null,
|
|
15
|
-
val headerBar: String? = null,
|
|
16
|
-
val headerGradient: String? = null,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
@Immutable
|
|
20
|
-
data class MiniAppContext(
|
|
21
|
-
val appIcon: String = "",
|
|
22
|
-
val appName: Any? = null,
|
|
23
|
-
val appId: String = "",
|
|
24
|
-
val appCode: String = "",
|
|
25
|
-
val description: Any? = null,
|
|
26
|
-
val support: Map<String, Any?> = emptyMap(),
|
|
27
|
-
val toolkitConfig: Map<String, Any?> = emptyMap(),
|
|
28
|
-
val providerId: String = "",
|
|
29
|
-
val permissions: List<Map<String, Any>>? = emptyList(),
|
|
30
|
-
val features: FeatureFlags? = null,
|
|
31
|
-
val scaleSizeMaxRate: Float? = null,
|
|
32
|
-
val userScaleRate: Float? = null,
|
|
33
|
-
val useOSScaleRate: Boolean? = null,
|
|
34
|
-
) {
|
|
35
|
-
companion object {
|
|
36
|
-
|
|
37
|
-
fun toMap(context: MiniAppContext?): Map<String, Any?> = mapOf(
|
|
38
|
-
"icon" to (context?.appIcon ?: ""),
|
|
39
|
-
"name" to context?.appName,
|
|
40
|
-
"appId" to (context?.appId ?: ""),
|
|
41
|
-
"code" to (context?.appCode ?: ""),
|
|
42
|
-
"description" to (context?.description ?: ""),
|
|
43
|
-
"support" to (context?.support ?: emptyMap()),
|
|
44
|
-
"toolkitConfig" to (context?.toolkitConfig ?: emptyMap()),
|
|
45
|
-
"providerId" to (context?.providerId ?: ""),
|
|
46
|
-
"permissions" to (context?.permissions ?: emptyList()),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
fun merge(parent: MiniAppContext?, child: MiniAppContext?): MiniAppContext? {
|
|
50
|
-
if (parent == null && child == null) return null
|
|
51
|
-
if (parent == null) return child
|
|
52
|
-
if (child == null) return parent
|
|
53
|
-
|
|
54
|
-
return MiniAppContext(
|
|
55
|
-
appIcon = parent.appIcon.ifBlank { child.appIcon },
|
|
56
|
-
appName = parent.appName ?: child.appName,
|
|
57
|
-
appId = parent.appId.ifBlank { child.appId },
|
|
58
|
-
appCode = parent.appCode.ifBlank { child.appCode },
|
|
59
|
-
description = parent.description ?: child.description,
|
|
60
|
-
support = mergeMaps(parent.support, child.support),
|
|
61
|
-
toolkitConfig = mergeMaps(parent.toolkitConfig, child.toolkitConfig),
|
|
62
|
-
providerId = parent.providerId.ifBlank { child.providerId },
|
|
63
|
-
permissions = if (!parent.permissions.isNullOrEmpty()) parent.permissions else child.permissions,
|
|
64
|
-
features = mergeFeatureFlags(parent.features, child.features),
|
|
65
|
-
scaleSizeMaxRate = parent.scaleSizeMaxRate ?: child.scaleSizeMaxRate,
|
|
66
|
-
userScaleRate = parent.userScaleRate ?: child.userScaleRate,
|
|
67
|
-
useOSScaleRate = parent.useOSScaleRate ?: child.useOSScaleRate,
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private fun mergeMaps(parent: Map<String, Any?>, child: Map<String, Any?>): Map<String, Any?> {
|
|
72
|
-
return child + parent
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private fun mergeFeatureFlags(parent: FeatureFlags?, child: FeatureFlags?): FeatureFlags? {
|
|
76
|
-
if (parent == null && child == null) return null
|
|
77
|
-
if (parent == null) return child
|
|
78
|
-
if (child == null) return parent
|
|
79
|
-
|
|
80
|
-
return FeatureFlags(
|
|
81
|
-
showBaseLineDebug = parent.showBaseLineDebug ?: child.showBaseLineDebug
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@Immutable
|
|
88
|
-
data class ComponentInformation(
|
|
89
|
-
val componentName: String? = null,
|
|
90
|
-
val componentId: String? = null,
|
|
91
|
-
val params: Map<String,Any?>? = null,
|
|
92
|
-
val action: String? = null
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
var IsShowBaseLineDebug = false
|
|
96
|
-
|
|
97
|
-
val LocalContext = staticCompositionLocalOf<MiniAppContext?> {
|
|
98
|
-
null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
val LocalComponentInformation = staticCompositionLocalOf<ComponentInformation?> {
|
|
102
|
-
null
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
val LocalDesignSystemConfig = staticCompositionLocalOf<DesignSystemConfig?> {
|
|
106
|
-
null
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Deprecated("No longer read; wrap content in ScaleSizeScope(scaleSizeMaxRate) to cap the font scale.")
|
|
110
|
-
val ScaleSizeMaxRate = staticCompositionLocalOf<Float?> { null }
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.application
|
|
2
|
-
|
|
3
|
-
import androidx.compose.runtime.Immutable
|
|
4
|
-
import androidx.compose.runtime.getValue
|
|
5
|
-
import androidx.compose.runtime.mutableStateOf
|
|
6
|
-
import androidx.compose.runtime.setValue
|
|
7
|
-
import kotlinx.coroutines.CoroutineScope
|
|
8
|
-
import kotlinx.coroutines.Dispatchers
|
|
9
|
-
import kotlinx.coroutines.Job
|
|
10
|
-
import kotlinx.coroutines.SupervisorJob
|
|
11
|
-
import kotlinx.coroutines.flow.Flow
|
|
12
|
-
import kotlinx.coroutines.flow.MutableStateFlow
|
|
13
|
-
import kotlinx.coroutines.flow.StateFlow
|
|
14
|
-
import kotlinx.coroutines.flow.asStateFlow
|
|
15
|
-
import kotlinx.coroutines.launch
|
|
16
|
-
|
|
17
|
-
@Immutable
|
|
18
|
-
data class DesignSystemKitsConfigs(
|
|
19
|
-
val userScaleRate: Float = 1f,
|
|
20
|
-
val useOSScaleRate: Boolean = true,
|
|
21
|
-
val isWhiteList: Boolean = false,
|
|
22
|
-
val designSystemConfig: DesignSystemConfig? = null,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
// The kit is sandboxed from the host's storage/config, so the host implements this and hands it to init().
|
|
26
|
-
interface DesignSystemKitsSource {
|
|
27
|
-
// Sync read: seeds the kit before the first frame, so there is no default-then-real flicker.
|
|
28
|
-
fun getConfigs(): DesignSystemKitsConfigs
|
|
29
|
-
|
|
30
|
-
val configsFlow: Flow<DesignSystemKitsConfigs>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// App-wide design-system inputs (font scale, whitelist, remote config). scaleSize(), defaultTheme and
|
|
34
|
-
// NavigationContainer fall back to these when no MiniAppContext / LocalDesignSystemConfig is provided.
|
|
35
|
-
object DesignSystemKits {
|
|
36
|
-
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
37
|
-
private var observeJob: Job? = null
|
|
38
|
-
|
|
39
|
-
// Snapshot state recomposes Compose readers; the StateFlow serves non-Compose observers (the host
|
|
40
|
-
// SwiftUI bridge), where Compose's global snapshot apply loop may never have started.
|
|
41
|
-
private var currentConfigs by mutableStateOf(DesignSystemKitsConfigs())
|
|
42
|
-
private val mutableConfigsFlow = MutableStateFlow(currentConfigs)
|
|
43
|
-
val configsFlow: StateFlow<DesignSystemKitsConfigs> = mutableConfigsFlow.asStateFlow()
|
|
44
|
-
|
|
45
|
-
// Idempotent: a repeated call (e.g. Activity re-creation) replaces the previous observer.
|
|
46
|
-
fun init(source: DesignSystemKitsSource) {
|
|
47
|
-
observeJob?.cancel()
|
|
48
|
-
setConfigs(source.getConfigs())
|
|
49
|
-
observeJob = scope.launch {
|
|
50
|
-
source.configsFlow.collect { setConfigs(it) }
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// While init() is observing a source, its next emission overrides a value set here.
|
|
55
|
-
fun setConfigs(configs: DesignSystemKitsConfigs) {
|
|
56
|
-
currentConfigs = configs
|
|
57
|
-
mutableConfigsFlow.value = configs
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fun getConfigs(): DesignSystemKitsConfigs = currentConfigs
|
|
61
|
-
}
|