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

Swipeable autoclose #3093

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions CodenameOne/src/com/codename1/ui/SwipeableContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ public void actionPerformed(ActionEvent evt) {
}

if (initialX != -1) {
if (getPreviouslyOpened() != null && getPreviouslyOpened() != SwipeableContainer.this && getPreviouslyOpened().isOpen())
getPreviouslyOpened().close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add curly brackets around the statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, yes, sure

int diff = x - initialX;
int val = 0;
if(!isOpen()){
Expand Down Expand Up @@ -444,4 +446,12 @@ public void actionPerformed(ActionEvent evt) {
}
}

/**
* override to return a previously opened SwipeableContainer that should be automatically closed when starting to open this one
* @return
*/
public SwipeableContainer getPreviouslyOpened() {
return null;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a field and a setter, also include text in the @return tag otherwise the Javadoc looks weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my use case (and I believe most other), a field and setter doesn't make sense: I have a long list of SwipeableContainers and keep track of which is opened in the Form (I overwrite openToLeft, openToRight and close() to store/remove an open Swipeable). For a local field (like 'openSwipeable') to make sense, every SwipeableContainer would need to get that set.

I assume there might be a better overall way to smoothly close any already opened Swpeiable, but here I went for minimal impact to the existing code.

(NB. My first attempt was to override openToLeft/openToRight to close the previously opened Swipeable, but since they only get called once Swipeable is completely opened, it didn't look right).

If you still think it makes sense, I can add these since it won't break anything, at worst it could lead a developer down a wrong path at first :-)

}