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

Lead component action listener on Contact Row disables Scrolling #3079

Closed
mike-at-acs opened this issue Apr 11, 2020 · 5 comments
Closed

Lead component action listener on Contact Row disables Scrolling #3079

mike-at-acs opened this issue Apr 11, 2020 · 5 comments
Assignees
Milestone

Comments

@mike-at-acs
Copy link

Swipeable container with a lead component action listener seems to deactivate scrollability. This was working with previous CN1 build versions. The first 3 rows in the screenshot below have URLImages and at the same time include an action listener so that the user can zoom in on the icon if needed. Scrolling on the first 3 rows doesn’t work but works fine on the rest of the rows where there is no lead component action listener.
image

I thought the problem was the URLImages but it’s actually the lead component action listener that was getting added only to rows that also have URLImages.

How to replicate:

See attached code (change .txt to .java) based on the CN1 Contacts Demo described here Find the section labelled “offending code”. Commenting out the offending code solves the problem. Uncommenting it replicates the problem.

MySQLContactsDemo.txt

This is my first time opening an issue. Apologies if I didn't do it quite right. Thx, Mike

@codenameone codenameone added this to the Version 7.0 milestone Apr 12, 2020
@shannah
Copy link
Collaborator

shannah commented Apr 15, 2020

I've pulled this from your sample:

// start of the offending code 
                ///*
                // with previous CN1 Build Versions scrolling worked with this in
                // but now scrolling only works if this is commented out
                Button contactRowBtn = new Button();
                contactRowBtn.addActionListener(e -> {
//                        viewThisPhoto(iconName);
                    System.out.println("viewThisPhoto displays a zoomed up view of the icon");
                });
                sc.setLeadComponent(contactRowBtn);

There are a couple of problems here:

  1. This code is called inside scheduleBackgroundTask() -> it isn't run on the EDT.
  2. You're setting the contactRowBtn as the lead component for sc, but I don't see where you're actually adding contactRowBtn to the UI. The lead component should be a child of the component that it is a lead for (or at least part of the branch whose root is the container for which it is a lead).

If you can produce a self-contained test case (e.g. single file, no dependencies, ..) it will make it easier for me to look into this.

shannah added a commit that referenced this issue Apr 15, 2020
@shannah
Copy link
Collaborator

shannah commented Apr 15, 2020

I added a test case for this issue. Please try to modify this test case to reproduce the problem. So far seems to work OK. Closing this for now. If you can reproduce the problem in test case, I'll reopen.

@shannah shannah closed this as completed Apr 15, 2020
@mike-at-acs
Copy link
Author

Steve - Thanks for your suggestions and your test code. It works as desired, other than the rows aren’t swipeable. Is that expected?

This seems like a situation where my non-standard coding got-by before but doesn’t work with the latest CN1 build version. I’m pretty slow at coding so rather than taking another day or so to replicate the problem in another test case, I’ve tried to replicate your solution in my code and the good news is that worked. Sort of. I was able to keep the scrolling working with the “offending code” included by just adding before the setLeadComponent line….

sc.add(contactRowBtn);

But unfortunately each row with that lead component now became unswipeable.

This approach also fixed the scrolling on my actual code and the action listener worked but swipeability stopped working and also, each row that has this lead component set is now covered in solid blue and nothing underneath is visible. Any ideas why those two problems happen and how to solve?

Thanks for your help,
Mike

@shannah
Copy link
Collaborator

shannah commented Apr 16, 2020

Thanks for your suggestions and your test code. It works as desired, other than the rows aren’t swipeable. Is that expected?

The sample didn't include any components in the right or left of the swipe container so, yes that was expected. I've updated the sample to include such components so you can verify that swiping still works.

But unfortunately each row with that lead component now became unswipeable.

I think this is actually the crux of the issue. The SwipeContainer is a bit of a special container that may have its only pointer handling. When you set a lead component on a container, it delegates all pointer events for the container to the lead component - which may be problematic. You should set the button as the lead component on "center" container of the SwipeContainer and not the SwipeContainer itself.

@mike-at-acs
Copy link
Author

Thanks Steve. I see the swipeability works in your demo. To prevent the action listening button from covering up the whole row in my code, I created a transparent button, ButtonTrans, in theme.res and then added

contactRowBtn.setUIID("ButtonTrans");

to my code and that did the trick.

All good now. Thanks again.

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

No branches or pull requests

2 participants