New bug in event handling?

Hi,

I seem to have a strange issue with event handling.
On a page, I trigger a custom event on “page focus” which works well. (and I am doing this repeatly)
Now when I navigate away from the page and to the page again, two events are fired, one of them the last event I had fired before I left the page.
When I navigate from the page away and then back to the page, three events are fired.

Any idea what is going on here?
It happens in the latest version and I have no idea how to better trace this down.
I need events as I would need to duplicate lots of code otherwise.

It worked some time ago.
Thanks and best,
Jo

When you are Navigating “Back” to the page, are you doing so with the ‘Open Page’ flow function? Because if you are then it is actually opening a New Instance of that page (!). I discovered this the hard way when I saw multiple duplicate events and loops running from the same page in my app.

Always use ‘Navigate Back’ flows to prevent this. ‘Open Page’ does exactly what it says - It Opens a New Page (over and over each time it’s called)

Hey John, thanks. Unfortunately I cannot use navigate_back all the time.
If I create a new instance, why are two events triggered? Are “both active”?

Yes, if the Events are specific to that page ( any event prefixed with Page_ ), then they are active for each instance of the page that is Open. For me, fortunately Im able to design my app with an explicit ‘Back’ button on each page that does ‘Navigate Back’ to help direct the user to Navigate backwards back to the Main page whenever possible. That is the only way a page truly closes without being left open and running in memory.

Ok, maybe @Harri_Sarsa there is a way how this issue can be prevented in the code, it does not sound to my like something that needs to be like this…
My issue here is:
In my app, the user is guided through a series of pages which are dynamically determined based on loaded data. This can also be the same page several times with different data → the page acts more like a template, a logic of “navigate back” does not make much sense.
So i needs to be possible to put the same page several times on the “page stack” without having an issue that the old page interferes with the new one.
This worked in the old version to my understanding!
In addition: If the user stops the app and starts later, she can go to the point where the she left. As there is a back button on every page, I would need to “secretly” navigate the user through everything. (which takes time as openpage seems to take half a sec or so)
but even then, I would open the page several times.

Maybe someone has a different idea how to implement this?

Update: I could now solve it with using a single page for everything, but then I dont have any transitions between my “fake” pages. If anyone has ideas how to simulate a page transition effect, please let me know!

How are you doing fake pages? With containers?

Yes, with containers & visibility flag

There is an Animate Component flow function that has a lot of transition effects. You should try it out.

Animate Component
Market Place Token: 50fkNU_KY3W7bnH-GclgsQ

Thanks for the tip, will try it!

The behavior is as expected, as on mobile the pages in the stack stay open and thus react to events. You could add an app variable “currentPageUUID”, so that every time you open a page, you include an uuid parameter with GENERATE_UUID(), and set the app variable to match that. This way, when the event is fired, params.uuid will be different for each instance, and you can add an IF condition to trigger only the currently active page’s logic.

That said, a platform functionality to add a flag to Receive event for “Only trigger when page is focused” and “Only trigger when page is topmost in its navigation stack” would be useful.

You could also use the Replace page flow function, which will replace the current page instead of adding a new one into the stack!

Thanks!
This means that I can also do stuff based on events on pages which were opened once but are not visible right now? Is this reliable both on iOS and Android?
I was not aware of the “Replace page” flow function, this is also cool!

Yes, triggering on opened pages works on iOS and Android, but note that it doesn’t work on web!

Yea I didnt know about Replace Page either, that would have solved a lot of headaches before!