Linear horizontal transparent gradient

After trying unsuccesfully the solutions proposed here:

The solution proposed uses animations that applies to the whole object.
I was able to make it using a simple linear gradient that melts with the background color, i was complicating things too much trying to make the gradient transparent.

static void apply_gradient_in(lv_obj_t *obj)
{
    lv_obj_set_style_bg_color(obj, <bg_color>, 0);
    lv_obj_set_style_bg_grad_color(obj, <obj_color>, 0);
    lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
}

static void apply_gradient_out(lv_obj_t *obj)
{
    lv_obj_set_style_bg_color(obj, <obj_color>, 0);
    lv_obj_set_style_bg_grad_color(obj, <bg_color>, 0);
    lv_obj_set_style_bg_grad_dir(obj, LV_GRAD_DIR_HOR, 0);
}

<bg_color> is backgroung color;
<obj_color> is the color of the static object to fade in/out;