@momo-kits/native-kits 0.167.1-duo.4-debug → 0.167.1-duo.5

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