Skip to content

Commit 07a0148

Browse files
Fix Sheet native blocking issue by adding a background blocker component only when peers are present.
This change conditionally adds a transparent Button component behind the Sheet in its container if Form.activePeerCount > 0. 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 is not added for lightweight-only forms to minimize overhead.
1 parent df155d6 commit 07a0148

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -488,18 +488,26 @@ public void paint(Graphics g, Rectangle rect) {
488488
}
489489
}
490490

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);
491+
boolean needsBlocker = Form.activePeerCount > 0;
492+
if (needsBlocker) {
493+
if (blocker == null) {
494+
blocker = new Button();
495+
blocker.setUIID("Container");
496+
blocker.getAllStyles().setBgTransparency(0);
497+
blocker.setPreferredSize(new com.codename1.ui.geom.Dimension(10000, 10000));
498+
((Button) blocker).addActionListener(new ActionListener() {
499+
@Override
500+
public void actionPerformed(ActionEvent evt) {
501+
hide(duration);
502+
}
503+
});
504+
cnt.addComponent(0, BorderLayout.CENTER, blocker);
505+
}
506+
} else {
507+
if (blocker != null) {
508+
cnt.removeComponent(blocker);
509+
blocker = null;
510+
}
503511
}
504512

505513
if (foundSheet) {

0 commit comments

Comments
 (0)