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

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