@momo-kits/native-kits 0.169.8-beta.2-debug → 0.169.8-beta.3

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 (141) hide show
  1. package/ios/native-kits.podspec +1 -1
  2. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  3. package/package.json +1 -1
  4. package/build.gradle.kts +0 -11
  5. package/compose/build.gradle.kts +0 -198
  6. package/compose/compose.podspec +0 -47
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
  10. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
  11. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
  12. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
  13. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -62
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -267
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -82
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -356
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -128
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -195
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -263
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -235
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -265
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -343
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -363
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -307
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -306
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -220
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -457
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -120
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -210
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -292
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -316
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -52
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -113
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -205
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -422
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -727
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -148
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -400
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -100
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -97
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -207
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -132
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -456
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -399
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -204
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -9
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -22
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
  123. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
  124. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
  125. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -118
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
  129. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
  130. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -66
  131. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -218
  132. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
  133. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -144
  134. package/gradle/libs.versions.toml +0 -67
  135. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  136. package/gradle/wrapper/gradle-wrapper.properties +0 -8
  137. package/gradle.properties +0 -24
  138. package/gradlew +0 -252
  139. package/gradlew.bat +0 -94
  140. package/ios-demo/README.md +0 -120
  141. package/settings.gradle.kts +0 -64
@@ -1,1067 +0,0 @@
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) =
516
- insetLeft + spacing
517
-
518
- override fun MeasureScope.headerHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int) =
519
- statusBar + rowHeight
520
- override fun MeasureScope.collapsedHeaderHeight(
521
- screenLayout: ScreenLayout,
522
- statusBar: Int,
523
- rowHeight: Int,
524
- ) = statusBar + rowHeight
525
- override fun MeasureScope.headerRightStartX(
526
- screenLayout: ScreenLayout,
527
- width: Int,
528
- insetRight: Int,
529
- spacing: Int,
530
- rightWidth: Int,
531
- ) = width - insetRight - spacing - rightWidth
532
-
533
- override fun MeasureScope.searchStartY(
534
- screenLayout: ScreenLayout,
535
- headerY: Int,
536
- statusBar: Int,
537
- rowHeight: Int,
538
- ) = headerY + statusBar
539
- }
540
-
541
- private class IPhoneDuoLiteScreenGeometry : LiteScreenGeometry {
542
- override fun MeasureScope.safeWidth(
543
- screenLayout: ScreenLayout,
544
- width: Int,
545
- insetLeft: Int,
546
- insetRight: Int,
547
- ): Int {
548
- val clearance = screenLayout.statusBarClearance
549
- return (
550
- width - insetLeft - insetRight -
551
- (clearance?.left?.roundToPx() ?: 0) -
552
- (clearance?.right?.roundToPx() ?: 0)
553
- ).coerceAtLeast(0)
554
- }
555
-
556
- override fun MeasureScope.searchStartX(screenLayout: ScreenLayout, insetLeft: Int, spacing: Int) =
557
- insetLeft + (screenLayout.statusBarClearance?.left?.roundToPx() ?: 0) + spacing
558
-
559
- override fun MeasureScope.headerHeight(screenLayout: ScreenLayout, statusBar: Int, rowHeight: Int): Int {
560
- val rowTop = screenLayout.headerStatusBarHeight +
561
- (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
562
- return max(screenLayout.headerHeight.roundToPx(), rowTop.roundToPx() + rowHeight)
563
- }
564
- override fun MeasureScope.collapsedHeaderHeight(
565
- screenLayout: ScreenLayout,
566
- statusBar: Int,
567
- rowHeight: Int,
568
- ) = (
569
- screenLayout.headerStatusBarHeight +
570
- (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
571
- ).roundToPx() + rowHeight
572
- override fun MeasureScope.headerRightStartX(
573
- screenLayout: ScreenLayout,
574
- width: Int,
575
- insetRight: Int,
576
- spacing: Int,
577
- rightWidth: Int,
578
- ) = width - insetRight -
579
- (screenLayout.statusBarClearance?.right?.roundToPx() ?: 0) -
580
- spacing - rightWidth
581
-
582
- override fun MeasureScope.searchStartY(
583
- screenLayout: ScreenLayout,
584
- headerY: Int,
585
- statusBar: Int,
586
- rowHeight: Int,
587
- ) = headerY + (
588
- screenLayout.headerStatusBarHeight +
589
- (screenLayout.headerBarHeight - rowHeight.toDp()) / 2
590
- ).roundToPx()
591
- }
592
-
593
- private class LiteScreenLayoutPolicy(
594
- private val screenLayout: ScreenLayout,
595
- private val applySafeAreaPadding: Boolean,
596
- private val useAnimationSearch: Boolean,
597
- private val isHeaderNone: Boolean,
598
- private val isHeaderExtend: Boolean,
599
- private val statusBarHeight: Dp,
600
- private val scrollPercentage: State<Float>,
601
- private val titlePosition: TitlePosition,
602
- private val headerSpaceBetween: Dp? = null,
603
- private val animationOption: AnimationOption?,
604
- private val verticalArrangement: Arrangement.Vertical,
605
- private val horizontalAlignment: Alignment.Horizontal,
606
- ) : MeasurePolicy {
607
- private val geometry = if (screenLayout.isIPhoneDuo) {
608
- IPhoneDuoLiteScreenGeometry()
609
- } else {
610
- StandardPhoneLiteScreenGeometry()
611
- }
612
-
613
- val searchStartPosition: IntOffset by lazy {
614
- if (animationOption == null) return@lazy IntOffset.Zero
615
- val offset = animationOption.targetBounds.topLeft
616
- IntOffset(
617
- x = offset.x.roundToInt(),
618
- y = offset.y.roundToInt(),
619
- )
620
- }
621
-
622
- override fun MeasureScope.measure(
623
- measurables: List<Measurable>,
624
- constraints: Constraints
625
- ): MeasureResult {
626
- val spacing12 = Spacing.M.roundToPx()
627
- val spaceBetween = headerSpaceBetween?.roundToPx() ?: spacing12
628
- val statusBarPx = statusBarHeight.roundToPx()
629
- val headerRowDefault = HEADER_HEIGHT.dp.roundToPx()
630
- val scrollPercent = scrollPercentage.value
631
-
632
- val contentMeasurable = measurables.find { it.layoutId == HeaderId.CONTENT_ID }
633
-
634
- val insetLeft = if (applySafeAreaPadding) screenLayout.insetLeft.roundToPx() else 0
635
- val insetRight = if (applySafeAreaPadding) screenLayout.insetRight.roundToPx() else 0
636
- val safeLayoutWidth = with(geometry) {
637
- safeWidth(screenLayout, constraints.maxWidth, insetLeft, insetRight)
638
- }
639
- val searchStartX = with(geometry) { searchStartX(screenLayout, insetLeft, spacing12) }
640
- val realConstraints = constraints.copy(
641
- minWidth = 0,
642
- minHeight = 0,
643
- maxWidth = (safeLayoutWidth - spacing12 * 2).coerceAtLeast(0),
644
- )
645
- val backIconPlaceable =
646
- measurables.find { it.layoutId == HeaderId.BACK_ID }?.measure(realConstraints)
647
- val headerRightPlaceable =
648
- measurables.find { it.layoutId == HeaderId.HEADER_RIGHT_ID }?.measure(
649
- realConstraints.copy(
650
- maxWidth = realConstraints.maxWidth / 2,
651
- )
652
- )
653
- val headerBackWidth = if (screenLayout.sideBar == null) backIconPlaceable.safeWidth else 0
654
- val baseInputSearchConstraints = if (isHeaderExtend) {
655
- val minWidth =
656
- if (useAnimationSearch) realConstraints.maxWidth - headerBackWidth - headerRightPlaceable.safeWidth - spaceBetween * 2
657
- else realConstraints.maxWidth
658
- realConstraints.copy(
659
- maxWidth = (realConstraints.maxWidth * (1 - scrollPercent)).toInt()
660
- .coerceAtLeast(minWidth)
661
- )
662
- } else {
663
- var spaceConsumed = 0
664
- if (headerBackWidth != 0) spaceConsumed += headerBackWidth + spaceBetween
665
- if (headerRightPlaceable.safeWidth != 0) spaceConsumed += headerRightPlaceable.safeWidth + spaceBetween
666
- realConstraints.copy(
667
- maxWidth = realConstraints.maxWidth - spaceConsumed
668
- )
669
- }
670
- val inputSearchConstraints = baseInputSearchConstraints.withAnimationTargetBounds()
671
- val inputSearchPlaceable = measurables.find { it.layoutId == HeaderId.INPUT_SEARCH_ID }
672
- ?.measure(inputSearchConstraints)
673
- val titlePlaceable = measurables.find { it.layoutId == HeaderId.TITLE_ID }?.measure(
674
- constraints = realConstraints.copy(
675
- maxWidth = realConstraints.maxWidth - headerBackWidth - headerRightPlaceable.safeWidth - spaceBetween * 2
676
- )
677
- )
678
-
679
- // Same height rule as navigation.component.HeaderBackground.
680
- var defaultHeight = with(geometry) { headerHeight(screenLayout, statusBarPx, headerRowDefault) }
681
- if (isHeaderExtend) {
682
- defaultHeight = if (screenLayout.isIPhoneDuo) {
683
- max(defaultHeight, 154.dp.roundToPx())
684
- } else {
685
- 154.dp.roundToPx()
686
- }
687
- }
688
- val headerHeight = when {
689
- isHeaderNone -> statusBarPx
690
- !useAnimationSearch && !isHeaderExtend -> defaultHeight
691
- else -> {
692
- val collapsableSpace = defaultHeight -
693
- with(geometry) { collapsedHeaderHeight(screenLayout, statusBarPx, headerRowDefault) }
694
- (defaultHeight - scrollPercent * collapsableSpace).toInt()
695
- }
696
- }
697
-
698
- val layoutWidth = constraints.maxWidth
699
- val layoutHeight = constraints.maxHeight
700
- val backgroundInsetLeft = if (!applySafeAreaPadding && screenLayout.sideBar != null) screenLayout.insetLeft.roundToPx() else 0
701
- val contentHeight = (layoutHeight - headerHeight).coerceAtLeast(0)
702
- val contentPlaceable = contentMeasurable?.measure(
703
- constraints.copy(
704
- minWidth = 0,
705
- minHeight = contentHeight,
706
- maxHeight = contentHeight,
707
- )
708
- )
709
- val backgroundPlaceable = measurables.find { it.layoutId == HeaderId.BACKGROUND_ID }
710
- ?.measure(
711
- Constraints.fixed(
712
- width = layoutWidth,
713
- height = headerHeight,
714
- )
715
- )
716
- val childrenHeights = intArrayOf(
717
- headerHeight,
718
- contentPlaceable.safeHeight,
719
- )
720
- val childrenY = IntArray(childrenHeights.size)
721
- with(verticalArrangement) {
722
- arrange(
723
- totalSize = layoutHeight,
724
- sizes = childrenHeights,
725
- outPositions = childrenY,
726
- )
727
- }
728
- val headerY = childrenY[0]
729
- val contentY = childrenY[1]
730
-
731
- return layout(
732
- width = layoutWidth,
733
- height = layoutHeight,
734
- ) {
735
- val progress = animationOption?.progress?.value ?: 1f
736
-
737
- val startX = searchStartX
738
- val startY = with(geometry) {
739
- searchStartY(screenLayout, headerY, statusBarPx, headerRowDefault)
740
- }
741
- var curX = startX
742
- var curY = startY
743
-
744
- contentPlaceable?.place(
745
- x = horizontalAlignment.align(
746
- size = contentPlaceable.width,
747
- space = layoutWidth,
748
- layoutDirection = layoutDirection,
749
- ),
750
- y = contentY,
751
- )
752
-
753
- backgroundPlaceable?.place(
754
- x = -backgroundInsetLeft,
755
- y = headerY,
756
- )
757
-
758
- if (backIconPlaceable != null) {
759
- val sideBar = screenLayout.sideBar
760
- if (sideBar == null) {
761
- backIconPlaceable.place(
762
- x = startX,
763
- y = startY + backIconPlaceable.verticalCenterOffset(headerRowDefault),
764
- )
765
- curX += backIconPlaceable.safeWidth + spaceBetween
766
- } else {
767
- val x = when (sideBar.edge) {
768
- SideBarEdge.LEFT -> insetLeft - screenLayout.insetLeft.roundToPx() + sideBar.width.roundToPx() - spacing12 - backIconPlaceable.width
769
- SideBarEdge.RIGHT -> layoutWidth + (if (applySafeAreaPadding) 0 else screenLayout.insetRight.roundToPx()) - sideBar.width.roundToPx() + spacing12
770
- }
771
- backIconPlaceable.place(
772
- x = x,
773
- y = sideBar.top.roundToPx() + (DuoMetrics.controlSize.roundToPx() - backIconPlaceable.height) / 2,
774
- )
775
- }
776
- }
777
- headerRightPlaceable?.place(
778
- x = with(geometry) {
779
- headerRightStartX(
780
- screenLayout,
781
- layoutWidth,
782
- insetRight,
783
- spacing12,
784
- headerRightPlaceable.safeWidth,
785
- )
786
- },
787
- y = startY + headerRightPlaceable.verticalCenterOffset(headerRowDefault),
788
- )
789
-
790
- val titleOffset = IntOffset(
791
- x = if (titlePosition == TitlePosition.LEFT) curX
792
- else searchStartX - spacing12 + titlePlaceable.horizontalCenterOffset(
793
- space = safeLayoutWidth - spacing12 * 2,
794
- layoutDirection = layoutDirection,
795
- ),
796
- y = startY + titlePlaceable.verticalCenterOffset(headerRowDefault),
797
- )
798
-
799
- titlePlaceable?.place(titleOffset)
800
-
801
- if ((backIconPlaceable != null && screenLayout.sideBar == null) || headerRightPlaceable != null || titlePlaceable != null) {
802
- curY += headerRowDefault
803
- }
804
-
805
- val inputSearchOffset = if (isHeaderExtend) {
806
- val baseY = curY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault)
807
- val y = (baseY * (1 - scrollPercent)).toInt().coerceAtLeast(
808
- startY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault)
809
- )
810
- IntOffset(
811
- x = startX + ((headerBackWidth + spaceBetween) * (scrollPercent * 2f).coerceIn(
812
- 0f, 1f
813
- )).toInt(),
814
- y = y,
815
- )
816
- } else {
817
- IntOffset(
818
- x = curX,
819
- y = startY + inputSearchPlaceable.verticalCenterOffset(headerRowDefault),
820
- )
821
- }
822
- val finalPosition = lerp(
823
- searchStartPosition,
824
- inputSearchOffset,
825
- progress,
826
- )
827
-
828
- inputSearchPlaceable?.place(
829
- finalPosition
830
- )
831
- }
832
- }
833
-
834
- private val Placeable?.safeHeight
835
- get() = this?.height ?: 0
836
- private val Placeable?.safeWidth
837
- get() = this?.width ?: 0
838
-
839
- private fun Constraints.withAnimationTargetBounds(): Constraints {
840
- val option = animationOption ?: return this
841
- val progress = option.progress.value
842
- if (progress >= 1f) return this
843
-
844
- val targetWidth = option.targetBounds.width.roundToInt().coerceAtLeast(0)
845
- val targetHeight = option.targetBounds.height.roundToInt().coerceAtLeast(0)
846
- val animatedMinWidth = lerpPx(targetWidth, minWidth, progress)
847
- .coerceInBounds(maxWidth)
848
- val animatedMaxWidth = lerpMaxPx(targetWidth, maxWidth, progress)
849
- .coerceAtLeast(animatedMinWidth)
850
- val animatedMinHeight = lerpPx(targetHeight, minHeight, progress)
851
- .coerceInBounds(maxHeight)
852
- val animatedMaxHeight = lerpMaxPx(targetHeight, maxHeight, progress)
853
- .coerceAtLeast(animatedMinHeight)
854
-
855
- return copy(
856
- minWidth = animatedMinWidth,
857
- maxWidth = animatedMaxWidth,
858
- minHeight = animatedMinHeight,
859
- maxHeight = animatedMaxHeight,
860
- )
861
- }
862
-
863
- private fun lerpPx(
864
- start: Int,
865
- stop: Int,
866
- fraction: Float,
867
- ): Int = androidx.compose.ui.util.lerp(
868
- start.toFloat(),
869
- stop.toFloat(),
870
- fraction,
871
- ).roundToInt()
872
-
873
- private fun lerpMaxPx(
874
- start: Int,
875
- stop: Int,
876
- fraction: Float,
877
- ): Int {
878
- if (stop == Constraints.Infinity) return Constraints.Infinity
879
- return lerpPx(start, stop, fraction)
880
- }
881
-
882
- private fun Int.coerceInBounds(max: Int): Int {
883
- if (max == Constraints.Infinity) return coerceAtLeast(0)
884
- return coerceIn(0, max)
885
- }
886
-
887
- private fun Placeable?.verticalCenterOffset(space: Int): Int {
888
- if (this == null) return 0
889
- return Alignment.CenterVertically.align(safeHeight, space)
890
- }
891
-
892
- private fun Placeable?.horizontalCenterOffset(
893
- space: Int,
894
- layoutDirection: LayoutDirection
895
- ): Int {
896
- if (this == null) return 0
897
- return Alignment.CenterHorizontally.align(safeWidth, space, layoutDirection)
898
- }
899
- }
900
-
901
- private val EMPTY_FUNC = {}
902
-
903
- @Stable
904
- data class LiteInputSearchProps(
905
- val textFieldState: MutableState<String>,
906
- val onValueChange: (String) -> Unit,
907
- val onClear: () -> Unit = EMPTY_FUNC,
908
- val clearCondition: (() -> Boolean)? = null,
909
- val modifier: Modifier = Modifier,
910
- val onFocused: (() -> Unit) = EMPTY_FUNC,
911
- val keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
912
- val keyboardActions: KeyboardActions = KeyboardActions.Default,
913
- val onKeyboardAction: (() -> Unit) = EMPTY_FUNC,
914
-
915
- val btnText: String? = null,
916
- val isShowBtnText: Boolean = !btnText.isNullOrEmpty(),
917
- val onPressBtnText: (() -> Unit) = EMPTY_FUNC,
918
-
919
- val disabled: Boolean = false,
920
-
921
- val placeHolder: String? = null,
922
-
923
- val cursorBrush: Brush? = null,
924
- val customBackIcon: @Composable ((Modifier) -> Unit)? = null,
925
- val customSearchIcon: @Composable (() -> Unit)? = null,
926
- val customPlaceHolder: @Composable (() -> Unit)? = null,
927
- val customTextStyle: TextStyle? = null,
928
- val customIconClear: @Composable (() -> Unit)? = null,
929
- val iconRightTextField: @Composable ((Modifier) -> Unit)? = null,
930
- )
931
-
932
- @Composable
933
- private fun LiteInputSearch(
934
- modifier: Modifier = Modifier,
935
- inputSearchProps: LiteInputSearchProps? = null,
936
- ) {
937
- inputSearchProps ?: return
938
- val theme = AppTheme.current
939
-
940
- val isFocused = remember { mutableStateOf(false) }
941
- val interactionSource = remember { MutableInteractionSource() }
942
- val textState by remember { inputSearchProps.textFieldState }
943
-
944
- val isShowBtnText = inputSearchProps.isShowBtnText &&
945
- !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
- }