@momo-kits/native-kits 0.112.1-beta.5 → 0.112.1-beta.7

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.
@@ -22,8 +22,6 @@ import vn.momo.kits.const.defaultTheme
22
22
  import vn.momo.kits.platform.disableOverscroll
23
23
  import vn.momo.kits.platform.getStatusBarHeight
24
24
 
25
- val PlatformApi = staticCompositionLocalOf<Any?> { null }
26
-
27
25
  interface ComposeApi {
28
26
  fun request(funcName: String, params: String?): String
29
27
  fun request(funcName: String, params: String?, onResponse: ((String) -> Unit)?): String
@@ -31,10 +29,6 @@ interface ComposeApi {
31
29
  fun removeCallback(id: String)
32
30
  }
33
31
 
34
- val AppNavigator = staticCompositionLocalOf<Navigator> {
35
- error("no navigator provided!")
36
- }
37
-
38
32
  class Navigator {
39
33
  fun push(content: @Composable () -> Unit) {
40
34
  }
@@ -67,11 +61,30 @@ class Navigator {
67
61
  }
68
62
  }
69
63
 
64
+ data class MiniAppContext(
65
+ val icon: String = "",
66
+ val name: String = "",
67
+ val appId: String = "",
68
+ val code: String = "",
69
+ val description: String? = "",
70
+ )
71
+
72
+ val PlatformApi = staticCompositionLocalOf<Any?> { null }
73
+
74
+ val AppNavigator = staticCompositionLocalOf<Navigator> {
75
+ error("no navigator provided!")
76
+ }
77
+
78
+ val ApplicationContext = staticCompositionLocalOf<MiniAppContext?> {
79
+ error("no context provided!")
80
+ }
81
+
70
82
  @Composable
71
83
  fun ApplicationContainer(
72
84
  theme: Theme = defaultTheme,
73
85
  composeApi: ComposeApi? = null,
74
86
  statusBarHeight: Dp? = AppStatusBar.current ?: getStatusBarHeight(),
87
+ applicationContext: MiniAppContext? = null,
75
88
  content: @Composable () -> Unit
76
89
  ) {
77
90
  var appTheme by remember { mutableStateOf(theme) }
@@ -97,8 +110,7 @@ fun ApplicationContainer(
97
110
  }
98
111
  }
99
112
  }
100
- }
101
- catch (e: Exception) {
113
+ } catch (e: Exception) {
102
114
  print("@@ == NavigationContainer fetch config error $e")
103
115
  }
104
116
  }
@@ -109,6 +121,7 @@ fun ApplicationContainer(
109
121
  PlatformApi provides composeApi,
110
122
  AppNavigator provides Navigator(),
111
123
  AppStatusBar provides statusBarHeight,
124
+ ApplicationContext provides applicationContext
112
125
  ) {
113
126
  content()
114
127
  }
@@ -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.kits.application.ApplicationContext
26
27
  import vn.momo.kits.application.ComposeApi
27
28
  import vn.momo.kits.application.PlatformApi
28
29
  import vn.momo.kits.const.Colors
@@ -78,19 +79,22 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
78
79
  var isFavorite by remember { mutableStateOf(false) }
79
80
  val isLoading by remember { mutableStateOf(false) }
80
81
  val api = PlatformApi.current as? ComposeApi
82
+ val context = ApplicationContext.current
81
83
 
82
84
  fun onPressShortcut() {
83
85
  isFavorite = !isFavorite
84
86
  }
85
87
 
86
88
  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, {})
89
+ val paramMap: Map<String, Any?> = mapOf(
90
+ "appId" to context?.appId,
91
+ "code" to context?.code,
92
+ "name" to context?.name,
93
+ "icon" to context?.icon,
94
+ "description" to context?.description
95
+ )
96
+ val params = ModelConvertUtils.encodeToJsonFromAny(paramMap).toString()
97
+ api?.request("showHelpCenter", params, { _ -> })
94
98
  }
95
99
 
96
100
  fun onPressClose() {
@@ -98,13 +102,19 @@ fun ToolkitHeaderRight(headerRight: HeaderRightData? = null) {
98
102
  }
99
103
 
100
104
  fun onPressMore() {
101
- val params = ModelConvertUtils.encodeToJsonFromAny(
102
- arrayOf(
103
- headerRight?.tools,
104
- emptyMap<Any, Any>()
105
+ val param = listOf(
106
+ headerRight?.tools ?: emptyList<ToolGroup>(),
107
+ mapOf(
108
+ "appId" to context?.appId,
109
+ "code" to context?.code,
110
+ "name" to context?.name,
111
+ "icon" to context?.icon,
112
+ "description" to context?.description
105
113
  )
106
- ).toString()
107
- api?.request("showTools", params, {})
114
+ )
115
+
116
+ val params = ModelConvertUtils.encodeToJsonFromAny(param).toString()
117
+ api?.request("showTools", params, { _ -> })
108
118
  }
109
119
 
110
120
  fun getNavigationButtonConfig(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.112.1-beta.5",
3
+ "version": "0.112.1-beta.7",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},