Unwanted swipe left on swipeable container when swiping another

Viewed 40

I have a number of swipeable containers added to a page. The swipeable containers have buttons left and right and the top component is a multibutton that takes the user to another page. When the user goes back to the page with the swipeable containers and swipes left (only left) on a different swipeable container then the first container also opens to the left. Images and sample code below:-

//Swipeable containers bugs
public void SwipeableContainerPage(Form mainForm){
    
    Form formSC = new Form("Swipeable Container", new BorderLayout());
    formSC.getToolbar().setBackCommand("", e -> mainForm.showBack());
    
    Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    
    MultiButton mb_1 = new MultiButton("MB1");
    Button b_l1 = new Button("LB1");
    Button b_r1 = new Button("RB1");
    
    MultiButton mb_2 = new MultiButton("MB2");
    Button b_l2 = new Button("LB2");
    Button b_r2 = new Button("RB2");
    
    MultiButton mb_3 = new MultiButton("MB3");
    Button b_l3 = new Button("LB3");
    Button b_r3 = new Button("RB3");
            
    SwipeableContainer sc_1 = new SwipeableContainer(b_l1, b_r1, mb_1);
    SwipeableContainer sc_2 = new SwipeableContainer(b_l2, b_r2, mb_2);
    SwipeableContainer sc_3 = new SwipeableContainer(b_l3, b_r3, mb_3);
    
    mb_1.addActionListener(new ActionListener() {
    @Override
        public void actionPerformed(ActionEvent e) {
            GoToAndBackPage(formSC);
        }        
    });
    
    mb_2.addActionListener(new ActionListener() {
    @Override
        public void actionPerformed(ActionEvent e) {
            GoToAndBackPage(formSC);
        }        
    });
    
    mb_3.addActionListener(new ActionListener() {
    @Override
        public void actionPerformed(ActionEvent e) {
            GoToAndBackPage(formSC);
        }        
    });
    
    centercnt.add(sc_1);
    centercnt.add(sc_2);
    centercnt.add(sc_3);        
    
    formSC.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);  
    formSC.show();
    
}
//page for SC to go to
public void GoToAndBackPage(Form mainForm){
    Form formGoTo = new Form("Go To Page", new BorderLayout());
    formGoTo.getToolbar().setBackCommand("", e -> mainForm.showBack());
    
    Container northcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Container centercnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    Container southcnt = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    
    Label l_welcome = new Label("Welcome to the Go To Page");
    
    centercnt.add(l_welcome);
    
    formGoTo.add(BorderLayout.NORTH, northcnt).add(BorderLayout.CENTER, centercnt).add(BorderLayout.SOUTH, southcnt);  
    formGoTo.show();        
}

1. Press on MB1 and go to next page

2. go back to swipeable container page

3. Swipe left on MB3 and MB1 also swipes left

1 Answers

This sounds like a bug and ideally you should file an issue with a test case. But try this for a workaround.

Wrap the code that handles the navigation to a different form in a call serially. E.g. if the code looks like:

myMultiButton.addActionListener(e -> showOtherForm(...));

Then do this:

myMultiButton.addActionListener(e -> callSerially(showOtherForm(...)));

My theory is that the press brings the swipable component to a state that "could" be dragging. But because the navigation event happens to soon the release event isn't received by the button (we're on a different form now) and everything is lost.

So when you get back to the form you now have two "charged" buttons. By using a callSerially you effectively flush the event queue and make sure the release event is processed by everyone on the current Form before moving to the next Form.

Related