@momo-kits/native-kits 0.112.1-beta.7 → 0.112.1-beta.9
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/compose/src/commonMain/kotlin/vn/momo/kits/{components → application}/HeaderRight.kt +10 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/NavigationContainer.kt +13 -30
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Screen.kt +0 -1
- package/package.json +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/ModelConverter.kt +0 -82
package/compose/src/commonMain/kotlin/vn/momo/kits/{components → application}/HeaderRight.kt
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package vn.momo.kits.
|
|
1
|
+
package vn.momo.kits.application
|
|
2
2
|
|
|
3
3
|
import androidx.compose.foundation.background
|
|
4
4
|
import androidx.compose.foundation.border
|
|
@@ -23,11 +23,10 @@ import androidx.compose.ui.Modifier
|
|
|
23
23
|
import androidx.compose.ui.draw.clip
|
|
24
24
|
import androidx.compose.ui.graphics.Color
|
|
25
25
|
import androidx.compose.ui.unit.dp
|
|
26
|
-
import vn.momo.kits.
|
|
27
|
-
import vn.momo.kits.
|
|
28
|
-
import vn.momo.kits.
|
|
26
|
+
import vn.momo.kits.components.BadgeDot
|
|
27
|
+
import vn.momo.kits.components.DotSize
|
|
28
|
+
import vn.momo.kits.components.Icon
|
|
29
29
|
import vn.momo.kits.const.Colors
|
|
30
|
-
import vn.momo.kits.utils.ModelConvertUtils
|
|
31
30
|
|
|
32
31
|
data class HeaderRightData(
|
|
33
32
|
val useOnBoarding: Boolean = false,
|
|
@@ -82,19 +81,20 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
82
81
|
val context = ApplicationContext.current
|
|
83
82
|
|
|
84
83
|
fun onPressShortcut() {
|
|
85
|
-
|
|
84
|
+
api?.request("onToolAction", mapOf("item" to mapOf("key" to "onFavorite"))) {
|
|
85
|
+
isFavorite = !isFavorite
|
|
86
|
+
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
fun onPressHelpCenter() {
|
|
89
|
-
val paramMap
|
|
90
|
+
val paramMap = mapOf(
|
|
90
91
|
"appId" to context?.appId,
|
|
91
92
|
"code" to context?.code,
|
|
92
93
|
"name" to context?.name,
|
|
93
94
|
"icon" to context?.icon,
|
|
94
95
|
"description" to context?.description
|
|
95
96
|
)
|
|
96
|
-
|
|
97
|
-
api?.request("showHelpCenter", params, { _ -> })
|
|
97
|
+
api?.request("showHelpCenter", paramMap, { _ -> })
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
fun onPressClose() {
|
|
@@ -102,7 +102,7 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
fun onPressMore() {
|
|
105
|
-
val
|
|
105
|
+
val params = listOf(
|
|
106
106
|
headerRight?.tools ?: emptyList<ToolGroup>(),
|
|
107
107
|
mapOf(
|
|
108
108
|
"appId" to context?.appId,
|
|
@@ -113,7 +113,6 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
|
|
|
113
113
|
)
|
|
114
114
|
)
|
|
115
115
|
|
|
116
|
-
val params = ModelConvertUtils.encodeToJsonFromAny(param).toString()
|
|
117
116
|
api?.request("showTools", params, { _ -> })
|
|
118
117
|
}
|
|
119
118
|
|
|
@@ -23,42 +23,25 @@ import vn.momo.kits.platform.disableOverscroll
|
|
|
23
23
|
import vn.momo.kits.platform.getStatusBarHeight
|
|
24
24
|
|
|
25
25
|
interface ComposeApi {
|
|
26
|
-
fun request(funcName: String, params:
|
|
27
|
-
fun request(funcName: String, params:
|
|
28
|
-
fun requestCallback(funcName: String, params:
|
|
26
|
+
fun request(funcName: String, params: Any?): String
|
|
27
|
+
fun request(funcName: String, params: Any?, onResponse: ((String) -> Unit)?): String
|
|
28
|
+
fun requestCallback(funcName: String, params: Any?, onResponse: ((String) -> Unit)?)
|
|
29
29
|
fun removeCallback(id: String)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
class Navigator {
|
|
33
|
-
fun push(content: @Composable () -> Unit) {
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fun
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fun reset(content: @Composable () -> Unit) {
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fun pop() {
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
fun replace(content: @Composable () -> Unit) {
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
fun popToTop() {
|
|
51
|
-
}
|
|
52
|
-
|
|
33
|
+
fun push(content: @Composable () -> Unit) {}
|
|
34
|
+
fun present(content: @Composable () -> Unit) {}
|
|
35
|
+
fun reset(content: @Composable () -> Unit) {}
|
|
36
|
+
fun pop() {}
|
|
37
|
+
fun replace(content: @Composable () -> Unit) {}
|
|
38
|
+
fun popToTop() {}
|
|
53
39
|
fun showModal(
|
|
54
40
|
onClose: () -> Unit = {},
|
|
55
41
|
canBackgroundClose: Boolean = true,
|
|
56
42
|
content: @Composable () -> Unit,
|
|
57
|
-
) {
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fun showBottomSheet(content: @Composable () -> Unit) {
|
|
61
|
-
}
|
|
43
|
+
) {}
|
|
44
|
+
fun showBottomSheet(content: @Composable () -> Unit) {}
|
|
62
45
|
}
|
|
63
46
|
|
|
64
47
|
data class MiniAppContext(
|
|
@@ -85,7 +68,7 @@ fun ApplicationContainer(
|
|
|
85
68
|
composeApi: ComposeApi? = null,
|
|
86
69
|
statusBarHeight: Dp? = AppStatusBar.current ?: getStatusBarHeight(),
|
|
87
70
|
applicationContext: MiniAppContext? = null,
|
|
88
|
-
content: @Composable () -> Unit
|
|
71
|
+
content: @Composable () -> Unit,
|
|
89
72
|
) {
|
|
90
73
|
var appTheme by remember { mutableStateOf(theme) }
|
|
91
74
|
val coroutineScope = rememberCoroutineScope()
|
|
@@ -121,7 +104,7 @@ fun ApplicationContainer(
|
|
|
121
104
|
PlatformApi provides composeApi,
|
|
122
105
|
AppNavigator provides Navigator(),
|
|
123
106
|
AppStatusBar provides statusBarHeight,
|
|
124
|
-
ApplicationContext provides applicationContext
|
|
107
|
+
ApplicationContext provides applicationContext,
|
|
125
108
|
) {
|
|
126
109
|
content()
|
|
127
110
|
}
|
package/package.json
CHANGED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
package vn.momo.kits.utils
|
|
2
|
-
|
|
3
|
-
import kotlinx.serialization.json.Json
|
|
4
|
-
import kotlinx.serialization.json.JsonArray
|
|
5
|
-
import kotlinx.serialization.json.JsonElement
|
|
6
|
-
import kotlinx.serialization.json.JsonNull
|
|
7
|
-
import kotlinx.serialization.json.JsonObject
|
|
8
|
-
import kotlinx.serialization.json.JsonPrimitive
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
object ModelConvertUtils {
|
|
12
|
-
private const val discriminator = "momoClassDiscriminator"
|
|
13
|
-
val formatter = Json {
|
|
14
|
-
encodeDefaults = true
|
|
15
|
-
ignoreUnknownKeys = true
|
|
16
|
-
classDiscriminator = discriminator
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
fun encodeToJson(data: String?): JsonElement? = try {
|
|
20
|
-
formatter.parseToJsonElement(data ?: "")
|
|
21
|
-
} catch (e: Throwable) {
|
|
22
|
-
null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
fun encodeToJson(data: Collection<*>): JsonElement {
|
|
26
|
-
val parsedData = mutableListOf<JsonElement>()
|
|
27
|
-
data.forEach { value ->
|
|
28
|
-
when (value) {
|
|
29
|
-
is Map<*, *> -> parsedData.add(encodeToJson(value))
|
|
30
|
-
is Collection<*> -> parsedData.add(encodeToJson(value))
|
|
31
|
-
is Number -> parsedData.add(JsonPrimitive(value))
|
|
32
|
-
is Boolean -> parsedData.add(JsonPrimitive(value))
|
|
33
|
-
is String -> parsedData.add(JsonPrimitive(value))
|
|
34
|
-
is Enum<*> -> encodeToJson(value.name)?.let { parsedData.add(it) }
|
|
35
|
-
is JsonPrimitive -> parsedData.add(value)
|
|
36
|
-
is JsonElement -> parsedData.add(value)
|
|
37
|
-
null -> parsedData.add(JsonNull)
|
|
38
|
-
else -> throw IllegalStateException("Can't serialize unknown collection type: $value")
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return JsonArray(parsedData)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fun encodeToJson(data: Map<*, *>): JsonElement {
|
|
45
|
-
val parsedData = mutableMapOf<String, JsonElement>()
|
|
46
|
-
data.forEach { (key, value) ->
|
|
47
|
-
if (key is String && value != null) {
|
|
48
|
-
when (value) {
|
|
49
|
-
is Map<*, *> -> parsedData[key] = encodeToJson(value)
|
|
50
|
-
is Collection<*> -> parsedData[key] = encodeToJson(value)
|
|
51
|
-
is Number -> parsedData[key] = JsonPrimitive(value)
|
|
52
|
-
is Boolean -> parsedData[key] = JsonPrimitive(value)
|
|
53
|
-
is String -> parsedData[key] = JsonPrimitive(value)
|
|
54
|
-
is Enum<*> -> encodeToJson(value.name)?.let { parsedData[key] = it }
|
|
55
|
-
is Array<*> -> parsedData[key] = encodeToJsonFromArray(value)
|
|
56
|
-
is JsonPrimitive -> parsedData[key] = value
|
|
57
|
-
is JsonElement -> parsedData[key] = value
|
|
58
|
-
else -> throw IllegalStateException("Can't serialize unknown type: $value")
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return JsonObject(parsedData)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
fun encodeToJsonFromAny(data: Any): JsonElement {
|
|
66
|
-
return when (data) {
|
|
67
|
-
is Map<*, *> -> encodeToJson(data)
|
|
68
|
-
is Collection<*> -> encodeToJson(data)
|
|
69
|
-
is Number -> JsonPrimitive(data)
|
|
70
|
-
is Boolean -> JsonPrimitive(data)
|
|
71
|
-
is String -> JsonPrimitive(data)
|
|
72
|
-
is Enum<*> -> encodeToJson(data.name) ?: JsonNull
|
|
73
|
-
is Array<*> -> encodeToJsonFromArray(data)
|
|
74
|
-
is JsonElement -> data
|
|
75
|
-
else -> JsonNull
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private fun encodeToJsonFromArray(data: Array<*>): JsonArray =
|
|
80
|
-
JsonArray(data.filterNotNull().map { encodeToJsonFromAny(it) })
|
|
81
|
-
|
|
82
|
-
}
|