@momo-kits/native-kits 0.164.1-beta.12 → 0.164.1-beta.13-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 (140) hide show
  1. package/build.gradle.kts +11 -0
  2. package/compose/build.gradle.kts +190 -0
  3. package/compose/build.gradle.kts.backup +190 -0
  4. package/compose/compose.podspec +47 -0
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
  8. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
  9. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +150 -0
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +52 -0
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +106 -0
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +183 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +207 -0
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +39 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +293 -0
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +826 -0
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +269 -0
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +110 -0
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +378 -0
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +82 -0
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
  30. package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +356 -0
  32. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +113 -0
  33. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
  34. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +128 -0
  35. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
  36. package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +542 -0
  37. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
  38. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
  39. package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
  40. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +231 -0
  41. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +134 -0
  42. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +475 -0
  43. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +114 -0
  44. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +214 -0
  45. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +240 -0
  46. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +216 -0
  47. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +259 -0
  48. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +182 -0
  49. package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +343 -0
  50. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
  51. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
  52. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
  53. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +84 -0
  54. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
  55. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +328 -0
  56. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +97 -0
  57. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +310 -0
  58. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
  59. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
  60. package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
  61. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +90 -0
  62. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +323 -0
  63. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +217 -0
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +473 -0
  65. package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
  66. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +199 -0
  67. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +91 -0
  68. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +470 -0
  69. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +88 -0
  70. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +131 -0
  71. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +203 -0
  72. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
  73. package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +175 -0
  74. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
  75. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
  76. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
  77. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +234 -0
  78. package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +188 -0
  79. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
  80. package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +16 -0
  81. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitFontScale.kt +22 -0
  82. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
  83. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
  84. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
  85. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +263 -0
  86. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +52 -0
  87. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +38 -0
  88. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +39 -0
  89. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +52 -0
  90. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
  91. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
  92. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
  93. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
  94. package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
  95. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +299 -0
  96. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +129 -0
  97. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +103 -0
  98. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +191 -0
  99. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +386 -0
  100. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
  101. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +619 -0
  102. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +157 -0
  103. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +39 -0
  104. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +156 -0
  105. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +225 -0
  106. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
  107. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +169 -0
  108. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +320 -0
  109. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +81 -0
  110. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +309 -0
  111. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +34 -0
  112. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +360 -0
  113. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +132 -0
  114. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
  115. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +15 -0
  116. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +91 -0
  117. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +9 -0
  118. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +69 -0
  119. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
  120. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
  121. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
  122. package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
  123. package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +40 -0
  124. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +125 -0
  125. package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
  126. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +35 -0
  127. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +66 -0
  128. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +220 -0
  129. package/gradle/libs.versions.toml +69 -0
  130. package/gradle/wrapper/gradle-wrapper.jar +0 -0
  131. package/gradle/wrapper/gradle-wrapper.properties +8 -0
  132. package/gradle.properties +26 -0
  133. package/gradlew +252 -0
  134. package/gradlew.bat +94 -0
  135. package/ios/native-kits.podspec +1 -1
  136. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  137. package/ios-demo/README.md +120 -0
  138. package/local.properties +8 -0
  139. package/package.json +1 -1
  140. package/settings.gradle.kts +64 -0
