Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scroll): fix deletion animation causing missing scroll end event #5979

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

qinshijing
Copy link
Contributor

@qinshijing qinshijing commented Mar 27, 2024

Description of the feature or fix

Anim's completed_cb will not be called when the animation is deleted, so if the animation is deleted, there will be no scroll end event.
In the example below, when the blue block animation scrolls to position 320, completed cb has not been called yet. Click btn to scroll to position 320. At this time, the animation will be deleted. You can see in the log that there is no scroll end event.

static void anim_completed_cb(lv_anim_t* a)
{
  LV_LOG_USER("completed cb");
  lv_anim_completed_cb_t completed = a->user_data;
  if (completed) {
    completed(a);
  }
}

static void scroll_event_cb(lv_event_t* e)
{
  if (e->code == LV_EVENT_SCROLL_BEGIN) {

    lv_anim_t * a = lv_event_get_scroll_anim(e);
    if (a) {
      lv_anim_set_user_data(a, a->completed_cb);
      a->completed_cb = anim_completed_cb;
      a->duration = 20000;
    }
    LV_LOG_USER("LV_EVENT_SCROLL_BEGIN");
  } else if (e->code == LV_EVENT_SCROLL_END) {
    LV_LOG_USER("LV_EVENT_SCROLL_END");
  }
}

static void btn_cb(lv_event_t* e)
{
  lv_obj_t* cont = lv_event_get_user_data(e);
  lv_obj_scroll_to(cont, 0, 320, LV_ANIM_OFF);
  LV_LOG_USER("scroll to 320");
}

static void lv_scroll_demo(void)
{
  lv_obj_t* cont = lv_obj_create(lv_scr_act());
  lv_obj_set_size(cont, LV_PCT(100), LV_PCT(100));
  lv_obj_set_scroll_snap_y(cont, LV_SCROLL_SNAP_CENTER);
  lv_obj_add_event_cb(cont, scroll_event_cb, LV_EVENT_SCROLL_BEGIN, NULL);
  lv_obj_add_event_cb(cont, scroll_event_cb, LV_EVENT_SCROLL_END, NULL);

  lv_obj_t* obj = lv_obj_create(cont);
  lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
  lv_obj_set_style_bg_color(obj, lv_color_hex(0xff0000), 0);

  obj = lv_obj_create(cont);
  lv_obj_set_size(obj, LV_PCT(100), LV_PCT(100));
  lv_obj_set_style_bg_color(obj, lv_color_hex(0x0000ff), 0);
  lv_obj_set_y(obj, LV_VER_RES);

  lv_obj_t* btn = lv_obj_create(lv_layer_sys());
  lv_obj_center(btn);
  lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
  lv_obj_add_event_cb(btn, btn_cb, LV_EVENT_CLICKED, cont);
}
no_scroll_end.mp4

Notes

@FASTSHIFT FASTSHIFT changed the title fix(scroll): Fixed deletion animation causing missing LV_EVENT_SCROLL… fix(scroll): fix deletion animation causing missing scroll end event Mar 28, 2024
@kisvegabor
Copy link
Member

The changes makes sense, however as it's a non-trivial case, could you add a test for it?

@qinshijing
Copy link
Contributor Author

The changes makes sense, however as it's a non-trivial case, could you add a test for it?

Sorry, I've been a little busy lately and don't have time to add.

Copy link
Member

@kisvegabor kisvegabor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's hard to test let's go without test now.

@kisvegabor kisvegabor merged commit 7e7590a into lvgl:master Apr 15, 2024
16 checks passed
kisvegabor pushed a commit to zjanosy/lvgl that referenced this pull request Apr 17, 2024
@IAMMX
Copy link
Contributor

IAMMX commented Apr 22, 2024

please fix issue: #6098

@qinshijing qinshijing deleted the fix_scroll branch April 22, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants