The property OnVisible
of a screen is a much used location for your logic (code). After the code is run, that screen is in a “start” mode from where people can take further actions. Code in the property OnVisible
is only run when you navigate to that screen though so there is no way to run it while you are on the screen. There is a workaround for this: A redirect screen
In this blog post I explain how to create a redirect screen. I also describe something I call a “Screen OnVisible button” which is related to this topic.
Redirect screen
With a redirect screen, you temporary navigate to another screen to immediately switch to the screen you want to go to, which could be the screen you originated from and thus running the “OnVisible” code again.
There must be a place for a user to trigger this redirect action from. A menu where each menu item navigates to a specific screen is a common way.
The steps below explain how to create a redirect screen.
1) When clicking on a menu option, set a global variable (glb_RedirectScreen for this blog post) so it contains the screen object of the screen you want to navigate to. Example:
Set(glb_RedirectScreen, ThisItem.Screen);
Navigate(scr_Redirect)
2) On the app control, in the property OnStart
, set a global variable (glb_Redirect for this blog post) to true. When creating the canvas app, you can easily update the value of this variable to false and run the property OnStart
of the app control again if you want to make changes to the redirect screen. Example:
Set(glb_Redirect, true)
3) Create a new screen and give it a proper name.
4) Add a button on that screen, give it a proper name (btn_Redirect for this blog post) and set the property Visible
to false. I normally place such button in the top left.
5) Add the following code to the property OnVisible
of the redirect screen:
Select(btn_Redirect)
6) Put the following code in the property OnSelect
of the button:
If(
glb_Redirect,
Navigate(glb_RedirectScreen)
)
And that is all there is to it.
The variable glb_Redirect is important for a redirect screen. When such a construction is not used, the redirect screen could never be changed again because you will always be redirected.
Screen OnVisible button
This is a button which contains the logic (code) you would normally put in the screen property OnVisible
. The button is not visible and called from the property OnVisible
of the screen using the function Select. Example:
Select(btn_Home)
If you want to bring your screen to its “start” mode again, you simple on have to call the screen OnVisible button again using the function Select.
Using only a screen OnVisible button is not enough from an user experience perspective. When a user clicks on the menu item related to the active screen, it is expected that the screen is set to its “start” mode again.