@momo-kits/native-kits 0.160.1-searchinput.2 → 0.160.1-test.1-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.
- package/.claude/settings.local.json +15 -0
- package/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +180 -0
- package/compose/build.gradle.kts.backup +180 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +117 -0
- package/compose/src/commonMain/composeResources/font/momosignature.otf +0 -0
- package/compose/src/commonMain/composeResources/font/momotrustdisplay.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_black.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_bold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_heavy.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_light.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_medium.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_regular.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_semibold.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_thin.ttf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.otf +0 -0
- package/compose/src/commonMain/composeResources/font/sfprotext_ultralight.ttf +0 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/AnimationSearchInput.kt +57 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +109 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/FloatingButton.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Header.kt +222 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderAnimated.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderBackground.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderDefault.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderExtended.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderRight.kt +305 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/HeaderTitle.kt +33 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +720 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +121 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +403 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/useHeaderSearchAnimation.kt +69 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +85 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +340 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +198 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +357 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +123 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +94 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +136 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +543 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +23 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +148 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +116 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +448 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +172 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +255 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +231 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +233 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +254 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +241 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +364 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +92 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +352 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +70 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +96 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +348 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +256 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +494 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +131 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +215 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +96 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +531 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +92 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +130 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +214 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +590 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +177 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +192 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +239 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +191 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +306 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +188 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +285 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +2 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +2 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +57 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +68 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +14 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +253 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +99 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +141 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +346 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +558 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +161 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +243 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +279 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +80 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +306 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +370 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +131 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +62 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +105 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +180 -0
- package/gradle/libs.versions.toml +58 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +26 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- package/local.properties +8 -0
- package/package.json +1 -1
- package/settings.gradle.kts +52 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.layout.Box
|
|
4
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
5
|
+
import androidx.compose.runtime.Composable
|
|
6
|
+
import androidx.compose.runtime.MutableState
|
|
7
|
+
import androidx.compose.runtime.mutableStateOf
|
|
8
|
+
import androidx.compose.runtime.staticCompositionLocalOf
|
|
9
|
+
import androidx.compose.ui.Alignment
|
|
10
|
+
import androidx.compose.ui.Modifier
|
|
11
|
+
import androidx.navigation.NavController
|
|
12
|
+
import kotlinx.coroutines.CoroutineScope
|
|
13
|
+
import kotlinx.coroutines.Dispatchers
|
|
14
|
+
import kotlinx.coroutines.SupervisorJob
|
|
15
|
+
import kotlinx.coroutines.cancel
|
|
16
|
+
import kotlinx.coroutines.delay
|
|
17
|
+
import kotlinx.coroutines.launch
|
|
18
|
+
import kotlinx.serialization.Serializable
|
|
19
|
+
import vn.momo.kits.components.PopupAction
|
|
20
|
+
import vn.momo.kits.components.PopupNotify
|
|
21
|
+
import vn.momo.kits.navigation.BottomHeader.*
|
|
22
|
+
import vn.momo.kits.navigation.component.SnackBar
|
|
23
|
+
import vn.momo.maxapi.IMaxApi
|
|
24
|
+
|
|
25
|
+
class Navigator(
|
|
26
|
+
private val navController: NavController,
|
|
27
|
+
private val maxApi: IMaxApi?
|
|
28
|
+
) {
|
|
29
|
+
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
|
30
|
+
|
|
31
|
+
internal var currentScreenId: Int = -1
|
|
32
|
+
private set
|
|
33
|
+
|
|
34
|
+
internal fun setCurrentScreenId(id: Int) {
|
|
35
|
+
currentScreenId = id
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
fun push(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
39
|
+
val route = DynamicScreenRegistry.register(screenName, content, options)
|
|
40
|
+
navController.navigate(DynamicScreenRoute(route.id))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
fun replace(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
44
|
+
if (navController.previousBackStackEntry != null){
|
|
45
|
+
val latestScreen = DynamicScreenRegistry.getLatestScreen()
|
|
46
|
+
latestScreen?.let { DynamicScreenRegistry.unregisterScreen(it.id) }
|
|
47
|
+
navController.popBackStack()
|
|
48
|
+
push(screenName, content, options)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun onBackSafe(callBack: (() -> Unit)? = null) {
|
|
53
|
+
val latestScreen = DynamicScreenRegistry.getLatestScreen()
|
|
54
|
+
val options = latestScreen?.options
|
|
55
|
+
if (options?.onBackHandler != null) {
|
|
56
|
+
options.onBackHandler.invoke()
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
val preventBack = options?.headerBackProps?.preventBack
|
|
60
|
+
if (preventBack != null) {
|
|
61
|
+
showModal(
|
|
62
|
+
content = {
|
|
63
|
+
PopupNotify(preventBack.copy(
|
|
64
|
+
primary = PopupAction(
|
|
65
|
+
title = preventBack.primary?.title ?: "",
|
|
66
|
+
onPress = {
|
|
67
|
+
preventBack.primary?.onPress?.invoke()
|
|
68
|
+
pop(2, callBack) // close popup notify, then close the screen
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
))
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
} else {
|
|
75
|
+
pop(1, callBack)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fun pop(count: Int = 1, callBack: (() -> Unit)? = null) {
|
|
80
|
+
scope.launch {
|
|
81
|
+
repeat(count) {
|
|
82
|
+
if (OverplayComponentRegistry.getOverplayType() == OverplayComponentType.SNACK_BAR){
|
|
83
|
+
dismissScreen()
|
|
84
|
+
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
85
|
+
}
|
|
86
|
+
else if (OverplayComponentRegistry.isOverplayShowing()){
|
|
87
|
+
dismissOverplay()
|
|
88
|
+
} else {
|
|
89
|
+
dismissScreen()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
callBack?.invoke()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
private suspend fun dismissOverplay(isDelay: Boolean = true) {
|
|
96
|
+
OverplayComponentRegistry.clear()
|
|
97
|
+
if (isDelay) delay(300L)
|
|
98
|
+
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private suspend fun dismissScreen() {
|
|
102
|
+
if (navController.previousBackStackEntry != null){
|
|
103
|
+
navController.popBackStack()
|
|
104
|
+
delay(300L)
|
|
105
|
+
DynamicScreenRegistry.getLatestScreen()?.let { it1 ->
|
|
106
|
+
DynamicScreenRegistry.unregisterScreen(it1.id)
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
maxApi?.dismiss { }
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fun present(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
114
|
+
val route = DynamicScreenRegistry.register(screenName, content, options)
|
|
115
|
+
navController.navigate(DynamicDialogRoute(route.id))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
fun reset(screenName: String, content: @Composable () -> Unit, options: NavigationOptions? = null) {
|
|
119
|
+
DynamicScreenRegistry.unregisterAll()
|
|
120
|
+
|
|
121
|
+
val route = DynamicScreenRegistry.register(screenName, content, options)
|
|
122
|
+
navController.navigate(DynamicScreenRoute(route.id)) {
|
|
123
|
+
popUpTo(0) { inclusive = true }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fun showModal(
|
|
128
|
+
content: @Composable () -> Unit,
|
|
129
|
+
barrierDismissible: Boolean = true,
|
|
130
|
+
onDismiss: (() -> Unit)? = null
|
|
131
|
+
){
|
|
132
|
+
// AI-GENERATED START: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
133
|
+
val id = currentScreenId.takeIf { it != -1 } ?: DynamicScreenRegistry.getLatestScreen()?.id ?: -1
|
|
134
|
+
// AI-GENERATED END: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
135
|
+
OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.MODAL, false, barrierDismissible, onDismiss)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
fun showBottomSheet(
|
|
139
|
+
content: @Composable () -> Unit,
|
|
140
|
+
isSurface: Boolean = false,
|
|
141
|
+
barrierDismissible: Boolean = true,
|
|
142
|
+
onDismiss: (() -> Unit)? = null,
|
|
143
|
+
bottomSheetHeader: BottomHeader? = null
|
|
144
|
+
){
|
|
145
|
+
// AI-GENERATED START: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
146
|
+
val id = currentScreenId.takeIf { it != -1 } ?: DynamicScreenRegistry.getLatestScreen()?.id ?: -1
|
|
147
|
+
// AI-GENERATED END: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
148
|
+
OverplayComponentRegistry.registerOverplay(id, content, OverplayComponentType.BOTTOM_SHEET, isSurface, barrierDismissible, onDismiss, bottomSheetHeader)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
fun showSnackBar(snackBar: SnackBar, onDismiss: (() -> Unit)? = null) {
|
|
152
|
+
// AI-GENERATED START: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
153
|
+
val id = currentScreenId.takeIf { it != -1 } ?: DynamicScreenRegistry.getLatestScreen()?.id ?: -1
|
|
154
|
+
// AI-GENERATED END: use per-Navigator currentScreenId; fall back to global registry if not yet set
|
|
155
|
+
scope.launch {
|
|
156
|
+
OverplayComponentRegistry.registerOverplay(
|
|
157
|
+
id = id,
|
|
158
|
+
content = {
|
|
159
|
+
SnackBar(snackBar, onDismiss)
|
|
160
|
+
},
|
|
161
|
+
type = OverplayComponentType.SNACK_BAR,
|
|
162
|
+
onDismiss = onDismiss
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fun hideSnackBar() {
|
|
168
|
+
scope.launch {
|
|
169
|
+
OverplayComponentRegistry.clear()
|
|
170
|
+
delay(250L)
|
|
171
|
+
OverplayComponentRegistry.hardClearAfterDismiss()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fun dispose(){
|
|
176
|
+
scope.cancel()
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
val LocalNavigator = staticCompositionLocalOf<Navigator> {
|
|
181
|
+
error("No NavigationStack provided")
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@Serializable
|
|
185
|
+
data class DynamicScreenRoute(val id: Int)
|
|
186
|
+
|
|
187
|
+
@Serializable
|
|
188
|
+
data class DynamicDialogRoute(val id: Int)
|
|
189
|
+
|
|
190
|
+
data class DynamicScreen(
|
|
191
|
+
val id: Int,
|
|
192
|
+
val name: String,
|
|
193
|
+
val content: @Composable () -> Unit,
|
|
194
|
+
var options: NavigationOptions? = null
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
object DynamicScreenRegistry {
|
|
198
|
+
private val screens = mutableMapOf<Int, DynamicScreen>()
|
|
199
|
+
private var idCounter = 1
|
|
200
|
+
|
|
201
|
+
fun register(screenName: String, content: @Composable () -> Unit, options: NavigationOptions?): DynamicScreenRoute {
|
|
202
|
+
val id = idCounter++
|
|
203
|
+
screens[id] = DynamicScreen(
|
|
204
|
+
id = id,
|
|
205
|
+
name = screenName,
|
|
206
|
+
content = content,
|
|
207
|
+
options = options
|
|
208
|
+
)
|
|
209
|
+
return DynamicScreenRoute(id)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
fun unregisterScreen(id: Int) {
|
|
213
|
+
screens.remove(id)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
fun getLatestScreen(): DynamicScreen?{
|
|
217
|
+
return screens.entries.lastOrNull()?.value
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
fun unregisterAll(){
|
|
221
|
+
val ids = screens.keys.toList()
|
|
222
|
+
for (id in ids) {
|
|
223
|
+
unregisterScreen(id)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
fun getScreen(id: Int): DynamicScreen? = screens[id]
|
|
228
|
+
|
|
229
|
+
fun setOptions(id: Int, options: NavigationOptions){
|
|
230
|
+
screens[id]?.options = options
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
sealed class OverplayComponentParams {
|
|
236
|
+
class Modal(
|
|
237
|
+
val onDismiss: (() -> Unit)? = null,
|
|
238
|
+
val barrierDismissible: Boolean = true
|
|
239
|
+
) : OverplayComponentParams()
|
|
240
|
+
|
|
241
|
+
class BottomSheet(
|
|
242
|
+
val isSurface: Boolean = false,
|
|
243
|
+
val onDismiss: (() -> Unit)? = null,
|
|
244
|
+
val barrierDismissible: Boolean = true,
|
|
245
|
+
val bottomSheetHeader: BottomHeader? = null,
|
|
246
|
+
) : OverplayComponentParams()
|
|
247
|
+
|
|
248
|
+
class SnackBar() : OverplayComponentParams()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
data class OverplayComponent(
|
|
252
|
+
val id: Int,
|
|
253
|
+
val type: OverplayComponentType? = null,
|
|
254
|
+
val content: @Composable () -> Unit,
|
|
255
|
+
val params: OverplayComponentParams? = null
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
enum class OverplayComponentType {
|
|
259
|
+
MODAL, BOTTOM_SHEET, SNACK_BAR
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
object OverplayComponentRegistry {
|
|
263
|
+
private var currentOverlayComponent : MutableState<OverplayComponent?> = mutableStateOf(null)
|
|
264
|
+
private var requestClose: (() -> Unit)? = null
|
|
265
|
+
internal fun bindClose(handler: (() -> Unit)?) {
|
|
266
|
+
requestClose = handler
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fun registerOverplay(
|
|
270
|
+
id: Int,
|
|
271
|
+
content: @Composable () -> Unit,
|
|
272
|
+
type: OverplayComponentType,
|
|
273
|
+
isSurface: Boolean = false,
|
|
274
|
+
barrierDismissible: Boolean = true,
|
|
275
|
+
onDismiss: (() -> Unit)?,
|
|
276
|
+
bottomSheetHeader: BottomHeader? = null,
|
|
277
|
+
){
|
|
278
|
+
val params = when(type){
|
|
279
|
+
OverplayComponentType.MODAL -> OverplayComponentParams.Modal(onDismiss, barrierDismissible)
|
|
280
|
+
OverplayComponentType.BOTTOM_SHEET -> OverplayComponentParams.BottomSheet(isSurface, onDismiss, barrierDismissible, bottomSheetHeader)
|
|
281
|
+
OverplayComponentType.SNACK_BAR -> OverplayComponentParams.SnackBar()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
currentOverlayComponent.value = OverplayComponent(
|
|
285
|
+
id = id,
|
|
286
|
+
type = type,
|
|
287
|
+
content = content,
|
|
288
|
+
params = params
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
fun isOverplayShowing(): Boolean = currentOverlayComponent.value != null
|
|
293
|
+
|
|
294
|
+
fun getOverplayType(): OverplayComponentType? = currentOverlayComponent.value?.type
|
|
295
|
+
|
|
296
|
+
fun currentRootId(): Int? = currentOverlayComponent.value?.id
|
|
297
|
+
|
|
298
|
+
fun clear(){
|
|
299
|
+
if (requestClose != null) {
|
|
300
|
+
requestClose?.invoke()
|
|
301
|
+
} else {
|
|
302
|
+
currentOverlayComponent.value = null
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
internal fun hardClearAfterDismiss() {
|
|
307
|
+
currentOverlayComponent.value = null
|
|
308
|
+
requestClose = null
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
@Composable
|
|
312
|
+
fun OverlayComponent(){
|
|
313
|
+
val overplay = currentOverlayComponent.value ?: return
|
|
314
|
+
|
|
315
|
+
when (val params = overplay.params) {
|
|
316
|
+
is OverplayComponentParams.BottomSheet -> {
|
|
317
|
+
BottomSheet(
|
|
318
|
+
content = overplay.content,
|
|
319
|
+
header = params.bottomSheetHeader ?: Title(),
|
|
320
|
+
isSurface = params.isSurface,
|
|
321
|
+
barrierDismissible = params.barrierDismissible,
|
|
322
|
+
onDismiss = params.onDismiss
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
is OverplayComponentParams.Modal -> {
|
|
327
|
+
ModalScreen(
|
|
328
|
+
content = overplay.content,
|
|
329
|
+
barrierDismissible = params.barrierDismissible,
|
|
330
|
+
onDismiss = params.onDismiss
|
|
331
|
+
)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
is OverplayComponentParams.SnackBar -> {
|
|
335
|
+
Box(
|
|
336
|
+
modifier = Modifier.fillMaxSize(),
|
|
337
|
+
contentAlignment = Alignment.BottomCenter
|
|
338
|
+
) {
|
|
339
|
+
overplay.content()
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
null -> {}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|