@@ -63,6 +63,7 @@ import io.nubrick.nubrick.schema.UIRootBlock
6363import io.nubrick.nubrick.template.compile
6464import kotlinx.coroutines.DelicateCoroutinesApi
6565import kotlinx.serialization.json.JsonElement
66+ import kotlinx.serialization.json.JsonNull
6667
6768private fun parseUIEventToEvent (event : UIBlockEventDispatcher ): Event {
6869 return Event (
@@ -83,6 +84,11 @@ private fun parseUIEventToEvent(event: UIBlockEventDispatcher): Event {
8384 )
8485}
8586
87+ internal data class WebviewData (
88+ val url : String ,
89+ val trigger : UIBlockEventDispatcher ? ,
90+ ) {}
91+
8692internal class RootViewModel (
8793 private val root : UIRootBlock ,
8894 private val modalViewModel : ModalViewModel ,
@@ -93,7 +99,7 @@ internal class RootViewModel(
9399) : ViewModel() {
94100 private val pages: List <UIPageBlock > = root.data?.pages ? : emptyList()
95101 val displayedPageBlock = mutableStateOf<PageBlockData ?>(null )
96- val webviewUrl = mutableStateOf( " " )
102+ val webviewData = mutableStateOf< WebviewData ?>( null )
97103
98104 // We use them for sdk bridge between flutter <-> android.
99105 val currentPageBlock = mutableStateOf<UIPageBlock ?>(null )
@@ -150,7 +156,10 @@ internal class RootViewModel(
150156 }
151157
152158 if (destBlock.data?.kind == PageKind .WEBVIEW_MODAL ) {
153- this .webviewUrl.value = destBlock.data.webviewUrl ? : " "
159+ this .webviewData.value = WebviewData (
160+ url = destBlock.data.webviewUrl ? : " " ,
161+ trigger = destBlock.data.triggerSetting?.onTrigger
162+ )
154163 return
155164 }
156165
@@ -190,7 +199,7 @@ internal class RootViewModel(
190199 }
191200
192201 fun handleWebviewDismiss () {
193- this .webviewUrl .value = " "
202+ this .webviewData .value = null
194203 }
195204}
196205
@@ -287,6 +296,11 @@ internal fun Root(
287296 container.handleEvent(e)
288297 }
289298 }
299+ LaunchedEffect (Unit ) {
300+ modalViewModel.setOnTrigger { trigger, data ->
301+ listener(trigger, data)
302+ }
303+ }
290304
291305 val currentPageBlock = viewModel.currentPageBlock.value
292306 val displayedPageBlock = viewModel.displayedPageBlock.value
@@ -321,7 +335,7 @@ internal fun Root(
321335
322336 if (modalState.modalVisibility) {
323337 BackHandler (true ) {
324- modalViewModel.back()
338+ modalViewModel.back(JsonNull )
325339 }
326340 val isLarge =
327341 modalState.modalPresentationStyle == ModalPresentationStyle .DEPENDS_ON_CONTEXT_OR_FULL_SCREEN
@@ -340,7 +354,7 @@ internal fun Root(
340354 shape = RoundedCornerShape (topStart = 10 .dp, topEnd = 10 .dp),
341355 ) {
342356 ModalBottomSheetBackHandler {
343- modalViewModel.back()
357+ modalViewModel.back(JsonNull )
344358 }
345359 Column (
346360 modifier = if (modalState.modalPresentationStyle == ModalPresentationStyle .DEPENDS_ON_CONTEXT_OR_FULL_SCREEN ) {
@@ -373,7 +387,7 @@ internal fun Root(
373387 it,
374388 stack.block,
375389 onClose = { modalViewModel.close() },
376- onBack = { modalViewModel.back() },
390+ onBack = { modalViewModel.back(JsonNull ) },
377391 isFullscreen,
378392 )
379393 ModalPage (
@@ -388,7 +402,7 @@ internal fun Root(
388402 }
389403 }
390404
391- if (viewModel.webviewUrl .value.isNotEmpty() ) {
405+ if (viewModel.webviewData .value != null ) {
392406 Dialog (
393407 properties = DialogProperties (
394408 usePlatformDefaultWidth = true ,
@@ -406,8 +420,11 @@ internal fun Root(
406420 .background(Color .LightGray )
407421 ) {
408422 WebViewPage (
409- url = viewModel.webviewUrl .value,
423+ url = viewModel.webviewData .value?.url ? : " " ,
410424 onDismiss = {
425+ viewModel.webviewData.value?.trigger?.let { trigger ->
426+ listener(trigger, JsonNull )
427+ }
411428 viewModel.handleWebviewDismiss()
412429 },
413430 modifier = Modifier
0 commit comments