Skip to content

Commit df155d6

Browse files
Fix Sheet native blocking issue by adding a background blocker component.
This change adds a transparent Button component behind the Sheet in its container. This ensures that native components (like BrowserComponent) correctly detect that they are covered by another component when checking `getComponentAt(x, y)`, preventing unwanted event propagation. The blocker also handles the standard "tap to dismiss" behavior.
1 parent 0286dde commit df155d6

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

CodenameOne/src/com/codename1/ui/Sheet.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,31 @@ public void paint(Graphics g, Rectangle rect) {
478478
cnt.revalidate();
479479

480480
}
481-
if (cnt.getComponentCount() > 0) {
481+
boolean foundSheet = false;
482+
Component blocker = null;
483+
for (Component child : cnt) {
484+
if (child instanceof Sheet) {
485+
foundSheet = true;
486+
} else {
487+
blocker = child;
488+
}
489+
}
490+
491+
if (blocker == null) {
492+
blocker = new Button();
493+
blocker.setUIID("Container");
494+
blocker.getAllStyles().setBgTransparency(0);
495+
blocker.setPreferredSize(new com.codename1.ui.geom.Dimension(10000, 10000));
496+
((Button)blocker).addActionListener(new ActionListener() {
497+
@Override
498+
public void actionPerformed(ActionEvent evt) {
499+
hide(duration);
500+
}
501+
});
502+
cnt.addComponent(0, BorderLayout.CENTER, blocker);
503+
}
504+
505+
if (foundSheet) {
482506
$(".Sheet", cnt).each(new ComponentClosure() {
483507
@Override
484508
public void call(Component c) {
@@ -514,8 +538,18 @@ public void call(Component c) {
514538
}
515539

516540
});
517-
Component existing = cnt.getComponentAt(0);
518-
cnt.replace(existing, this, null);
541+
Component existing = null;
542+
for(Component c : cnt) {
543+
if (c instanceof Sheet) {
544+
existing = c;
545+
break;
546+
}
547+
}
548+
if (existing != null) {
549+
cnt.replace(existing, this, null);
550+
} else {
551+
cnt.add(getPosition(), this);
552+
}
519553
cnt.animateLayout(duration);
520554
} else {
521555
cnt.add(getPosition(), this);

0 commit comments

Comments
 (0)