@momo-kits/native-kits 0.112.1-beta.1 → 0.112.1-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.
@@ -242,10 +242,12 @@ fun Header(
242
242
  }
243
243
  }
244
244
 
245
- Box(Modifier.graphicsLayer {
246
- alpha = if (animatedHeader !== null) opacity ?: 1f else 1f
247
- }) {
248
- headerRight?.invoke()
245
+ if (inputSearchProps == null) {
246
+ Box(Modifier.graphicsLayer {
247
+ alpha = if (animatedHeader !== null) opacity ?: 1f else 1f
248
+ }) {
249
+ headerRight?.invoke()
250
+ }
249
251
  }
250
252
  }
251
253
 
@@ -23,6 +23,7 @@ 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.compose.utils.datamapping.ModelConvertUtils
26
27
  import vn.momo.kits.application.ComposeApi
27
28
  import vn.momo.kits.application.PlatformApi
28
29
  import vn.momo.kits.const.Colors
@@ -81,14 +82,29 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
81
82
  fun onPressShortcut() {
82
83
  isFavorite = !isFavorite
83
84
  }
84
- fun onPressHelpCenter(){
85
- api?.request("showHelpCenter", "")
85
+
86
+ fun onPressHelpCenter() {
87
+ val params = ModelConvertUtils.encodeToJsonFromAny(
88
+ arrayOf<Any>(
89
+ mapOf("title" to "title"),
90
+ mapOf("title" to "title")
91
+ )
92
+ ).toString()
93
+ api?.request("showHelpCenter", params, {})
86
94
  }
87
- fun onPressClose(){
95
+
96
+ fun onPressClose() {
88
97
  api?.request("dismiss", "")
89
98
  }
99
+
90
100
  fun onPressMore() {
91
- api?.request("showTools", "")
101
+ val params = ModelConvertUtils.encodeToJsonFromAny(
102
+ arrayOf(
103
+ headerRight?.tools,
104
+ emptyMap<Any, Any>()
105
+ )
106
+ ).toString()
107
+ api?.request("showTools", params, {})
92
108
  }
93
109
 
94
110
  fun getNavigationButtonConfig(
@@ -0,0 +1,175 @@
1
+ package vn.momo.compose.utils.datamapping
2
+
3
+ import kotlinx.serialization.json.JsonArray
4
+ import kotlinx.serialization.json.JsonElement
5
+ import kotlinx.serialization.json.JsonNull
6
+ import kotlinx.serialization.json.JsonObject
7
+ import kotlinx.serialization.json.JsonPrimitive
8
+ import kotlinx.serialization.json.booleanOrNull
9
+ import kotlinx.serialization.json.contentOrNull
10
+ import kotlinx.serialization.json.doubleOrNull
11
+ import kotlinx.serialization.json.floatOrNull
12
+ import kotlinx.serialization.json.intOrNull
13
+ import kotlinx.serialization.json.jsonArray
14
+ import kotlinx.serialization.json.jsonObject
15
+ import kotlinx.serialization.json.jsonPrimitive
16
+ import kotlinx.serialization.json.longOrNull
17
+
18
+ fun emptyJsonObject() = JsonObject(mapOf())
19
+
20
+ val JsonObject.Companion.EMPTY
21
+ get() = JsonObject(emptyMap())
22
+
23
+ val JsonArray.Companion.EMPTY
24
+ get() = JsonArray(emptyList())
25
+
26
+ fun JsonObject.tryToGetObject(key: String): JsonObject? {
27
+ return try {
28
+ this[key]?.toJsonElement()?.jsonObject
29
+ } catch (_: Exception) {
30
+ JsonObject.EMPTY
31
+ }
32
+ }
33
+
34
+ fun JsonObject.tryToGetArray(key: String): JsonArray? {
35
+ return try {
36
+ this[key]?.toJsonElement()?.jsonArray
37
+ } catch (_: Exception) {
38
+ JsonArray.EMPTY
39
+ }
40
+ }
41
+
42
+ fun JsonObject.tryToGetString(key: String): String {
43
+ return try {
44
+ this.getOrElse(key) { "" }.toJsonElement().jsonPrimitive.content
45
+ } catch (_: Exception) {
46
+ ""
47
+ }
48
+ }
49
+
50
+ fun JsonObject.tryToGetStringNullable(key: String): String? {
51
+ return try {
52
+ this.getOrElse(key) { null }.toJsonElement().jsonPrimitive.contentOrNull
53
+ } catch (_: Exception) {
54
+ null
55
+ }
56
+ }
57
+
58
+ fun JsonObject.tryToGetLong(key: String): Long? {
59
+ return try {
60
+ this.getOrElse(key) { "" }.toJsonElement().jsonPrimitive.longOrNull
61
+ } catch (_: Exception) {
62
+ null
63
+ }
64
+ }
65
+
66
+ fun JsonObject.tryToGetLong(key: String, default: Long = 0L): Long {
67
+ return try {
68
+ this.getOrElse(key) { default }.toJsonElement().jsonPrimitive.longOrNull ?: default
69
+ } catch (_: Exception) {
70
+ default
71
+ }
72
+ }
73
+
74
+ fun JsonObject.tryToGetDoubleNullable(key: String): Double? {
75
+ return try {
76
+ this.getOrElse(key) { "" }.toJsonElement().jsonPrimitive.doubleOrNull
77
+ } catch (_: Exception) {
78
+ null
79
+ }
80
+ }
81
+
82
+ fun JsonObject.tryToGetDouble(key: String, default: Double = 0.0): Double {
83
+ return try {
84
+ this.getOrElse(key) { default }.toJsonElement().jsonPrimitive.doubleOrNull ?: default
85
+ } catch (_: Exception) {
86
+ default
87
+ }
88
+ }
89
+
90
+ fun JsonObject.tryToGetBoolean(key: String): Boolean {
91
+ return try {
92
+ this[key]?.jsonPrimitive?.booleanOrNull ?: false
93
+ } catch (_: Exception) {
94
+ false
95
+ }
96
+ }
97
+
98
+ fun JsonObject.tryToGetBooleanNullable(key: String): Boolean? {
99
+ return try {
100
+ this[key]?.jsonPrimitive?.booleanOrNull
101
+ } catch (_: Exception) {
102
+ null
103
+ }
104
+ }
105
+
106
+ internal fun JsonElement.toPureMap(): Map<String, Any?> {
107
+ return (this as? JsonObject)?.toPureMap() ?: emptyMap()
108
+ }
109
+
110
+ fun JsonObject.toPureMap(): Map<String, Any?> {
111
+ val map: MutableMap<String, Any?> = mutableMapOf()
112
+ this.jsonObject.entries.forEach { (key, value) ->
113
+ when (value) {
114
+ is Map<*, *> -> map[key] = value.toPureMap()
115
+ is Collection<*> -> map[key] = value.toList().map { it.toJsonElement().toPureMap() }
116
+ is JsonPrimitive -> map[key] =
117
+ if (value.isString) value.content else value.intOrNull ?: value.doubleOrNull
118
+ ?: value.floatOrNull ?: value.booleanOrNull
119
+ is JsonNull -> map[key] = null
120
+ else -> throw IllegalStateException("Can't serialize unknown type: $value")
121
+ }
122
+ }
123
+ return map
124
+ }
125
+
126
+ fun JsonElement.tryToString(): String {
127
+ return try {
128
+ this.jsonPrimitive.content
129
+ } catch (_: Exception) {
130
+ ""
131
+ }
132
+ }
133
+
134
+ internal fun JsonElement.toCollection(): Collection<Any?> {
135
+ val list: MutableList<Any?> = mutableListOf()
136
+ (this as? JsonArray)?.forEach { value ->
137
+ when (value) {
138
+ is Map<*, *> -> list.add(value.toMap())
139
+ is Collection<*> -> list.add(value.toCollection())
140
+ is JsonPrimitive -> list.add(
141
+ if (value.isString) value.content else value.booleanOrNull ?: value.intOrNull
142
+ ?: value.longOrNull ?: value.doubleOrNull ?: value.floatOrNull
143
+ )
144
+
145
+ is JsonNull -> list.add(null)
146
+ else -> throw IllegalStateException("Can't serialize unknown type: $value")
147
+ }
148
+ }
149
+ return list
150
+ }
151
+
152
+ internal fun JsonElement.toMap(): Map<String, Any?> {
153
+ val map: MutableMap<String, Any?> = mutableMapOf()
154
+ (this as? JsonObject)?.entries?.forEach { (key, value) ->
155
+ when (value) {
156
+ is Map<*, *> -> map[key] = value.toMap()
157
+ is Collection<*> -> map[key] = value.toCollection()
158
+ is JsonPrimitive -> map[key] =
159
+ if (value.isString) value.content else value.booleanOrNull ?: value.intOrNull
160
+ ?: value.longOrNull ?: value.doubleOrNull ?: value.floatOrNull
161
+
162
+ is JsonNull -> map[key] = null
163
+ else -> throw IllegalStateException("Can't serialize unknown type: $value")
164
+ }
165
+ }
166
+ return map
167
+ }
168
+
169
+ fun JsonElement.tryForceToStringStringMap(): Map<String, String?>? = try {
170
+ this.toMap() as Map<String, String?>?
171
+ } catch (e: Exception) {
172
+ null
173
+ }
174
+
175
+
@@ -0,0 +1,82 @@
1
+ package vn.momo.compose.utils.datamapping
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.112.1-beta.1",
3
+ "version": "0.112.1-beta.2",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},