@momo-kits/native-kits 0.113.1-beta.2 → 0.113.1-beta.3

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.
@@ -40,6 +40,8 @@ import vn.momo.kits.utils.ifNotNull
40
40
  data class PopupAction(
41
41
  val title: String,
42
42
  val onPress: (() -> Unit)?,
43
+ val onPressMiniapp: ((Int) -> Unit)? = null,
44
+ val typePopupDisplay: String? = null
43
45
  )
44
46
 
45
47
  enum class PopupActionDirection {
@@ -58,6 +60,7 @@ fun PopupNotify(
58
60
  secondary: PopupAction? = null,
59
61
  buttonDirection: PopupActionDirection = PopupActionDirection.ROW,
60
62
  onIconClose: () -> Unit,
63
+ buttons: List<String>? = emptyList()
61
64
  ) {
62
65
  var isScroll by remember { mutableStateOf(false) }
63
66
  val layoutResult = remember { mutableStateOf<TextLayoutResult?>(null) }
@@ -95,6 +98,10 @@ fun PopupNotify(
95
98
  callback?.invoke()
96
99
  }
97
100
 
101
+ fun onCloseMiniapp(callback: ((Int) -> Unit)?) {
102
+ callback?.invoke(buttons?.indexOf(buttons.first()) ?: -1)
103
+ }
104
+
98
105
  Box(Modifier.semantics {
99
106
  testTag = "popup_notify"
100
107
  }, contentAlignment = Alignment.TopEnd) {
@@ -134,7 +141,7 @@ fun PopupNotify(
134
141
  ) {
135
142
  BuildAction(primary, secondary, buttonDirection, onAction = { callback ->
136
143
  onClose(callback)
137
- })
144
+ }, onActionMiniapp = {callback -> onCloseMiniapp(callback)})
138
145
  }
139
146
  }
140
147
 
@@ -178,6 +185,7 @@ fun BuildAction(
178
185
  secondary: PopupAction?,
179
186
  buttonDirection: PopupActionDirection = PopupActionDirection.ROW,
180
187
  onAction: (onPress: (() -> Unit)?) -> Unit,
188
+ onActionMiniapp: (onPress: ((Int) -> Unit)?) -> Unit,
181
189
  ) {
182
190
  val closeAction = remember { mutableStateOf("button_action") }
183
191
  when (buttonDirection) {
@@ -194,7 +202,8 @@ fun BuildAction(
194
202
  secondary = secondary,
195
203
  onAction = onAction,
196
204
  closeAction = closeAction,
197
- primary = primary
205
+ primary = primary,
206
+ onActionMiniapp = onActionMiniapp
198
207
  )
199
208
  }
200
209
  }
@@ -203,7 +212,8 @@ fun BuildAction(
203
212
  secondary = secondary,
204
213
  onAction = onAction,
205
214
  closeAction = closeAction,
206
- primary = primary
215
+ primary = primary,
216
+ onActionMiniapp = onActionMiniapp
207
217
  )
208
218
 
