Skip to content

Cobalt Web Lifecycle Messages

Guillaume Gendre edited this page Jun 7, 2019 · 3 revisions

Cobalt automatically sends messages to the webpages to notice te web developper about the application state changes.

There is 3 categories of messages which are explained below:

  • Application state messages
  • Page state messages
  • Weblayer messages

All those messages are PubSub messages but are sent to the web side only.

Lifecycle workflow

Here is a workflow of all lifecycle messages.

workflow

Application State messages

There are 3 messages in this category :

  • cobalt:onAppStarted
  • cobalt:onAppBackground
  • cobalt:onAppForeground

All of them are sent to the top/latest Cobalt view created.

cobalt:onAppStarted

Occurs when application is started. It is not fired when app is sent to background and then foreground again.

cobalt:onAppBackground

Occurs when the user leaves the application without killing it, by switching to an other app or pressing the device home button.

  • On iOS it is also fired when double-tapping on the main button (to switch app).
  • On Android it is also fired when displaying currently running application list and switching to another app or removing the app from the list.

cobalt:onAppForeground

Occurs when the user comes back to the application when it was previously in background mode. It can be when the user taps the app icon on the home screen or the application list or switching to it from the currently running application list.

Page State messages

There is only 1 message in this category for now :

  • cobalt:onPageShown

cobalt:onPageShown

Occurs when the page is displayed to the user. It can be :

  • when the page is created
  • when the user get back to it after he pops out from another view
  • when switching app and coming back again

You can rely on it to create or update your view to latest changes.

When coming back from background mode, cobalt:onPageShown is fired after cobalt:onAppForeground.

cobalt:onPageShown receives one parameter : data. This represent the data that was sent with cobalt.navigate.push, replace and modal if defined.

Weblayer messages

Weblayer are also sending messages to the parent page to track their lifecycle.

There is :

  • cobalt:onWebLayerDismissed
  • cobalt:onWebLayerLoading
  • cobalt:onWebLayerLoaded
  • cobalt:onWebLayerLoadFailed

All of them are explained on the Weblayer page.

Clone this wiki locally