Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions CodenameOne/src/com/codename1/ui/Sheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public class Sheet extends Container {
*/
private String tabletPosition = position;

/**
* Original padding values to prevent accumulation when showing the sheet multiple times.
* These are set the first time the sheet is shown and used as the base for safe area calculations.
*/
private int[] originalPadding = null;

private ActionListener formPointerListener = new ActionListener() {
@Override
Expand Down Expand Up @@ -369,29 +374,49 @@ public void show(final int duration) {
// Deal with iPhoneX notch.
UIManager uim = UIManager.getInstance();

// Store original padding values on first show to prevent accumulation
if (originalPadding == null) {
originalPadding = new int[4];
originalPadding[0] = s.getPaddingTop(); // top
originalPadding[1] = s.getPaddingRightNoRTL(); // right
originalPadding[2] = s.getPaddingBottom(); // bottom
originalPadding[3] = s.getPaddingLeftNoRTL(); // left
} else {
// Check if style was reset (current padding much smaller than stored original)
// This can happen if the component was removed and re-added with a new style
int currentBottom = s.getPaddingBottom();
if (currentBottom < originalPadding[2] / 2 && currentBottom >= 0) {
// Style appears to have been reset, update our cache
originalPadding[0] = s.getPaddingTop();
originalPadding[1] = s.getPaddingRightNoRTL();
originalPadding[2] = s.getPaddingBottom();
originalPadding[3] = s.getPaddingLeftNoRTL();
}
}

Style statusBarStyle = uim.getComponentStyle("StatusBar");
Style titleAreaStyle = uim.getComponentStyle("TitleArea");

int topPadding = statusBarStyle.getPaddingTop() + statusBarStyle.getPaddingBottom() + titleAreaStyle.getPaddingTop();
int positionInt = getPositionInt();
Rectangle displaySafeArea = new Rectangle();
Display.getInstance().getDisplaySafeArea(displaySafeArea);
int bottomPadding = s.getPaddingBottom();
// Use original bottom padding to prevent accumulation
int bottomPadding = originalPadding[2];
int safeAreaBottomPadding = CN.getDisplayHeight() - (displaySafeArea.getY() + displaySafeArea.getHeight());
bottomPadding = bottomPadding + safeAreaBottomPadding;
if (positionInt == S || positionInt == C) {
// For Center and South position we use margin to
// prevent overlap with top notch. This looks better as overlap is only
// an edge case that occurs when the sheet is the full screen height.
$(this).setMargin(topPadding, 0 , 0, 0);
$(this).setPadding(s.getPaddingTop(), s.getPaddingRightNoRTL(), bottomPadding, s.getPaddingLeftNoRTL());
$(this).setPadding(originalPadding[0], originalPadding[1], bottomPadding, originalPadding[3]);
} else {
// For other cases we use padding to prevent overlap with top notch. This looks
// better as it appears that the sheet bleeds all the way to the top edge of the screen,
// but the content is not obscured by the notch.


$(this).setPadding(topPadding, s.getPaddingRightNoRTL(), bottomPadding, s.getPaddingLeftNoRTL());
$(this).setPadding(topPadding, originalPadding[1], bottomPadding, originalPadding[3]);
}

// END Deal with iPhoneX notch
Expand Down