@momo-kits/native-kits 0.169.13-beta.4 → 0.169.13-beta.4-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.
Files changed (164) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +202 -0
  3. package/compose/compose.podspec +47 -0
  4. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
  11. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +647 -0
  12. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +1411 -0
  13. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +130 -0
  14. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +524 -0
  15. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +559 -0
  16. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +741 -0
  17. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +221 -0
  18. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +270 -0
  19. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +849 -0
  20. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +212 -0
  21. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +239 -0
  22. package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +252 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  126. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
  127. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
  128. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
  129. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
  130. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  131. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
  132. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +154 -0
  133. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +1038 -0
  134. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +848 -0
  135. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +47 -0
  136. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +39 -0
  137. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +463 -0
  138. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +1146 -0
  139. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +667 -0
  140. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +240 -0
  141. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +185 -0
  142. package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +200 -0
  143. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  144. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  145. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  146. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
  147. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
  148. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
  149. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  150. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
  151. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
  152. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
  153. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  154. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
  155. package/gradle/libs.versions.toml +69 -0
  156. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  157. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  158. package/gradle.properties +24 -0
  159. package/gradlew +252 -0
  160. package/gradlew.bat +94 -0
  161. package/ios-demo/README.md +120 -0
  162. package/package.json +1 -1
  163. package/scripts/sdui-visual/README.md +64 -0
  164. package/settings.gradle.kts +64 -0
