I have a slide in animation from one screen to another that runs for 500ms. I also have a Screen_Loaded function handler for the second screen. The handler gets called before the transition animation completes, so the screen freezes halfway over waiting for the loaded code to complete.
Is there a way to have the function call after the animation is complete instead of what appears to be they both get called at the sameish time?
Hi,
It’s handled in LVGL like this:
static void scr_anim_ready(lv_anim_t * a)
{
lv_disp_t * d = lv_obj_get_disp(a->var);
lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOADED, NULL);
lv_event_send(d->prev_scr, LV_EVENT_SCREEN_UNLOADED, NULL);
if(d->prev_scr && d->del_prev) lv_obj_del(d->prev_scr);
d->prev_scr = NULL;
d->draw_prev_over_act = false;
d->scr_to_load = NULL;
lv_obj_remove_local_style_prop(a->var, LV_STYLE_OPA, 0);
lv_obj_invalidate(d->act_scr);
}
So in when the animation is ready scr_anim_ready
is called and it fires the LV_EVENT_SCREEN_LOADED
event.
So it should wok as you have described. Could you send your project so that we can examine it?
kisvegabor:
static void scr_anim_ready(lv_anim_t * a)
{
lv_disp_t * d = lv_obj_get_disp(a->var);
//This event signals that the screen is fully loaded..
//but any handler delay will stall rendering until...
lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOADED, NULL);
lv_event_send(d->prev_scr, LV_EVENT_SCREEN_UNLOADED, NULL);
if(d->prev_scr && d->del_prev) lv_obj_del(d->prev_scr);
d->prev_scr = NULL;
d->draw_prev_over_act = false;
d->scr_to_load = NULL;
lv_obj_remove_local_style_prop(a->var, LV_STYLE_OPA, 0);
lv_obj_invalidate(d->act_scr); //...this causes the final position render
}
Sorry to necro this thread, but I’ve also run into this several times. I’ve annotated the code above to explain what I suspect is the issue.
Seems to fix it by forcing out a frame before we send the events:
static void scr_anim_ready(lv_anim_t * a)
{
lv_obj_remove_local_style_prop(a->var, LV_STYLE_OPA, 0);
lv_disp_t * d = lv_obj_get_disp(a->var);
lv_obj_invalidate(d->act_scr);
if(d->refr_timer) _lv_disp_refr_timer(d->refr_timer);
lv_event_send(d->act_scr, LV_EVENT_SCREEN_LOADED, NULL);
lv_event_send(d->prev_scr, LV_EVENT_SCREEN_UNLOADED, NULL);
if(d->prev_scr && d->del_prev) lv_obj_del(d->prev_scr);
d->prev_scr = NULL;
d->draw_prev_over_act = false;
d->scr_to_load = NULL;
}