Is tab animation broken?

29 views
Skip to first unread message

Carlos Verdier

unread,
Nov 25, 2019, 11:49:25 AM11/25/19
to CodenameOne Discussions
Hi

I think this code is not working now:

tab.setSelectedIndex(1, true);

The animation does not work. Can you reproduce this?

Thanks

Shai Almog

unread,
Nov 25, 2019, 9:20:17 PM11/25/19
to CodenameOne Discussions
Hi,
this works for me:

Form hi = new Form("Tabs", new BorderLayout());
Tabs t = new Tabs();
Label t1 = new Label("Blue");
t1
.getAllStyles().setBgColor(0xff);
t1
.getAllStyles().setBgTransparency(255);
Label t2 = new Label("Green");
t2
.getAllStyles().setBgColor(0xff00);
t2
.getAllStyles().setBgTransparency(255);
Label t3 = new Label("Red");
t3
.getAllStyles().setBgColor(0xff0000);
t3
.getAllStyles().setBgTransparency(255);

t
.addTab("Blue", t1);
t
.addTab("Green", t2);
t
.addTab("Red", t3);

UITimer.timer(500, true, hi, () -> {
   
int idx = t.getSelectedIndex() + 1;
   
if(idx >= t.getTabCount()) {
        idx
= 0;
   
}
    t
.setSelectedIndex(idx, true);
});

hi
.add(CENTER, t);
hi
.show();



Carlos Verdier

unread,
Nov 26, 2019, 10:42:08 AM11/26/19
to CodenameOne Discussions
Ok, this test case wasn't easy to find, but I got it.

        Form hi = new Form("Tabs", new LayeredLayout());

       
Tabs t = new Tabs();

       
SpanLabel t1 = new SpanLabel("Blue");
        t1
.getAllStyles().setBgColor(0xff);
        t1
.getAllStyles().setBgTransparency(255);
       
SpanLabel t2 = new SpanLabel("Green");
        t2
.getAllStyles().setBgColor(0xff00);
        t2
.getAllStyles().setBgTransparency(255);
       
SpanLabel t3 = new SpanLabel("Red");

        t3
.getAllStyles().setBgColor(0xff0000);
        t3
.getAllStyles().setBgTransparency(255);

        t
.addTab("Blue", t1);
        t
.addTab("Green", t2);
        t
.addTab("Red", t3);

       
UITimer.timer(500, true, hi, () -> {
           
int idx = t.getSelectedIndex() + 1;
           
if(idx >= t.getTabCount()) {
                idx
= 0;
           
}
            t
.setSelectedIndex(idx, true);
       
});


        hi
.add(t);
        hi
.show();    

As you can see the combination of LayeredLayout and SpanLabel is causing the issue. This configuration used to work before.

LayeredLayout is causing some troubles with container.replace(contA, contB) as well. I can try to reproduce this if you need it.

Shai Almog

unread,
Nov 26, 2019, 9:08:05 PM11/26/19
to CodenameOne Discussions
I'm not sure why it causes it but there's a bug in the code and when you fix it the animation works.
You forgot f.setScrollable(false). Since a form is scrollable by default you should disable that for tabs. With BorderLayout this is implicitly turned off so we don't need to explicitly write that.

Carlos Verdier

unread,
Nov 27, 2019, 4:34:13 AM11/27/19
to CodenameOne Discussions
Yes, your solution fixes the animation, but I still think there is a problem. This new code still fails:

        Form hi = new Form("Tabs", new BorderLayout());

       
Tabs t = new Tabs();
       
SpanLabel t1 = new SpanLabel("Blue");
        t1
.getAllStyles().setBgColor(0xff);
        t1
.getAllStyles().setBgTransparency(255);

       
Container cont1 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        cont1
.add(t1);

       
SpanLabel t2 = new SpanLabel("Green");
        t2
.getAllStyles().setBgColor(0xff00);
        t2
.getAllStyles().setBgTransparency(255);

       
Container cont2 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        cont2
.add(t2);        
       
SpanLabel t3 = new SpanLabel("Red");
        t3
.getAllStyles().setBgColor(0xff0000);
        t3
.getAllStyles().setBgTransparency(255);
       
Container cont3 = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        cont3
.add(t3);
        t
.addTab("Blue", cont1);
        t
.addTab("Green", cont2);
        t
.addTab("Red", cont3);


       
UITimer.timer(500, true, hi, () -> {
           
int idx = t.getSelectedIndex() + 1;
           
if(idx >= t.getTabCount()) {
                idx
= 0;
           
}
            t
.setSelectedIndex(idx, true);
       
});


        hi
.add(CENTER, t);
        hi
.show();    

If you use TextArea instead of SpanLabel, the animation works again, so it's not a big problem for me because I can style TextArea and make it work. But the issue is there, and it wasn't before.

Shai Almog

unread,
Nov 27, 2019, 9:20:41 PM11/27/19
to CodenameOne Discussions
OK,
please file an issue and make sure to reference that you believe this is a regression. It might be an errant revalidate that's breaking the animation here.

Carlos Verdier

unread,
Nov 28, 2019, 10:06:18 AM11/28/19
to CodenameOne Discussions
Ok, done. Thank you
Reply all
Reply to author
Forward
0 new messages