@@ -0,0 +1,1067 @@
1
+ package vn.momo.kits.application
2
+
3
+ import androidx.annotation.FloatRange
4
+ import androidx.compose.foundation.ScrollState
5
+ import androidx.compose.foundation.background
6
+ import androidx.compose.foundation.border
7
+ import androidx.compose.foundation.gestures.detectTapGestures
8
+ import androidx.compose.foundation.interaction.FocusInteraction
9
+ import androidx.compose.foundation.interaction.MutableInteractionSource
10
+ import androidx.compose.foundation.layout.Arrangement
11
+ import androidx.compose.foundation.layout.Box
12
+ import androidx.compose.foundation.layout.Row
13
+ import androidx.compose.foundation.layout.fillMaxSize
14
+ import androidx.compose.foundation.layout.padding
15
+ import androidx.compose.foundation.layout.size
16
+ import androidx.compose.foundation.rememberScrollState
17
+ import androidx.compose.foundation.shape.CircleShape
18
+ import androidx.compose.foundation.text.BasicTextField
19
+ import androidx.compose.foundation.text.KeyboardActions
20
+ import androidx.compose.foundation.text.KeyboardOptions
21
+ import androidx.compose.foundation.verticalScroll
22
+ import androidx.compose.runtime.Composable
23
+ import androidx.compose.runtime.CompositionLocalProvider
24
+ import androidx.compose.runtime.LaunchedEffect
25
+ import androidx.compose.runtime.MutableState
26
+ import androidx.compose.runtime.Stable
27
+ import androidx.compose.runtime.State
28
+ import androidx.compose.runtime.derivedStateOf
29
+ import androidx.compose.runtime.getValue
30
+ import androidx.compose.runtime.mutableStateOf
31
+ import androidx.compose.runtime.remember
32
+ import androidx.compose.runtime.rememberUpdatedState
33
+ import androidx.compose.runtime.staticCompositionLocalOf
34
+ import androidx.compose.ui.Alignment
35
+ import androidx.compose.ui.Modifier
36
+ import androidx.compose.ui.composed
37
+ import androidx.compose.ui.draw.clip
38
+ import androidx.compose.ui.draw.drawWithCache
39
+ import androidx.compose.ui.draw.drawWithContent
40
+ import androidx.compose.ui.geometry.Offset
41
+ import androidx.compose.ui.geometry.Rect
42
+ import androidx.compose.ui.graphics.Brush
43
+ import androidx.compose.ui.graphics.Color
44
+ import androidx.compose.ui.graphics.SolidColor
45
+ import androidx.compose.ui.graphics.graphicsLayer
46
+ import androidx.compose.ui.input.pointer.pointerInput
47
+ import androidx.compose.ui.layout.Layout
48
+ import androidx.compose.ui.layout.Measurable
49
+ import androidx.compose.ui.layout.MeasurePolicy
50
+ import androidx.compose.ui.layout.MeasureResult
51
+ import androidx.compose.ui.layout.MeasureScope
52
+ import androidx.compose.ui.layout.Placeable
53
+ import androidx.compose.ui.layout.layoutId
54
+ import androidx.compose.ui.platform.LocalDensity
55
+ import androidx.compose.ui.platform.LocalFocusManager
56
+ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
57
+ import androidx.compose.ui.text.TextStyle
58
+ import androidx.compose.ui.text.style.TextOverflow
59
+ import androidx.compose.ui.unit.Constraints
60
+ import androidx.compose.ui.unit.Dp
61
+ import androidx.compose.ui.unit.IntOffset
62
+ import androidx.compose.ui.unit.LayoutDirection
63
+ import androidx.compose.ui.unit.dp
64
+ import androidx.compose.ui.unit.lerp
65
+ import androidx.compose.ui.unit.sp
66
+ import kotlinx.coroutines.flow.collectLatest
67
+ import kotlinx.coroutines.flow.mapNotNull
68
+ import vn.momo.kits.components.Icon
69
+ import vn.momo.kits.components.Text
70
+ import vn.momo.kits.const.AppTheme
71
+ import vn.momo.kits.const.Colors
72
+ import vn.momo.kits.const.Spacing
73
+ import vn.momo.kits.const.Typography
74
+ import vn.momo.kits.const.getFontFamily
75
+ import vn.momo.kits.layout.DuoMetrics
76
+ import vn.momo.kits.layout.ScreenLayout
77
+ import vn.momo.kits.layout.SideBarEdge
78
+ import vn.momo.kits.layout.getScreenLayout
79
+ import vn.momo.kits.modifier.hideKeyboardOnTap
80
+ import vn.momo.kits.utils.horizontalSafeAreaPadding
81
+ import vn.momo.kits.modifier.kitsAutomationId
82
+ import vn.momo.kits.modifier.noFeedbackClickable
83
+ import vn.momo.kits.modifier.setAutomationId
84
+ import vn.momo.kits.navigation.component.headerFontFamily
85
+ import vn.momo.kits.navigation.component.HEADER_HEIGHT
86
+ import vn.momo.kits.navigation.component.HeaderColor
87
+ import vn.momo.kits.navigation.component.LocalHeaderColor
88
+ import vn.momo.kits.navigation.component.HeaderRight
89
+ import vn.momo.kits.navigation.component.SideBarButton
90
+ import vn.momo.kits.navigation.component.TitlePosition
91
+ import vn.momo.kits.navigation.component.ToolGroup
92
+ import vn.momo.kits.navigation.component.Toolkit
93
+ import vn.momo.kits.utils.getAppStatusBarHeight
94
+ import kotlin.math.max
95
+ import kotlin.math.roundToInt
96
+ import vn.momo.kits.navigation.component.getHeaderColor as getNavigationHeaderColor
97
+
98
+
99
+ data class AnimationOption(
100
+ val targetBounds: Rect,
101
+ val progress: State<Float>,
102
+ @param:FloatRange(from = 0.0, to = 1.0)
103
+ val opacityLimitFraction: Float = 0f,
104
+ ) {
105
+ val opacityCap: Float
106
+ get() = 1f - opacityLimitFraction
107
+
108
+ val animateOpacity: Float
109
+ get() {
110
+ if (progress.value < opacityLimitFraction) return 0f
111
+ return androidx.compose.ui.util.lerp(
112
+ 0f,
113
+ 1f,
114
+ (progress.value - opacityLimitFraction) / (opacityCap),
115
+ )
116
+ }
117
+ }
118
+
119
+ val LocalAnimationOption = staticCompositionLocalOf<AnimationOption?> { null }
120
+
121
+ // LiteScreen's own header kinds; StackScreen uses the sealed navigation.component.HeaderType.
122
+ enum class HeaderType {
123
+ DEFAULT,
124
+ EXTENDED,
125
+ NONE
126
+ }
127
+
128
+ @Stable
129
+ data class HeaderRightData(
130
+ val useShortcut: Boolean = false,
131
+ val useMore: Boolean = false,
132
+ val useSystemTools: Boolean = true,
133
+ val tools: List<ToolGroup> = emptyList(),
134
+ val toolCallback: ((String) -> Unit)? = { _ -> }
135
+ ) {
136
+ internal fun toToolkit() = HeaderRight.Toolkit(
137
+ useShortcut = useShortcut,
138
+ useMore = useMore,
139
+ useSystemTools = useSystemTools,
140
+ tools = tools,
141
+ toolCallback = toolCallback,
142
+ )
143
+ }
144
+
145
+ @Composable
146
+ fun LiteScreen(
147
+ scrollable: Boolean = true,
148
+ scrollState: ScrollState? = null,
149
+ headerType: HeaderType = HeaderType.DEFAULT,
150
+ verticalArrangement: Arrangement.Vertical = Arrangement.Top,
151
+ horizontalAlignment: Alignment.Horizontal = Alignment.Start,
152
+ backgroundColor: Color = AppTheme.current.colors.background.default,
153
+ title: String? = null,
154
+ inputSearchProps: LiteInputSearchProps? = null,
155
+ goBack: (() -> Unit)? = null,
156
+ headerRight: @Composable (() -> Unit)? = null,
157
+ useAnimationSearch: Boolean = true,
158
+ titlePosition: TitlePosition = TitlePosition.LEFT,
159
+ headerRightData: HeaderRightData? = null,
160
+ headerTintColor: Color? = null,
161
+ headerBackgroundColor: Color? = null,
162
+ headerSpaceBetween: Dp? = null,
163
+
164
+ screenContent: @Composable () -> Unit,
165
+ ) {
166
+ val content by rememberUpdatedState(screenContent)
167
+
168
+ val finalScrollState = scrollState ?: rememberScrollState()
169
+
170
+ val contentModifier = remember(
171
+ key1 = scrollable,
172
+ key2 = finalScrollState,
173
+ ) {
174
+ var res: Modifier = Modifier
175
+ .background(color = backgroundColor)
176
+ if (scrollable) {
177
+ res = res.verticalScroll(finalScrollState)
178
+ }
179
+ res
180
+ }
181
+
182
+ LiteScreenLayout(
183
+ scrollState = finalScrollState,
184
+ modifier = Modifier
185
+ .fillMaxSize()
186
+ .hideKeyboardOnTap(),
187
+ contentModifier = contentModifier,
188
+ verticalArrangement = verticalArrangement,
189
+ horizontalAlignment = horizontalAlignment,
190
+ title = title,
191
+ headerRight = headerRight,
192
+ headerType = headerType,
193
+ onGoBack = goBack,
194
+ inputSearchProps = inputSearchProps,
195
+ titlePosition = titlePosition,
196
+ useAnimationSearch = useAnimationSearch,
197
+ headerRightData = headerRightData,
198
+ tintColor = headerTintColor,
199
+ headerBackgroundColor = headerBackgroundColor,
200
+ headerSpaceBetween = headerSpaceBetween,
201
+ ) {
202
+ content()
203
+ }
204
+ }
205
+
206
+ private object HeaderId {
207
+ private const val PACKAGE_NAME = "vn.momo.compose.kits"
208
+ const val CONTENT_ID = "${PACKAGE_NAME}.content"
209
+ const val BACKGROUND_ID = "${PACKAGE_NAME}.background"
210
+ const val BACK_ID = "${PACKAGE_NAME}.back"
211
+ const val HEADER_RIGHT_ID = "${PACKAGE_NAME}.headerRight"
212
+ const val INPUT_SEARCH_ID = "${PACKAGE_NAME}.inputSearch"
213
+ const val TITLE_ID = "${PACKAGE_NAME}.title"
214
+
215
+ val EXTENDED_HEADER_HEIGHT = 154.dp
216
+ }
217
+
218
+ @Composable
219
+ private fun LiteScreenLayout(
220
+ scrollState: ScrollState?,
221
+ modifier: Modifier = Modifier,
222
+ contentModifier: Modifier = Modifier,
223
+ verticalArrangement: Arrangement.Vertical = Arrangement.Top,
224
+ horizontalAlignment: Alignment.Horizontal = Alignment.Start,
225
+ title: String? = null,
226
+ tintColor: Color? = null,
227
+ headerRightData: HeaderRightData? = null,
228
+ headerType: HeaderType = HeaderType.DEFAULT,
229
+ titlePosition: TitlePosition = TitlePosition.LEFT,
230
+ useAnimationSearch: Boolean = true,
231
+ onGoBack: (() -> Unit)? = null,
232
+ headerBackgroundColor: Color? = null,
233
+ headerSpaceBetween: Dp? = null,
234
+ inputSearchProps: LiteInputSearchProps? = null,
235
+ headerRight: @Composable (() -> Unit)? = null,
236
+ content: @Composable () -> Unit,
237
+ ) {
238
+ val statusBarHeight = getAppStatusBarHeight()
239
+ val screenLayout = getScreenLayout()
240
+ val applySafeAreaPadding = screenLayout.sideBar != null
241
+ val isHeaderNone = remember(headerType) {
242
+ headerType == HeaderType.NONE
243
+ }
244
+ val theme = AppTheme.current
245
+ val density = LocalDensity.current
246
+
247
+ val isHeaderExtend = remember(headerType) {
248
+ headerType == HeaderType.EXTENDED
249
+ }
250
+ val backgroundHeight = remember(isHeaderNone, isHeaderExtend, statusBarHeight) {
251
+ when {
252
+ isHeaderNone -> statusBarHeight
253
+ !isHeaderExtend -> statusBarHeight + HEADER_HEIGHT.dp
254
+ else -> HeaderId.EXTENDED_HEADER_HEIGHT
255
+ }
256
+ }
257
+ val listGradientColors = remember {
258
+ listOf(
259
+ Color(0xFFFDCADE),
260
+ Color(0x00FDCADE),
261
+ )
262
+ }
263
+
264
+ val headerColor = remember(tintColor, theme) {
265
+ if (tintColor == Colors.black_01) HeaderColor(
266
+ tintIconColor = tintColor,
267
+ backgroundButton = Colors.black_20.copy(alpha = 0.6f),
268
+ borderColor = Colors.black_01.copy(alpha = 0.2f)
269
+ )
270
+ else HeaderColor(
271
+ tintIconColor = tintColor ?: theme.colors.text.default,
272
+ backgroundButton = Colors.black_01.copy(alpha = 0.6f),
273
+ borderColor = Colors.black_20.copy(alpha = 0.2f)
274
+ )
275
+ }
276
+ val toolkit = remember(headerRightData) { (headerRightData ?: HeaderRightData()).toToolkit() }
277
+
278
+ val scrollPercentage = remember(useAnimationSearch, scrollState, backgroundHeight, density) {
279
+ derivedStateOf {
280
+ if (!useAnimationSearch || scrollState == null) {
281
+ 0f
282
+ } else {
283
+ val rangePx = with(density) { backgroundHeight.toPx() }
284
+ (scrollState.value / rangePx).coerceIn(0f, 1f)
285
+ }
286
+ }
287
+ }
288
+
289
+ val titleStyle = remember {
290
+ Typography.actionSBold.copy(
291
+ fontSize = 15.sp,
292
+ lineHeight = 22.sp,
293
+ )
294
+ }
295
+
296
+ val animationOption = LocalAnimationOption.current
297
+ val animationOpacityModifier = Modifier.graphicsLayer {
298
+ alpha = animationOption?.animateOpacity ?: 1f
299
+ }
300
+ val sideBarColor = getNavigationHeaderColor(
301
+ vn.momo.kits.navigation.component.HeaderType.Default(),
302
+ 1f,
303
+ null,
304
+ Colors.black_17,
305
+ )
306
+ val titleModifier = Modifier
307
+ .kitsAutomationId("title_navigation_header")
308
+ .layoutId(HeaderId.TITLE_ID)
309
+ .graphicsLayer {
310
+ val titleAlpha = if (isHeaderExtend && inputSearchProps != null && useAnimationSearch)
311
+ (1 - scrollPercentage.value * 2).coerceIn(0f, 1f)
312
+ else 1f
313
+ alpha = titleAlpha * (animationOption?.progress?.value ?: 1f)
314
+ }
315
+
316
+ val policy = remember(
317
+ screenLayout,
318
+ applySafeAreaPadding,
319
+ useAnimationSearch,
320
+ isHeaderNone,
321
+ isHeaderExtend,
322
+ statusBarHeight,
323
+ titlePosition,
324
+ scrollPercentage,
325
+ headerSpaceBetween,
326
+ animationOption,
327
+ verticalArrangement,
328
+ horizontalAlignment,
329
+ ) {
330
+ LiteScreenLayoutPolicy(
331
+ screenLayout = screenLayout,
332
+ applySafeAreaPadding = applySafeAreaPadding,
333
+ useAnimationSearch = useAnimationSearch,
334
+ isHeaderNone = isHeaderNone,
335
+ isHeaderExtend = isHeaderExtend,
336
+ statusBarHeight = statusBarHeight,
337
+ titlePosition = titlePosition,
338
+ scrollPercentage = scrollPercentage,
339
+ headerSpaceBetween = headerSpaceBetween,
340
+ animationOption = animationOption,
341
+ verticalArrangement = verticalArrangement,
342
+ horizontalAlignment = horizontalAlignment,
343
+ )
344
+ }
345
+
346
+ Layout(
347
+ modifier = modifier,
348
+ content = {
349
+ Box(
350
+ modifier = animationOpacityModifier
351
+ .layoutId(HeaderId.CONTENT_ID)
352
+ .then(contentModifier)
353
+ .then(if (applySafeAreaPadding) Modifier.horizontalSafeAreaPadding() else Modifier),
354
+ contentAlignment = Alignment.TopCenter,
355
+ ) {
356
+ content()
357
+ }
358
+
359
+ if (!isHeaderNone) {
360
+ Box(
361
+ modifier = Modifier
362
+ .layoutId(HeaderId.BACKGROUND_ID)
363
+ .then(animationOpacityModifier)
364
+ .drawWithCache {
365
+ if (headerBackgroundColor != null) {
366
+ val backgroundColor = headerBackgroundColor
367
+ onDrawBehind { drawRect(color = backgroundColor) }
368
+ } else {
369
+ val headerHeight = max(
370
+ HeaderId.EXTENDED_HEADER_HEIGHT.toPx(),
371
+ size.height,
372
+ )
373
+ val gradientBrush = Brush.linearGradient(
374
+ colors = listGradientColors,
375
+ start = Offset.Zero,
376
+ end = Offset(
377
+ x = 0f,
378
+ y = headerHeight * (1 - scrollPercentage.value),
379
+ ),
380
+ )
381
+ onDrawBehind {
382
+ drawRect(color = Colors.black_01)
383
+ drawRect(brush = gradientBrush)
384
+ }
385
+ }
386
+ },
387
+ )
388
+ }
389
+
390
+ if (!isHeaderNone && onGoBack != null) {
391
+ when {
392
+ screenLayout.sideBar != null || screenLayout.statusBarClearance != null -> {
393
+ Box(
394
+ modifier = Modifier.layoutId(HeaderId.BACK_ID),
395
+ ) {
396
+ SideBarButton(
397
+ icon = "arrow-back",
398
+ headerColor = sideBarColor,
399
+ onClick = onGoBack,
400
+ automationId = "btn_navigation_back",
401
+ )
402
+ }
403
+ }
404
+ else -> {
405
+ val coreModifier = Modifier
406
+ .layoutId(HeaderId.BACK_ID)
407
+ .then(animationOpacityModifier)
408
+ .clip(CircleShape)
409
+ .noFeedbackClickable(onClick = onGoBack)
410
+ .setAutomationId("btn_navigation_back")
411
+ inputSearchProps?.customBackIcon?.invoke(coreModifier) ?: Box(
412
+ modifier = coreModifier
413
+ .size(28.dp)
414
+ .border(
415
+ width = 0.2.dp,
416
+ color = headerColor.borderColor,
417
+ shape = CircleShape,
418
+ )
419
+ .background(color = headerColor.backgroundButton)
420
+ .padding(Spacing.XS),
421
+ ) {
422
+ Icon(
423
+ source = "arrow-back",
424
+ color = headerColor.tintIconColor,
425
+ size = 20.dp,
426
+ )
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ if (!isHeaderNone) {
433
+ Box(
434
+ modifier = Modifier
435
+ .layoutId(HeaderId.HEADER_RIGHT_ID)
436
+ .then(animationOpacityModifier)
437
+ ) {
438
+ if (headerRight != null) {
439
+ CompositionLocalProvider(LocalHeaderColor provides headerColor) {
440
+ headerRight()
441
+ }
442
+ } else {
443
+ Toolkit(
444
+ headerRight = toolkit,
445
+ tintColor = tintColor,
446
+ headerColor = headerColor,
447
+ )
448
+ }
449
+ }
450
+ }
451
+
452
+ if (!isHeaderNone && inputSearchProps != null) {
453
+ LiteInputSearch(
454
+ modifier = Modifier.layoutId(HeaderId.INPUT_SEARCH_ID),
455
+ inputSearchProps = inputSearchProps,
456
+ )
457
+ }
458
+ if (!isHeaderNone && title != null && (inputSearchProps == null || isHeaderExtend)) {
459
+ Text(
460
+ text = title,
461
+ color = headerColor.tintIconColor,
462
+ style = titleStyle,
463
+ fontFamily = headerFontFamily,
464
+ modifier = titleModifier,
465
+ maxLines = 1,
466
+ overflow = TextOverflow.Ellipsis
467
+ )
468
+ }
469
+ },
470
+ measurePolicy = policy,
471
+ )
472
+ }
473
+
474
+ private interface LiteScreenGeometry {
475
+ fun MeasureScope.safeWidth(
476
+ screenLayout: ScreenLayout,
477
+ width: Int,
478
+ insetLeft: Int,
479
+ insetRight: Int,
480
+ ): Int
481
+
482
+ fun MeasureScope.searchStartX(
483
+ screenLayout: ScreenLayout,
484
+ insetLeft: Int,
485
+ spacing: Int,
486
+ ): Int
487
+
488
+ fun MeasureScope.headerHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int): Int
489
+ fun MeasureScope.headerRightStartX(
490
+ screenLayout: ScreenLayout,
491
+ width: Int,
492
+ insetRight: Int,
493
+ spacing: Int,
494
+ rightWidth: Int,
495
+ ): Int
496
+
497
+ fun MeasureScope.collapsedHeaderHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int): Int
498
+
499
+ fun MeasureScope.searchStartY(
500
+ screenLayout: ScreenLayout,
501
+ headerY: Int,
502
+ statusBar: Int,
503
+ rowHeight: Int,
504
+ ): Int
505
+ }
506
+
507
+ private class StandardPhoneLiteScreenGeometry : LiteScreenGeometry {
508
+ override fun MeasureScope.safeWidth(
509
+ screenLayout: ScreenLayout,
510
+ width: Int,
511
+ insetLeft: Int,
512
+ insetRight: Int,
513
+ ) = (width - insetLeft - insetRight).coerceAtLeast(0)
514
+
515
+ override fun MeasureScope.searchStartX(screenLayout: ScreenLayout, insetLeft: Int, spacing: Int): Int {
516
+ return insetLeft + spacing
517
+ }
518
+
519
+ override fun MeasureScope.headerHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int): Int {
520
+ return statusBar + rowHeight
521
+ }
522
+ override fun MeasureScope.collapsedHeaderHeight(
523
+ screenLayout: ScreenLayout,
524
+ statusBar: Int,
525
+ rowHeight: Int,
526
+ ) = statusBar + rowHeight
527
+ override fun MeasureScope.headerRightStartX(
528
+ screenLayout: ScreenLayout,
529
+ width: Int,
530
+ insetRight: Int,
531
+ spacing: Int,
532
+ rightWidth: Int,
533
+ ) = width - insetRight - spacing - rightWidth
534
+
535
+ override fun MeasureScope.searchStartY(
536
+ screenLayout: ScreenLayout,
537
+ headerY: Int,
538
+ statusBar: Int,
539
+ rowHeight: Int,
540
+ ) = headerY + statusBar
541
+ }
542
+
543
+ private class IPhoneDuoLiteScreenGeometry : LiteScreenGeometry {
544
+ override fun MeasureScope.safeWidth(
545
+ screenLayout: ScreenLayout,
546
+ width: Int,
547
+ insetLeft: Int,
548
+ insetRight: Int,
549
+ ): Int {
550
+ val clearance = screenLayout.statusBarClearance
551
+ return (
552
+ width - insetLeft - insetRight -
553
+ (clearance?.left?.roundToPx() ?: 0) -
554
+ (clearance?.right?.roundToPx() ?: 0)
555
+ ).coerceAtLeast(0)
556
+ }
557
+
558
+ override fun MeasureScope.searchStartX(screenLayout: ScreenLayout, insetLeft: Int, spacing: Int): Int {
559
+ return insetLeft + (screenLayout.statusBarClearance?.left?.roundToPx() ?: 0) + spacing
560
+ }
561
+
562
+ override fun MeasureScope.headerHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int): Int {
563
+ val rowTop = screenLayout.headerStatusBarHeight +
564
+ (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
565
+ return max(screenLayout.headerHeight.roundToPx(), rowTop.roundToPx() + rowHeight)
566
+ }
567
+ override fun MeasureScope.collapsedHeaderHeight(
568
+ screenLayout: ScreenLayout,
569
+ statusBar: Int,
570
+ rowHeight: Int,
571
+ ) = (
572
+ screenLayout.headerStatusBarHeight +
573
+ (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
574
+ ).roundToPx() + rowHeight
575
+ override fun MeasureScope.headerRightStartX(
576
+ screenLayout: ScreenLayout,
577
+ width: Int,
578
+ insetRight: Int,
579
+ spacing: Int,
580
+ rightWidth: Int,
581
+ ) = width - insetRight -
582
+ (screenLayout.statusBarClearance?.right?.roundToPx() ?: 0) -
583
+ spacing - rightWidth
584
+
585
+ override fun MeasureScope.searchStartY(
586
+ screenLayout: ScreenLayout,
587
+ headerY: Int,
588
+ statusBar: Int,
589
+ rowHeight: Int,
590
+ ) = headerY + (
591
+ screenLayout.headerStatusBarHeight +
592
+ (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
593
+ ).roundToPx()
594
+ }
595
+
596
+ private class LiteScreenLayoutPolicy(
597
+ private val screenLayout: ScreenLayout,
598
+ private val applySafeAreaPadding: Boolean,
599
+ private val useAnimationSearch: Boolean,
600
+ private val isHeaderNone: Boolean,
601
+ private val isHeaderExtend: Boolean,
602
+ private val statusBarHeight: Dp,
603
+ private val scrollPercentage: State<Float>,
604
+ private val titlePosition: TitlePosition,
605
+ private val headerSpaceBetween: Dp? = null,
606
+ private val animationOption: AnimationOption?,
607
+ private val verticalArrangement: Arrangement.Vertical,
608
+ private val horizontalAlignment: Alignment.Horizontal,
609
+ ) : MeasurePolicy {
610
+ private val geometry = if (screenLayout.isIPhoneDuo) {
611
+ IPhoneDuoLiteScreenGeometry()
612
+ } else {
613
+ StandardPhoneLiteScreenGeometry()
614
+ }
615
+
616
+ val searchStartPosition: IntOffset by lazy {
617
+ if (animationOption == null) return@lazy IntOffset.Zero
618
+ val offset = animationOption.targetBounds.topLeft
619
+ IntOffset(
620
+ x = offset.x.roundToInt(),
621
+ y = offset.y.roundToInt(),
622
+ )
623
+ }
624
+
625
+ override fun MeasureScope.measure(
626
+ measurables: List<Measurable>,
627
+ constraints: Constraints
628
+ ): MeasureResult {
629
+ val spacing12 = Spacing.M.roundToPx()
630
+ val spaceBetween = headerSpaceBetween?.roundToPx() ?: spacing12
631
+ val statusBarPx = statusBarHeight.roundToPx()
632
+ val headerRowDefault = HEADER_HEIGHT.dp.roundToPx()
633
+ val scrollPercent = scrollPercentage.value
634
+
635
+ val contentMeasurable = measurables.find { it.layoutId == HeaderId.CONTENT_ID }
636
+
637
+ val insetLeft = if (applySafeAreaPadding) screenLayout.insetLeft.roundToPx() else 0
638
+ val insetRight = if (applySafeAreaPadding) screenLayout.insetRight.roundToPx() else 0
639
+ val safeLayoutWidth = with(geometry) {
640
+ safeWidth(screenLayout, constraints.maxWidth, insetLeft, insetRight)
641
+ }
642
+ val searchStartX = with(geometry) { searchStartX(screenLayout, insetLeft, spacing12) }
643
+ val realConstraints = constraints.copy(
644
+ minWidth = 0,
645
+ minHeight = 0,
646
+ maxWidth = (safeLayoutWidth - spacing12 * 2).coerceAtLeast(0),
647
+ )
648
+ val backIconPlaceable = measurables.find { it.layoutId == HeaderId.BACK_ID }?.measure(realConstraints)
649
+ val headerRightPlaceable = measurables.find { it.layoutId == HeaderId.HEADER_RIGHT_ID }?.measure(
650
+ realConstraints.copy(maxWidth = realConstraints.maxWidth / 2)
651
+ )
652
+ val headerBackWidth = if (screenLayout.sideBar == null) backIconPlaceable.safeWidth else 0
653
+ val baseInputSearchConstraints = if (isHeaderExtend) {
654
+ val minWidth = if (useAnimationSearch) {
655
+ realConstraints.maxWidth - headerBackWidth - headerRightPlaceable.safeWidth - spaceBetween * 2
656
+ } else {
657
+ realConstraints.maxWidth
658
+ }
659
+ realConstraints.copy(
660
+ maxWidth = (realConstraints.maxWidth * (1 - scrollPercent)).toInt()
661
+ .coerceAtLeast(minWidth)
662
+ )
663
+ } else {
664
+ var spaceConsumed = 0
665
+ if (headerBackWidth != 0) spaceConsumed += headerBackWidth + spaceBetween
666
+ if (headerRightPlaceable.safeWidth != 0) spaceConsumed += headerRightPlaceable.safeWidth + spaceBetween
667
+ realConstraints.copy(
668
+ maxWidth = realConstraints.maxWidth - spaceConsumed
669
+ )
670
+ }
671
+ val inputSearchConstraints = baseInputSearchConstraints.withAnimationTargetBounds()
672
+ val inputSearchPlaceable = measurables.find { it.layoutId == HeaderId.INPUT_SEARCH_ID }
673
+ ?.measure(inputSearchConstraints)
674
+ val titlePlaceable = measurables.find { it.layoutId == HeaderId.TITLE_ID }?.measure(
675
+ constraints = realConstraints.copy(
676
+ maxWidth = realConstraints.maxWidth - headerBackWidth - headerRightPlaceable.safeWidth - spaceBetween * 2
677
+ )
678
+ )
679
+
680
+ // Same height rule as navigation.component.HeaderBackground.
681
+ var defaultHeight = with(geometry) { headerHeight(screenLayout, statusBarPx, headerRowDefault) }
682
+ if (isHeaderExtend) {
683
+ defaultHeight = if (screenLayout.isIPhoneDuo) {
684
+ max(defaultHeight, 154.dp.roundToPx())
685
+ } else {
686
+ 154.dp.roundToPx()
687
+ }
688
+ }
689
+ val headerHeight = when {
690
+ isHeaderNone -> statusBarPx
691
+ !useAnimationSearch && !isHeaderExtend -> defaultHeight
692
+ else -> {
693
+ val collapsableSpace = defaultHeight -
694
+ with(geometry) { collapsedHeaderHeight(screenLayout, statusBarPx, headerRowDefault) }
695
+ (defaultHeight - scrollPercent * collapsableSpace).toInt()
696
+ }
697
+ }
698
+
699
+ val layoutWidth = constraints.maxWidth
700
+ val layoutHeight = constraints.maxHeight
701
+ val backgroundInsetLeft = if (!applySafeAreaPadding && screenLayout.sideBar != null) screenLayout.insetLeft.roundToPx() else 0
702
+ val contentHeight = (layoutHeight - headerHeight).coerceAtLeast(0)
703
+ val contentPlaceable = contentMeasurable?.measure(
704
+ constraints.copy(
705
+ minWidth = 0,
706
+ minHeight = contentHeight,
707
+ maxHeight = contentHeight,
708
+ )
709
+ )
710
+ val backgroundPlaceable = measurables.find { it.layoutId == HeaderId.BACKGROUND_ID }
711
+ ?.measure(
712
+ Constraints.fixed(
713
+ width = layoutWidth,
714
+ height = headerHeight,
715
+ )
716
+ )
717
+ val childrenHeights = intArrayOf(
718
+ headerHeight,
719
+ contentPlaceable.safeHeight,
720
+ )
721
+ val childrenY = IntArray(childrenHeights.size)
722
+ with(verticalArrangement) {
723
+ arrange(
724
+ totalSize = layoutHeight,
725
+ sizes = childrenHeights,
726
+ outPositions = childrenY,
727
+ )
728
+ }
729
+ val headerY = childrenY[0]
730
+ val contentY = childrenY[1]
731
+
732
+ return layout(
733
+ width = layoutWidth,
734
+ height = layoutHeight,
735
+ ) {
736
+ val progress = animationOption?.progress?.value ?: 1f
737
+
738
+ val startX = searchStartX
739
+ val startY = with(geometry) {
740
+ searchStartY(screenLayout, headerY, statusBarPx, headerRowDefault)
741
+ }
742
+ var curX = startX
743
+ var curY = startY
744
+
745
+ contentPlaceable?.place(
746
+ x = horizontalAlignment.align(
747
+ size = contentPlaceable.width,
748
+ space = layoutWidth,
749
+ layoutDirection = layoutDirection,
750
+ ),
751
+ y = contentY,
752
+ )
753
+
754
+ backgroundPlaceable?.place(
755
+ x = -backgroundInsetLeft,
756
+ y = headerY,
757
+ )
758
+
759
+ if (backIconPlaceable != null) {
760
+ val sideBar = screenLayout.sideBar
761
+ if (sideBar == null) {
762
+ backIconPlaceable.place(
763
+ x = startX,
764
+ y = startY + backIconPlaceable.verticalCenterOffset(headerRowDefault),
765
+ )
766
+ curX += backIconPlaceable.safeWidth + spaceBetween
767
+ } else {
768
+ val x = when (sideBar.edge) {
769
+ SideBarEdge.LEFT -> insetLeft - screenLayout.insetLeft.roundToPx() + sideBar.width.roundToPx() - spacing12 - backIconPlaceable.width
770
+ SideBarEdge.RIGHT -> layoutWidth + (if (applySafeAreaPadding) 0 else screenLayout.insetRight.roundToPx()) - sideBar.width.roundToPx() + spacing12
771
+ }
772
+ backIconPlaceable.place(
773
+ x = x,
774
+ y = sideBar.top.roundToPx() + (DuoMetrics.controlSize.roundToPx() - backIconPlaceable.height) / 2,
775
+ )
776
+ }
777
+ }
778
+ headerRightPlaceable?.place(
779
+ x = with(geometry) {
780
+ headerRightStartX(
781
+ screenLayout,
782
+ layoutWidth,
783
+ insetRight,
784
+ spacing12,
785
+ headerRightPlaceable.safeWidth,
786
+ )
787
+ },
788
+ y = startY + headerRightPlaceable.verticalCenterOffset(headerRowDefault),
789
+ )
790
+
791
+ val titleOffset = IntOffset(
792
+ x = if (titlePosition == TitlePosition.LEFT) curX
793
+ else searchStartX - spacing12 + titlePlaceable.horizontalCenterOffset(
794
+ space = safeLayoutWidth - spacing12 * 2,
795
+ layoutDirection = layoutDirection,
796
+ ),
797
+ y = startY + titlePlaceable.verticalCenterOffset(headerRowDefault),
798
+ )
799
+
800
+ titlePlaceable?.place(titleOffset)
801
+
802
+ if ((backIconPlaceable != null && screenLayout.sideBar == null) || headerRightPlaceable != null || titlePlaceable != null) {
803
+ curY += headerRowDefault
804
+ }
805
+
806
+ val inputSearchOffset = if (isHeaderExtend) {
807
+ val baseY = curY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault)
808
+ val y = (baseY * (1 - scrollPercent)).toInt().coerceAtLeast(
809
+ startY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault)
810
+ )
811
+ IntOffset(
812
+ x = startX + ((headerBackWidth + spaceBetween) * (scrollPercent * 2f).coerceIn(
813
+ 0f, 1f
814
+ )).toInt(),
815
+ y = y,
816
+ )
817
+ } else {
818
+ IntOffset(
819
+ x = curX,
820
+ y = startY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault),
821
+ )
822
+ }
823
+ val finalPosition = lerp(
824
+ searchStartPosition,
825
+ inputSearchOffset,
826
+ progress,
827
+ )
828
+
829
+ inputSearchPlaceable?.place(
830
+ finalPosition
831
+ )
832
+ }
833
+ }
834
+
835
+ private val Placeable?.safeHeight
836
+ get() = this?.height ?: 0
837
+ private val Placeable?.safeWidth
838
+ get() = this?.width ?: 0
839
+
840
+ private fun Constraints.withAnimationTargetBounds(): Constraints {
841
+ val option = animationOption ?: return this
842
+ val progress = option.progress.value
843
+ if (progress >= 1f) return this
844
+
845
+ val targetWidth = option.targetBounds.width.roundToInt().coerceAtLeast(0)
846
+ val targetHeight = option.targetBounds.height.roundToInt().coerceAtLeast(0)
847
+ val animatedMinWidth = lerpPx(targetWidth, minWidth, progress)
848
+ .coerceInBounds(maxWidth)
849
+ val animatedMaxWidth = lerpMaxPx(targetWidth, maxWidth, progress)
850
+ .coerceAtLeast(animatedMinWidth)
851
+ val animatedMinHeight = lerpPx(targetHeight, minHeight, progress)
852
+ .coerceInBounds(maxHeight)
853
+ val animatedMaxHeight = lerpMaxPx(targetHeight, maxHeight, progress)
854
+ .coerceAtLeast(animatedMinHeight)
855
+
856
+ return copy(
857
+ minWidth = animatedMinWidth,
858
+ maxWidth = animatedMaxWidth,
859
+ minHeight = animatedMinHeight,
860
+ maxHeight = animatedMaxHeight,
861
+ )
862
+ }
863
+
864
+ private fun lerpPx(
865
+ start: Int,
866
+ stop: Int,
867
+ fraction: Float,
868
+ ): Int = androidx.compose.ui.util.lerp(
869
+ start.toFloat(),
870
+ stop.toFloat(),
871
+ fraction,
872
+ ).roundToInt()
873
+
874
+ private fun lerpMaxPx(
875
+ start: Int,
876
+ stop: Int,
877
+ fraction: Float,
878
+ ): Int {
879
+ if (stop == Constraints.Infinity) return Constraints.Infinity
880
+ return lerpPx(start, stop, fraction)
881
+ }
882
+
883
+ private fun Int.coerceInBounds(max: Int): Int {
884
+ if (max == Constraints.Infinity) return coerceAtLeast(0)
885
+ return coerceIn(0, max)
886
+ }
887
+
888
+ private fun Placeable?.verticalCenterOffset(space: Int): Int {
889
+ if (this == null) return 0
890
+ return Alignment.CenterVertically.align(safeHeight, space)
891
+ }
892
+
893
+ private fun Placeable?.horizontalCenterOffset(
894
+ space: Int,
895
+ layoutDirection: LayoutDirection
896
+ ): Int {
897
+ if (this == null) return 0
898
+ return Alignment.CenterHorizontally.align(safeWidth, space, layoutDirection)
899
+ }
900
+ }
901
+
902
+ private val EMPTY_FUNC = {}
903
+
904
+ @Stable
905
+ data class LiteInputSearchProps(
906
+ val textFieldState: MutableState<String>,
907
+ val onValueChange: (String) -> Unit,
908
+ val onClear: () -> Unit = EMPTY_FUNC,
909
+ val clearCondition: (() -> Boolean)? = null,
910
+ val modifier: Modifier = Modifier,
911
+ val onFocused: (() -> Unit) = EMPTY_FUNC,
912
+ val keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
913
+ val keyboardActions: KeyboardActions = KeyboardActions.Default,
914
+ val onKeyboardAction: (() -> Unit) = EMPTY_FUNC,
915
+
916
+ val btnText: String? = null,
917
+ val isShowBtnText: Boolean = !btnText.isNullOrEmpty(),
918
+ val onPressBtnText: (() -> Unit) = EMPTY_FUNC,
919
+
920
+ val disabled: Boolean = false,
921
+
922
+ val placeHolder: String? = null,
923
+
924
+ val cursorBrush: Brush? = null,
925
+ val customBackIcon: @Composable ((Modifier) -> Unit)? = null,
926
+ val customSearchIcon: @Composable (() -> Unit)? = null,
927
+ val customPlaceHolder: @Composable (() -> Unit)? = null,
928
+ val customTextStyle: TextStyle? = null,
929
+ val customIconClear: @Composable (() -> Unit)? = null,
930
+ val iconRightTextField: @Composable ((Modifier) -> Unit)? = null,
931
+ )
932
+
933
+ @Composable
934
+ private fun LiteInputSearch(
935
+ modifier: Modifier = Modifier,
936
+ inputSearchProps: LiteInputSearchProps? = null,
937
+ ) {
938
+ inputSearchProps ?: return
939
+ val theme = AppTheme.current
940
+
941
+ val isFocused = remember { mutableStateOf(false) }
942
+ val interactionSource = remember { MutableInteractionSource() }
943
+ val textState by remember { inputSearchProps.textFieldState }
944
+
945
+ val isShowBtnText = inputSearchProps.isShowBtnText && !inputSearchProps.btnText.isNullOrEmpty()
946
+ val inputFieldFontFamily = getFontFamily(theme.font, Typography.bodyDefaultRegular.fontWeight)
947
+ val inputFieldStyle = remember(theme, inputFieldFontFamily) {
948
+ Typography.bodyDefaultRegular.copy(
949
+ color = theme.colors.text.default,
950
+ fontFamily = inputFieldFontFamily,
951
+ )
952
+ }
953
+
954
+ LaunchedEffect(inputSearchProps.onFocused) {
955
+ interactionSource.interactions.mapNotNull { it as? FocusInteraction }.collectLatest {
956
+ val isFocus = it is FocusInteraction.Focus
957
+ isFocused.value = isFocus
958
+ if (isFocus) inputSearchProps.onFocused()
959
+ }
960
+ }
961
+
962
+ Row(
963
+ modifier = modifier,
964
+ verticalAlignment = Alignment.CenterVertically,
965
+ ) {
966
+ val textFieldModifier = remember(inputSearchProps.modifier) {
967
+ inputSearchProps.modifier
968
+ .weight(1f)
969
+ }
970
+ BasicTextField(
971
+ value = textState,
972
+ onValueChange = inputSearchProps.onValueChange,
973
+ enabled = !inputSearchProps.disabled,
974
+ keyboardOptions = inputSearchProps.keyboardOptions,
975
+ keyboardActions = inputSearchProps.keyboardActions,
976
+ modifier = textFieldModifier,
977
+ textStyle = inputSearchProps.customTextStyle ?: inputFieldStyle,
978
+ singleLine = true,
979
+ cursorBrush = inputSearchProps.cursorBrush ?: SolidColor(Color.Black),
980
+ interactionSource = interactionSource,
981
+ decorationBox = { innerTextField ->
982
+ val isShowClear by remember(inputSearchProps.clearCondition, isFocused.value) {
983
+ derivedStateOf {
984
+ inputSearchProps.clearCondition?.invoke() == true || (isFocused.value && textState.isNotEmpty())
985
+ }
986
+ }
987
+ val placeHolder = inputSearchProps.placeHolder
988
+ ?.takeIf { textState.isEmpty() }
989
+ val iconRightModifier = remember {
990
+ Modifier
991
+ .padding(start = Spacing.L)
992
+ .drawWithContent {
993
+ val offsetX = -Spacing.S.toPx()
994
+ drawLine(
995
+ start = Offset(
996
+ x = offsetX,
997
+ y = 0f,
998
+ ),
999
+ end = Offset(
1000
+ x = offsetX,
1001
+ y = size.height,
1002
+ ),
1003
+ color = theme.colors.primary,
1004
+ strokeWidth = 1.dp.toPx(),
1005
+ )
1006
+ drawContent()
1007
+ }
1008
+ }
1009
+
1010
+ Row(
1011
+ modifier = Modifier
1012
+ .padding(
1013
+ horizontal = Spacing.M,
1014
+ vertical = Spacing.S,
1015
+ ),
1016
+ horizontalArrangement = Arrangement.Start,
1017
+ verticalAlignment = Alignment.CenterVertically,
1018
+ ) {
1019
+ inputSearchProps.customSearchIcon?.invoke() ?: Icon(
1020
+ source = "navigation_search",
1021
+ modifier = Modifier.padding(end = Spacing.XS),
1022
+ size = 24.dp,
1023
+ color = theme.colors.text.hint
1024
+ )
1025
+ Box(
1026
+ modifier = Modifier.weight(1f),
1027
+ contentAlignment = Alignment.CenterStart,
1028
+ ) {
1029
+ if (!placeHolder.isNullOrEmpty()) {
1030
+ inputSearchProps.customPlaceHolder?.invoke() ?: Text(
1031
+ text = placeHolder,
1032
+ style = inputSearchProps.customTextStyle
1033
+ ?: Typography.bodyDefaultRegular,
1034
+ maxLines = 1,
1035
+ color = theme.colors.text.hint,
1036
+ overflow = TextOverflow.Ellipsis
1037
+ )
1038
+ }
1039
+ innerTextField()
1040
+ }
1041
+
1042
+ if (isShowClear) {
1043
+ inputSearchProps.customIconClear?.invoke() ?: Icon(
1044
+ source = "24_navigation_close_circle_full",
1045
+ size = 16.dp,
1046
+ color = theme.colors.text.hint,
1047
+ modifier = Modifier.padding(start = Spacing.XS)
1048
+ .noFeedbackClickable(onClick = inputSearchProps.onClear),
1049
+ )
1050
+ }
1051
+
1052
+ inputSearchProps.iconRightTextField?.invoke(iconRightModifier)
1053
+ }
1054
+ }
1055
+ )
1056
+
1057
+ if (isShowBtnText) {
1058
+ Text(
1059
+ text = inputSearchProps.btnText,
1060
+ style = Typography.actionDefaultBold,
1061
+ color = theme.colors.text.default,
1062
+ modifier = Modifier.padding(start = Spacing.L)
1063
+ .noFeedbackClickable(onClick = inputSearchProps.onPressBtnText)
1064
+ )
1065
+ }
1066
+ }
1067
+ }