Skip to content

Commit aa48b63

Browse files
authored
Merge pull request #110 from abap2UI5/claude/admiring-bell-pO537
Document check_on_navigated lifecycle behavior for sub-app returns
2 parents b4c10b9 + dd38b47 commit aa48b63

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/cookbook/event_navigation/life_cycle.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,35 @@ abap2UI5 does not re-render the view automatically. After an event, if you do **
6262

6363
Call `view_display( )` again only when the **structure** of the view needs to change: different controls, different bindings, a new dialog, navigation to a different screen. Rebuilding and re-sending the view on every event is wasteful and can cause visible flicker, lost scroll position, and lost focus.
6464

65+
### Returning From a Sub-App Hits `check_on_navigated`, Not `check_on_init`
66+
`check_on_init( )` is `abap_true` **exactly once** — on the very first call of an app instance. It does *not* fire again when control comes back to the app after a `nav_app_call( )` (a popup or a fullscreen sub-app) is closed with `nav_app_leave( )`. That return is signalled by `check_on_navigated( )`.
67+
68+
This trips up apps that build their view only under `check_on_init`:
69+
70+
```abap
71+
" WRONG — screen is blank after returning from the sub-app
72+
CASE abap_true.
73+
WHEN client->check_on_init( ).
74+
render_main( ). " runs only the first time
75+
WHEN client->check_on_event( `OPEN_POPUP` ).
76+
client->nav_app_call( ... ).
77+
ENDCASE.
78+
```
79+
80+
When the sub-app is left, `main` runs again, but neither `check_on_init` nor any event matches, so `view_display( )` is never called and the user is left looking at a stale or empty screen. Render from the navigation-return branch as well — `check_on_navigated( )` fires both on the first display *and* on every return, so reacting to it alone is usually enough:
81+
82+
```abap
83+
" CORRECT — the view is rebuilt on first display and on every return
84+
CASE abap_true.
85+
WHEN client->check_on_navigated( ).
86+
render_main( ).
87+
WHEN client->check_on_event( `OPEN_POPUP` ).
88+
client->nav_app_call( ... ).
89+
ENDCASE.
90+
```
91+
92+
Reserve `check_on_init` for one-time setup that must *not* repeat on return (loading initial data, setting defaults). As a rule of thumb: anything needed to **show the screen** belongs in a branch that also fires on navigation return.
93+
6594
### `check_on_event` Fires Once Per Roundtrip
6695
Every HTTP request carries at most one event. `check_on_event( )` returns `abap_true` exactly once per call to `main`, for that single event. If the user clicks two buttons in quick succession, the framework dispatches them as two independent `main` invocations — they are never batched into one request.
6796

0 commit comments

Comments
 (0)