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