209
219
  else -> renderColumn(
@@ -221,6 +231,7 @@ fun renderRow(
221
231
  closeAction: MutableState<String>,
222
232
  primary: PopupAction?,
223
233
  onAction: (onPress: (() -> Unit)?) -> Unit,
234
+ onActionMiniapp: ((onPress: ((Int) -> Unit)?) -> Unit)? = null,
224
235
  ) {
225
236
  Row(horizontalArrangement = Arrangement.Center) {
226
237
  secondary?.let {
@@ -245,7 +256,10 @@ fun renderRow(
245
256
  size = Size.MEDIUM,
246
257
  onClick = {
247
258
  closeAction.value = "button_action"
248
- onAction(primary?.onPress)
259
+ if(primary?.typePopupDisplay == "miniapp")
260
+ onActionMiniapp?.invoke(primary.onPressMiniapp)
261
+ else
262
+ onAction( primary?.onPress)
249
263
  },
250
264
  title = primary?.title ?: "",
251
265
  modifier = Modifier.semantics {
@@ -262,13 +276,17 @@ fun renderColumn(
262
276
  closeAction: MutableState<String>,
263
277
  primary: PopupAction?,
264
278
  onAction: (onPress: (() -> Unit)?) -> Unit,
279
+ onActionMiniapp: ((onPress: ((Int) -> Unit)?) -> Unit)? = null,
265
280
  ) {
266
281
  Column(horizontalAlignment = Alignment.CenterHorizontally) {
267
282
  Button(
268
283
  size = Size.MEDIUM,
269
284
  onClick = {
270
285
  closeAction.value = "button_action"
271
- onAction(primary?.onPress)
286
+ if(primary?.typePopupDisplay == "miniapp")
287
+ onActionMiniapp?.invoke(primary.onPressMiniapp)
288
+ else
289
+ onAction( primary?.onPress)
272
290
  },
273
291
  title = primary?.title ?: "",
274
292
  modifier = Modifier.semantics {
@@ -20,7 +20,7 @@ public enum PopupButtonType {
20
20
  public struct PopupDisplay: View {
21
21
  // MARK: Lifecycle
22
22
 
23
- public init(isPresented: Binding<Bool>, title: String = "", description: String = "", url: String = "", buttonDirection: PopupButtonDirection = .column, buttonType: PopupButtonType = .button, actionButtonTitle: String = "", closeButtonTitle: String = "", onPressAction: @escaping () -> Void = {}, onPressCloseButton: @escaping () -> Void = {}, onClose: @escaping () -> Void = {}) {
23
+ public init(isPresented: Binding<Bool>, title: String = "", description: String = "", url: String = "", buttonDirection: PopupButtonDirection = .column, buttonType: PopupButtonType = .button, actionButtonTitle: String = "", closeButtonTitle: String = "", onPressAction: @escaping () -> Void = {}, onPressCloseButton: @escaping () -> Void = {}, onClose: @escaping () -> Void = {},onPressMiniapp: @escaping (Int) -> Void = {_ in }, typePopupDisplay: String = "", buttons: [String]? = []) {
24
24
  self._isPresented = isPresented
25
25
  self.title = title
26
26
  self.description = description
@@ -32,6 +32,9 @@ public struct PopupDisplay: View {
32
32
  self.onClose = onClose
33
33
  self.closeButtonTitle = closeButtonTitle
34
34
  self.actionButtonTitle = actionButtonTitle
35
+ self.onPressMiniapp = onPressMiniapp
36
+ self.typePopupDisplay = typePopupDisplay
37
+ self.buttons = buttons
35
38
  }
36
39
 
37
40
  // MARK: Public
@@ -107,6 +110,9 @@ public struct PopupDisplay: View {
107
110
  var onClose: () -> Void
108
111
  var actionButtonTitle: String
109
112
  var closeButtonTitle: String
113
+ var typePopupDisplay: String
114
+ var onPressMiniapp: ((_ index: Int)->Void)?
115
+ var buttons: [String]?
110
116
 
111
117
  var RowTextButtons: some View {
112
118
  HStack {
@@ -145,7 +151,15 @@ public struct PopupDisplay: View {
145
151
  var RowButtons: some View {
146
152
  HStack {
147
153
  Button(title: closeButtonTitle, action: onPressCloseButton, type: .secondary)
148
- Button(title: actionButtonTitle, action: onPressAction)
154
+ Button(
155
+ title: actionButtonTitle,
156
+ action: {if(typePopupDisplay == "miniapp") {
157
+ onPressMiniapp?(buttons?.startIndex ?? -1)
158
+ } else {
159
+ onPressAction()
160
+ } }
161
+ )
162
+
149
163
  }
150
164
  .frame(maxWidth: .infinity, alignment: .center)
151
165
  .padding(.horizontal, 24)
@@ -154,7 +168,14 @@ public struct PopupDisplay: View {
154
168
 
155
169
  var ColumnButtons: some View {
156
170
  VStack(alignment: .trailing) {
157
- Button(title: actionButtonTitle, action: onPressAction)
171
+ Button(
172
+ title: actionButtonTitle,
173
+ action: {if(typePopupDisplay == "miniapp") {
174
+ onPressMiniapp?(buttons?.startIndex ?? -1)
175
+ } else {
176
+ onPressAction()
177
+ } }
178
+ )
158
179
  Button(title: closeButtonTitle, action: onPressCloseButton, type: .secondary)
159
180
  }
160
181
  .frame(maxWidth: .infinity, alignment: .trailing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.113.1-beta.2",
3
+ "version": "0.113.1-beta.3",
4
4
  "private": false,
5
5
  "dependencies": {},
6
6
  "devDependencies": {},