@@ -0,0 +1,619 @@
1
+ package vn.momo.kits.navigation
2
+
3
+ import androidx.compose.animation.animateColorAsState
4
+ import androidx.compose.animation.core.animateDpAsState
5
+ import androidx.compose.foundation.ScrollState
6
+ import androidx.compose.foundation.background
7
+ import androidx.compose.foundation.border
8
+ import androidx.compose.foundation.gestures.ScrollableState
9
+ import androidx.compose.foundation.layout.Box
10
+ import androidx.compose.foundation.layout.Column
11
+ import androidx.compose.foundation.layout.ColumnScope
12
+ import androidx.compose.foundation.layout.Spacer
13
+ import androidx.compose.foundation.layout.WindowInsets
14
+ import androidx.compose.foundation.layout.asPaddingValues
15
+ import androidx.compose.foundation.layout.aspectRatio
16
+ import androidx.compose.foundation.layout.fillMaxSize
17
+ import androidx.compose.foundation.layout.fillMaxWidth
18
+ import androidx.compose.foundation.layout.height
19
+ import androidx.compose.foundation.layout.ime
20
+ import androidx.compose.foundation.layout.imePadding
21
+ import androidx.compose.foundation.layout.offset
22
+ import androidx.compose.foundation.layout.padding
23
+ import androidx.compose.foundation.lazy.LazyListState
24
+ import androidx.compose.foundation.lazy.rememberLazyListState
25
+ import androidx.compose.foundation.rememberScrollState
26
+ import androidx.compose.foundation.verticalScroll
27
+ import androidx.compose.material.ExperimentalMaterialApi
28
+ import androidx.compose.runtime.Composable
29
+ import androidx.compose.runtime.CompositionLocalProvider
30
+ import androidx.compose.runtime.LaunchedEffect
31
+ import androidx.compose.runtime.State
32
+ import androidx.compose.runtime.getValue
33
+ import androidx.compose.runtime.mutableIntStateOf
34
+ import androidx.compose.runtime.mutableStateOf
35
+ import androidx.compose.runtime.remember
36
+ import androidx.compose.runtime.rememberUpdatedState
37
+ import androidx.compose.runtime.snapshotFlow
38
+ import androidx.compose.runtime.staticCompositionLocalOf
39
+ import androidx.compose.ui.Alignment
40
+ import androidx.compose.ui.Modifier
41
+ import androidx.compose.ui.graphics.Brush
42
+ import androidx.compose.ui.graphics.Color
43
+ import androidx.compose.ui.graphics.lerp
44
+ import androidx.compose.ui.layout.onGloballyPositioned
45
+ import androidx.compose.ui.platform.LocalDensity
46
+ import androidx.compose.ui.unit.Dp
47
+ import androidx.compose.ui.unit.dp
48
+ import androidx.compose.ui.zIndex
49
+ import kotlinx.coroutines.flow.Flow
50
+ import vn.momo.kits.components.InputSearch
51
+ import vn.momo.kits.const.AppNavigationBar
52
+ import vn.momo.kits.const.AppStatusBar
53
+ import vn.momo.kits.const.AppTheme
54
+ import vn.momo.kits.application.IsShowBaseLineDebug
55
+ import vn.momo.kits.const.Colors
56
+ import vn.momo.kits.const.Spacing
57
+ import vn.momo.kits.modifier.conditional
58
+ import vn.momo.kits.modifier.hideKeyboardOnTap
59
+ import vn.momo.kits.navigation.bottomtab.BOTTOM_TAB_BAR_HEIGHT
60
+ import vn.momo.kits.navigation.component.FABPosition
61
+ import vn.momo.kits.navigation.component.FloatingButton
62
+ import vn.momo.kits.navigation.component.HEADER_HEIGHT
63
+ import vn.momo.kits.navigation.component.Header
64
+ import vn.momo.kits.navigation.component.HeaderBackground
65
+ import vn.momo.kits.navigation.component.HeaderRight
66
+ import vn.momo.kits.navigation.component.HeaderType
67
+ import vn.momo.kits.navigation.component.InputSearchType
68
+ import vn.momo.kits.platform.BackHandler
69
+ import vn.momo.kits.platform.supportsImePadding
70
+ import vn.momo.kits.navigation.tracking.ScreenTracker
71
+ import vn.momo.kits.navigation.tracking.ScreenTrackingState
72
+ import kotlinx.coroutines.delay
73
+ import vn.momo.kits.application.LocalContext
74
+ import kotlin.time.Clock
75
+ import kotlin.time.Duration.Companion.milliseconds
76
+ import kotlin.time.ExperimentalTime
77
+
78
+ internal val LocalFooterHeightPx = staticCompositionLocalOf { mutableIntStateOf(0) }
79
+ internal val LocalHeaderRightWidthPx = staticCompositionLocalOf { mutableIntStateOf(0) }
80
+
81
+ @Composable
82
+ private fun bottomTabBarInset(): Dp {
83
+ if (LocalNavigation.current.bottomTabIndex == -1) return 0.dp
84
+ val keyboard = keyboardSizeState().value
85
+ return (BOTTOM_TAB_BAR_HEIGHT.dp + Spacing.S - keyboard).coerceAtLeast(0.dp)
86
+ }
87
+
88
+ @OptIn(ExperimentalMaterialApi::class, ExperimentalTime::class)
89
+ @Composable
90
+ internal fun StackScreen(
91
+ content: @Composable () -> Unit,
92
+ navigationOptions: NavigationOptions? = null,
93
+ id: Int = -1,
94
+ name: String = "",
95
+ bottomTabIndex: Int = -1,
96
+ onBackHandler: (() -> Unit)? = null,
97
+ ) {
98
+ val navigator = LocalNavigator.current
99
+ val maxApi = LocalMaxApi.current
100
+ val context = LocalContext.current
101
+ val statusBar = AppStatusBar.current
102
+ val density = LocalDensity.current
103
+ val screenRegistry = LocalDynamicScreenRegistry.current
104
+ val navigation = remember { Navigation(id = id, bottomTabIndex = bottomTabIndex, initOptions = navigationOptions, registry = screenRegistry) }
105
+
106
+ val options by navigation.currentOptions
107
+ val isBottomTabChild = bottomTabIndex != -1
108
+ val isBottomTabRoot = navigation.isBottomTabRoot
109
+
110
+ // Auto tracking state
111
+ val trackingState = remember {
112
+ ScreenTrackingState().apply {
113
+ time = Clock.System.now().toEpochMilliseconds()
114
+ }
115
+ }
116
+
117
+ // Determine action: push or back
118
+ val action = remember {
119
+ if (ScreenTracker.getLastScreenName() != null) "push" else "back"
120
+ }
121
+
122
+ // Auto tracking effects
123
+ LaunchedEffect(name) {
124
+ // Track screen navigated immediately
125
+ ScreenTracker.trackScreenNavigated(
126
+ maxApi = maxApi,
127
+ context = context,
128
+ screenName = name,
129
+ action = action,
130
+ state = trackingState
131
+ )
132
+
133
+ // Track screen displayed after 2 seconds (debounce)
134
+ delay(2000.milliseconds)
135
+ val loadTime = Clock.System.now().toEpochMilliseconds() - trackingState.time
136
+ ScreenTracker.trackScreenDisplayed(
137
+ maxApi = maxApi,
138
+ context = context,
139
+ screenName = name,
140
+ duration = loadTime,
141
+ state = trackingState
142
+ )
143
+
144
+ // Track screen interacted after displayed
145
+ val interactionTime = Clock.System.now().toEpochMilliseconds() - trackingState.time
146
+ ScreenTracker.trackScreenInteracted(
147
+ maxApi = maxApi,
148
+ context = context,
149
+ screenName = name,
150
+ duration = interactionTime - loadTime,
151
+ totalDuration = interactionTime,
152
+ state = trackingState
153
+ )
154
+ }
155
+
156
+ val limit = with(density) {
157
+ (statusBar).toPx() + HEADER_HEIGHT
158
+ }.toInt()
159
+
160
+ val (scrollState, scrollInProcess) = if (options.scrollData.scrollState is LazyListState)
161
+ (options.scrollData.scrollState as? LazyListState ?: rememberLazyListState()).proxyScrollState(limit, 15)
162
+ else
163
+ (options.scrollData.scrollState as? ScrollState ?: rememberScrollState()).proxyLimitedScrollState(limit, 15)
164
+
165
+ val footerHeightPx = remember { mutableIntStateOf(0) }
166
+ val headerRightWidthPx = remember { mutableIntStateOf(0) }
167
+
168
+ if (navigation.options.scrollData.scrollToTopCallback != null) {
169
+ RegisterScrollToTop(navigation.options.scrollData.scrollToTopCallback)
170
+ }
171
+
172
+ // Port of RN's `hasCustomBackHandling`: this handler is registered inside the NavHost
173
+ // destination, so while it is enabled it beats NavHost's own predictive-back handler and
174
+ // swallows the swipe. Enable it only when a plain pop is the wrong answer.
175
+ val hasCustomBackHandling = !SwipeBackConfig.enabled ||
176
+ isBottomTabChild ||
177
+ options.onBackHandler != null ||
178
+ options.headerBackProps.preventBack != null ||
179
+ OverplayComponentRegistry.isOverplayShowing() ||
180
+ !navigator.canPop()
181
+
182
+ BackHandler(hasCustomBackHandling) { navigator.onBackSafe() }
183
+
184
+ // TEMPORARY DIAGNOSTIC (DS-760) — remove once the swallowing term is known.
185
+ // While this handler is enabled it out-ranks NavHost's predictive-back handler, so the back
186
+ // still lands on release but nothing seeks: the pop works and the transition is missing,
187
+ // which is exactly what is being reported. The test device has no Xcode, so the one channel
188
+ // known to reach it reports which of the six terms is true. Distinct styles, felt on entering
189
+ // the screen; "medium" means the whole predicate is false and the seek should be running.
190
+ LaunchedEffect(hasCustomBackHandling, options, isBottomTabChild) {
191
+ val api = maxApi ?: return@LaunchedEffect
192
+ val style = when {
193
+ !SwipeBackConfig.enabled -> "heavy"
194
+ isBottomTabChild -> "heavy"
195
+ options.onBackHandler != null -> "rigid"
196
+ options.headerBackProps.preventBack != null -> "soft"
197
+ OverplayComponentRegistry.isOverplayShowing() -> "soft"
198
+ !navigator.canPop() -> "heavy"
199
+ else -> "medium"
200
+ }
201
+ runCatching { api.triggerEventVibration(style, callback = null) }
202
+ }
203
+
204
+ CompositionLocalProvider(
205
+ StackScreenScrollableState provides options.scrollData.scrollState,
206
+ LocalNavigation provides navigation,
207
+ LocalScrollState provides scrollState,
208
+ LocalOptions provides options,
209
+ LocalFooterHeightPx provides footerHeightPx,
210
+ LocalHeaderRightWidthPx provides headerRightWidthPx
211
+ ) {
212
+ Box(
213
+ Modifier
214
+ .fillMaxSize()
215
+ .background(options.backgroundColor ?: AppTheme.current.colors.background.default)
216
+ .conditional(options.keyboardOptions.keyboardShouldPersistTaps) {
217
+ hideKeyboardOnTap()
218
+ }
219
+ .conditional(options.keyboardOptions.useAvoidKeyboard && supportsImePadding()) {
220
+ imePadding()
221
+ }
222
+ ) {
223
+ Box(Modifier.zIndex(1f)) {
224
+ HeaderBackground()
225
+ }
226
+
227
+ Box(Modifier.zIndex(4f)) {
228
+ Header(onBackHandler)
229
+ }
230
+
231
+ Column(Modifier.zIndex(5f)) {
232
+ SearchAnimated(isScrollInProgress = scrollInProcess)
233
+ }
234
+
235
+ Column(Modifier.zIndex(2f).fillMaxSize()) {
236
+ MainContent(content = content, isBottomTabRoot = isBottomTabRoot, isBottomTabChild = isBottomTabChild)
237
+ FooterContent()
238
+ }
239
+
240
+ Box(Modifier.zIndex(6f)) {
241
+ FloatingContent(isBottomTabChild = isBottomTabChild)
242
+ }
243
+
244
+ OverplayView(isBottomTabChild = isBottomTabChild, id = id)
245
+ }
246
+ }
247
+ }
248
+
249
+ @Suppress("FrequentlyChangingValue")
250
+ @Composable
251
+ internal fun FloatingContent(isBottomTabChild: Boolean) {
252
+ val options = LocalOptions.current
253
+ val density = LocalDensity.current
254
+ val footerHeightPx = LocalFooterHeightPx.current
255
+ val scrollState = LocalScrollState.current
256
+ val navigationBar = AppNavigationBar.current
257
+
258
+ val fabProps = options.floatingButtonProps ?: return
259
+ val bottomPadding = fabProps.bottom
260
+ ?: (Spacing.M + when {
261
+ options.hasFooter() -> with(density) { footerHeightPx.intValue.toDp() }
262
+ isBottomTabChild -> bottomTabBarInset() + (navigationBar - keyboardSizeState().value).coerceAtLeast(0.dp)
263
+ else -> navigationBar
264
+ })
265
+
266
+ FloatingButton(
267
+ scrollPosition = fabProps.scrollState?.value ?: scrollState.value,
268
+ onClick = fabProps.onClick,
269
+ containerColor = AppTheme.current.colors.primary,
270
+ bottom = bottomPadding,
271
+ icon = fabProps.icon,
272
+ iconColor = fabProps.iconColor,
273
+ text = fabProps.label,
274
+ size = fabProps.size,
275
+ position = fabProps.position ?: FABPosition.END,
276
+ )
277
+ }
278
+
279
+ @Composable
280
+ internal fun ColumnScope.MainContent(content: @Composable () -> Unit, isBottomTabRoot: Boolean, isBottomTabChild: Boolean) {
281
+ val options = LocalOptions.current
282
+ val inputSearchType = getInputSearchType(options)
283
+ val density = LocalDensity.current
284
+ val scrollState = LocalScrollState.current
285
+ val navigationBar = AppNavigationBar.current
286
+
287
+ Spacer(
288
+ Modifier.height(
289
+ if (options.headerType is HeaderType.DefaultOrExtended || (options.headerType is HeaderType.Transparent && !options.headerType.isFullScreenContent))
290
+ AppStatusBar.current + HEADER_HEIGHT.dp else 0.dp
291
+ )
292
+ )
293
+ if (inputSearchType == InputSearchType.Animated) {
294
+ val scrollDp = with(density) { scrollState.value.toDp() }
295
+
296
+ val animatedTopPadding by animateDpAsState(
297
+ targetValue = (HEADER_HEIGHT.dp - scrollDp).coerceIn(0.dp, HEADER_HEIGHT.dp),
298
+ label = "AnimatedTopPadding"
299
+ )
300
+ Spacer(Modifier.height(animatedTopPadding))
301
+ }
302
+ Column(
303
+ Modifier
304
+ .fillMaxWidth()
305
+ .weight(1f)
306
+ .conditional(options.scrollData.scrollable && options.scrollData.scrollState is ScrollState) {
307
+ verticalScroll(scrollState)
308
+ }
309
+ .padding(
310
+ bottom = when {
311
+ options.hasFooter() || isBottomTabRoot -> 0.dp
312
+ isBottomTabChild -> bottomTabBarInset() + (navigationBar - keyboardSizeState().value).coerceAtLeast(0.dp)
313
+ !options.scrollData.scrollable && options.scrollData.scrollState == null -> 0.dp
314
+ else -> navigationBar
315
+ }
316
+ )
317
+ ) {
318
+ ScreenContent(content = content)
319
+ }
320
+
321
+ }
322
+
323
+ @Composable
324
+ internal fun ScreenContent(content: @Composable () -> Unit) {
325
+ val scrollState = LocalScrollState.current
326
+ val options = LocalOptions.current
327
+
328
+ if (options.headerType is HeaderType.Animated) {
329
+ val animatedHeader = options.headerType
330
+ Box {
331
+ Box(Modifier.fillMaxWidth().aspectRatio(animatedHeader.aspectRatio.value)) {
332
+ animatedHeader.composable.invoke(scrollState.value)
333
+ }
334
+ Box(Modifier.padding(top = AppStatusBar.current + HEADER_HEIGHT.dp + animatedHeader.layoutOffSet)) {
335
+ content()
336
+ }
337
+ }
338
+ } else {
339
+ content()
340
+ }
341
+ }
342
+
343
+ @Composable
344
+ internal fun FooterContent() {
345
+ val options = LocalOptions.current
346
+ if (options.hasFooter()) {
347
+ val keyboardSize = keyboardSizeState()
348
+ val bottomPadding = (AppNavigationBar.current - keyboardSize.value).coerceAtLeast(0.dp)
349
+ Footer(
350
+ footerComponent = options.footerComponent,
351
+ bottomPadding = bottomPadding,
352
+ transparent = options.footerTransparent
353
+ )
354
+ }
355
+ }
356
+
357
+ @Composable
358
+ internal fun keyboardSizeState(): State<Dp> {
359
+ val bottom = WindowInsets.ime.asPaddingValues()
360
+ return rememberUpdatedState(bottom.calculateBottomPadding())
361
+ }
362
+
363
+ @Composable
364
+ internal fun OverplayView(isBottomTabChild: Boolean, id: Int) {
365
+ val overplayType = OverplayComponentRegistry.getOverplayType()
366
+
367
+ if (overplayType != null) {
368
+ Box(Modifier.zIndex(if (overplayType == OverplayComponentType.SNACK_BAR) 3f else 7f).fillMaxSize()) {
369
+ if (isBottomTabChild) return@Box
370
+ if (OverplayComponentRegistry.currentRootId() != id) return@Box
371
+ OverplayComponentRegistry.OverlayComponent()
372
+ }
373
+ }
374
+ }
375
+
376
+ @Composable
377
+ fun Footer(footerComponent: @Composable (() -> Unit)?, bottomPadding: Dp, transparent: Boolean = false) {
378
+ if (footerComponent == null) return
379
+
380
+ val footerHeightPx = LocalFooterHeightPx.current
381
+
382
+ val shadowBrush = remember {
383
+ Brush.verticalGradient(
384
+ colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.05f))
385
+ )
386
+ }
387
+
388
+ val backgroundColor = if (transparent) Color.Transparent else AppTheme.current.colors.background.surface
389
+
390
+ Box(Modifier.onGloballyPositioned {
391
+ if (footerHeightPx.intValue != it.size.height) footerHeightPx.intValue = it.size.height
392
+ }) {
393
+ Box(
394
+ Modifier
395
+ .fillMaxWidth()
396
+ .background(backgroundColor)
397
+ .conditional(IsShowBaseLineDebug) {
398
+ border(1.dp, Colors.blue_03)
399
+ }
400
+ .padding(top = Spacing.S, start = Spacing.M, end = Spacing.M, bottom = bottomPadding + Spacing.S)
401
+ ) {
402
+ footerComponent.invoke()
403
+ }
404
+
405
+ if (!transparent) {
406
+ Box(
407
+ modifier = Modifier
408
+ .fillMaxWidth()
409
+ .height(6.dp)
410
+ .offset(x = 0.dp, y = (-6).dp)
411
+ .background(shadowBrush)
412
+ )
413
+ }
414
+ }
415
+ }
416
+
417
+ data class InputSearchLayoutParams(
418
+ val topPadding: Dp,
419
+ val startPadding: Dp,
420
+ val endPadding: Dp
421
+ )
422
+
423
+ @Suppress("FrequentlyChangingValue")
424
+ @Composable
425
+ internal fun SearchAnimated(
426
+ isScrollInProgress: Boolean
427
+ ) {
428
+ val scrollState = LocalScrollState.current
429
+ val options = LocalOptions.current
430
+ val navigator = LocalNavigator.current
431
+ val density = LocalDensity.current
432
+
433
+ val scrollDp = with(density) { scrollState.value.toDp() }
434
+
435
+ val inputSearchType = getInputSearchType(options)
436
+ val headerRightWidthPx = LocalHeaderRightWidthPx.current
437
+ val headerRightWidthDp = with(density) { headerRightWidthPx.intValue.toDp() }
438
+
439
+ if (inputSearchType == InputSearchType.None) return
440
+ val inputSearchProps = (options.headerType as? HeaderType.DefaultOrExtended)?.inputSearchProps ?: return
441
+
442
+ val minTopPadding = AppStatusBar.current
443
+ val maxTopPadding = AppStatusBar.current + HEADER_HEIGHT.dp
444
+ val minStartPadding = Spacing.M
445
+ val maxStartPadding = if (options.hiddenBack) Spacing.M else 48.dp // button back: size + left +right = 28 + 12 + 8 = 48
446
+ val minEndPadding = Spacing.M
447
+ val maxEndPadding = headerRightWidthDp + if (options.headerRight is HeaderRight.None) Spacing.M else Spacing.M * 2
448
+
449
+ val targetColor = lerp(
450
+ AppTheme.current.colors.background.surface,
451
+ AppTheme.current.colors.background.default,
452
+ (scrollDp / minTopPadding).coerceIn(0f, 1f)
453
+ )
454
+ val animatedColor by animateColorAsState(targetValue = targetColor, label = "BackgroundColor")
455
+
456
+ val layoutParams = when (inputSearchType) {
457
+ InputSearchType.Header -> {
458
+ InputSearchLayoutParams(
459
+ topPadding = minTopPadding,
460
+ startPadding = maxStartPadding,
461
+ endPadding = maxEndPadding
462
+ )
463
+ }
464
+
465
+ InputSearchType.Animated -> {
466
+ val animatedTopPadding by animateDpAsState(
467
+ targetValue = (maxTopPadding - scrollDp).coerceIn(minTopPadding, maxTopPadding),
468
+ label = "AnimatedTopPadding"
469
+ )
470
+
471
+ val animatedStartPadding by animateDpAsState(
472
+ targetValue = (minStartPadding + scrollDp).coerceIn(minStartPadding, maxStartPadding),
473
+ label = "AnimatedStartPadding"
474
+ )
475
+
476
+ val animatedEndPadding by animateDpAsState(
477
+ targetValue = (minEndPadding + scrollDp).coerceIn(minEndPadding, maxEndPadding),
478
+ label = "AnimatedEndPadding"
479
+ )
480
+
481
+ val maxPadding = remember(maxTopPadding, maxStartPadding, maxEndPadding) {
482
+ maxOf(maxEndPadding, maxStartPadding, maxTopPadding)
483
+ }
484
+ val snapScrollValue = with(density) { maxPadding.toPx().toInt() }
485
+
486
+ LaunchedEffect(isScrollInProgress && scrollState.value != 0 && scrollState.value != snapScrollValue) {
487
+ if (scrollDp < maxPadding) {
488
+ if (!isScrollInProgress) {
489
+ val midpoint = (maxTopPadding - minTopPadding) / 2
490
+
491
+ if (scrollDp < midpoint) {
492
+ scrollState.animateScrollTo(0)
493
+ } else {
494
+ scrollState.animateScrollTo(snapScrollValue)
495
+ }
496
+ }
497
+ }
498
+ }
499
+
500
+ InputSearchLayoutParams(
501
+ topPadding = animatedTopPadding,
502
+ startPadding = animatedStartPadding,
503
+ endPadding = animatedEndPadding
504
+ )
505
+ }
506
+
507
+ InputSearchType.None -> return
508
+ }
509
+
510
+ Spacer(Modifier.height(layoutParams.topPadding))
511
+ Box(
512
+ modifier = Modifier
513
+ .height(HEADER_HEIGHT.dp)
514
+ .fillMaxWidth()
515
+ .padding(
516
+ start = layoutParams.startPadding,
517
+ end = layoutParams.endPadding
518
+ ),
519
+ contentAlignment = Alignment.Center
520
+ ) {
521
+ InputSearch(
522
+ inputSearchProps = inputSearchProps.copy(
523
+ backgroundColor = animatedColor,
524
+ onPressButtonText = {
525
+ navigator.pop()
526
+ }
527
+ )
528
+ )
529
+ }
530
+ }
531
+
532
+ private fun quantize(value: Int, stepPx: Int): Int {
533
+ if (stepPx <= 1) return value
534
+ return (value / stepPx) * stepPx
535
+ }
536
+
537
+ @Composable
538
+ internal fun LazyListState.proxyScrollState(
539
+ thresholdPx: Int = 200,
540
+ stepPx: Int = 4
541
+ ): Pair<ScrollState, Boolean> = proxyScroll(
542
+ source = this,
543
+ thresholdPx = thresholdPx,
544
+ stepPx = stepPx,
545
+ isScrollInProgress = { isScrollInProgress },
546
+ rawTargetFlow = {
547
+ snapshotFlow {
548
+ if (firstVisibleItemIndex == 0) firstVisibleItemScrollOffset
549
+ else SCROLLED_PAST_FIRST_ITEM_THRESHOLD
550
+ }
551
+ },
552
+ )
553
+
554
+ @Composable
555
+ internal fun ScrollState.proxyLimitedScrollState(
556
+ thresholdPx: Int = 200,
557
+ stepPx: Int = 4
558
+ ): Pair<ScrollState, Boolean> = proxyScroll(
559
+ source = this,
560
+ thresholdPx = thresholdPx,
561
+ stepPx = stepPx,
562
+ isScrollInProgress = { isScrollInProgress },
563
+ rawTargetFlow = { snapshotFlow { value } },
564
+ )
565
+
566
+ @Composable
567
+ private fun proxyScroll(
568
+ source: Any,
569
+ thresholdPx: Int,
570
+ stepPx: Int,
571
+ isScrollInProgress: () -> Boolean,
572
+ rawTargetFlow: () -> Flow<Int>,
573
+ ): Pair<ScrollState, Boolean> {
574
+ val proxy = rememberScrollState()
575
+ val locked = remember { mutableStateOf(false) }
576
+
577
+ LaunchedEffect(source, proxy, thresholdPx, stepPx) {
578
+ rawTargetFlow().collect { rawTarget ->
579
+ val shouldLock = rawTarget > thresholdPx
580
+ if (locked.value != shouldLock) locked.value = shouldLock
581
+
582
+ val desired = if (shouldLock) thresholdPx else quantize(rawTarget, stepPx)
583
+
584
+ if (proxy.value != desired) {
585
+ proxy.scrollTo(desired.coerceAtLeast(0))
586
+ }
587
+ }
588
+ }
589
+
590
+ val inProgress = remember { mutableStateOf(false) }
591
+ LaunchedEffect(source, thresholdPx) {
592
+ snapshotFlow { isScrollInProgress() }
593
+ .collect { progressing ->
594
+ inProgress.value = if (locked.value) false else progressing
595
+ }
596
+ }
597
+
598
+ return proxy to inProgress.value
599
+ }
600
+
601
+ private const val SCROLLED_PAST_FIRST_ITEM_THRESHOLD = 10_000
602
+
603
+ internal val LocalScrollState = staticCompositionLocalOf<ScrollState> { error("No Scroll State provided") }
604
+ internal val LocalOptions = staticCompositionLocalOf<NavigationOptions> { error("No NavigationOptions provided") }
605
+
606
+ val StackScreenScrollableState = staticCompositionLocalOf<ScrollableState?> { null }
607
+
608
+ internal fun getInputSearchType(options: NavigationOptions): InputSearchType {
609
+ return when (val headerType = options.headerType) {
610
+ is HeaderType.DefaultOrExtended -> when {
611
+ headerType.inputSearchProps == null -> InputSearchType.None
612
+ headerType.useAnimated -> InputSearchType.Animated
613
+ else -> InputSearchType.Header
614
+ }
615
+
616
+ else -> InputSearchType.None
617
+ }
618
+ }
619
+