Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

ObserveBindCHanges no NavigationContext sendo "triggered" mais de uma vez e problemas com Boolean. #1809

Closed
gabrielleonardozup opened this issue Apr 18, 2022 · 1 comment · Fixed by ZupIT/beagle-android#89
Assignees
Labels
android This issue directly affects structure and logic of Android project bug Something isn't working

Comments

@gabrielleonardozup
Copy link
Contributor

Description

Um componente que está "ouvindo" alterações de contexto de navegaação está sendo notificado múltiplas vezes. Isso faz com que o comportamento definido dentro do componente ( no cenário testado ele executa uma ação ) seja também executado diversas vezes.

Steps To Reproduce

  1. Crie duas telas no BFF, tela A e B, faça um botão na tela A que navegue para tela B utilizando pushView, a tela B possui um botão que realiza uma navegação de popView "setando" um valor no NavigationContext.

  2. A tela A além do botão, possui um componente custom ( invisível ou não ), que fica ouvindo alterações no NavigationContext para fins de tomada de decisão. Quando a tela B sai por causa do popView, o observeBindChanges desse componente é chamado de forma intermitente entre duas a três vezes seguidas.

  3. Problema do Boolean, se o valor setado no NavigationContext for um booleano, além de triggar o observeBindChanges múltiplas vezes, o valor "evaluated" nesse bind sempre vem nulo.

Expected Results

O esperado é que as chamadas ao observeBindCHanges sejam coerentes com a quantidade de alterações no contexto de navegação, sempre 1:1.

Code example, screenshot, or link to a repository:

Segue um json de uma tela de exemplo e o código de um componente custom ouvindo o contexto de navegação.

{
	"_beagleComponent_": "beagle:screenComponent",
	"navigationBar": {
		"title": "TextSD",
		"showBackButton": true
	},
	"child": {
		"_beagleComponent_": "beagle:container",
		"children": [{
			"_beagleComponent_": "beagle:text",
			"text": "@{navigationContext.shouldRetry}"
		}, {
			"_beagleComponent_": "beagle:button",
			"text": "vai para o erro",
			"onPress": [{
				"_beagleAction_": "beagle:setContext",
				"contextId": "text",
				"value": true
			}, {
				"_beagleAction_": "beagle:pushView",
				"route": {
					"screen": {
						"_beagleComponent_": "beagle:screenComponent",
						"child": {
							"_beagleComponent_": "beagle:container",
							"children": [{
								"_beagleComponent_": "beagle:button",
								"text": "pop",
								"onPress": [{
									"_beagleAction_": "beagle:popView",
									"navigationContext": {
										"value": "NAVIGATE",
										"path": "shouldRetry"
									}
								}]
							}]
						}
					}
				}
			}]
		}, {
			"_beagleComponent_": "custom:actionExecutor",
			"trigger": "@{navigationContext.shouldRetry}",
			"actions": [{
				"_beagleAction_": "beagle:pushView",
				"route": {
					"screen": {
						"_beagleComponent_": "beagle:screenComponent",
						"child": {
							"_beagleComponent_": "beagle:container",
							"children": [{
								"_beagleComponent_": "beagle:button",
								"text": "SIGNUP",
								"onPress": [{
									"_beagleAction_": "beagle:popView",
									"navigationContext": {
										"value": "NAVIGATE",
										"path": "shouldRetry"
									}
								}]
							}]
						}
					}
				}
			}]
		}],
		"style": {
			"cornerRadius": {},
			"size": {},
			"margin": {
				"all": {
					"value": 20.0,
					"type": "REAL"
				}
			},
			"flex": {
				"flexDirection": "COLUMN"
			}
		}
	},
	"context": {
		"id": "text",
		"value": false
	}
}

enum class ActionExecutorType{ NAVIGATE, NOTHING }

@RegisterWidget("ActionExecutor")
class ActionExecutor(
    var trigger: Bind<ActionExecutorType>,
    val actions: List<Action>
): WidgetView(){
    override fun buildView(rootView: RootView): View {
        val view = LinearLayout(rootView.getContext())
        var avoidCallingTwiceControl = true
        trigger.let {
            this@ActionExecutor.observeBindChanges(
                rootView = rootView,
                view = view,
                bind = it,
                observes = { shouldExecute ->
                    shouldExecute?.apply {
                        if (this == ActionExecutorType.NAVIGATE){
                            /** This is a workaround because
                             * there is a bug in observeBindChanges that make
                             * it being executed twice **/
                            if (avoidCallingTwiceControl){
                                this@ActionExecutor.handleEvent(
                                    rootView = rootView,
                                    origin = view,
                                    actions = actions,
                                    context = null,
                                    analyticsValue = null
                                )
                                avoidCallingTwiceControl = false
                            }
                        }
                    }
                }
            )
        }
        return view
    }
}
@gabrielleonardozup gabrielleonardozup added bug Something isn't working android This issue directly affects structure and logic of Android project labels Apr 18, 2022
@github-actions
Copy link

👋 @gabrielleonardozup
Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible and that you have followed our contributing guidelines.
We will review it as soon as possible.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
android This issue directly affects structure and logic of Android project bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants