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

fix: Fixed toolbar overlapping dynamic islands on iOS #3763

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
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
34 changes: 33 additions & 1 deletion CodenameOne/src/com/codename1/ui/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.codename1.ui.events.ActionEvent;
import com.codename1.ui.events.ActionListener;
import com.codename1.ui.events.ScrollListener;
import com.codename1.ui.geom.Rectangle;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.FlowLayout;
Expand Down Expand Up @@ -227,7 +228,6 @@ public Toolbar() {
&& UIManager.getInstance().getComponentStyle("Title").getAlignment() == CENTER) {
setTitleCentered(true);
}
//setSafeArea(true);
}

/**
Expand Down Expand Up @@ -2238,6 +2238,7 @@ protected List createOverflowCommandList(Vector commands) {
protected void initTitleBarStatus() {
Form f = getComponentForm();
if (f != null && !f.shouldPaintStatusBar()) {
setSafeArea(true);
return;
}
if (getUIManager().isThemeConstant("paintsTitleBarBool", false)) {
Expand All @@ -2249,11 +2250,42 @@ protected void initTitleBarStatus() {
} else {
bar.setUIID("StatusBar");
}
reallocateVerticalPaddingAndMarginsToTop(bar);
bar.setSafeArea(true);
addComponent(BorderLayout.NORTH, bar);
}
} else {
setSafeArea(true);
}
}

/**
* Reallocates vertical padding and margins to be all on top, so that bottom padding/margin
* is zero, but the total padding/margin is the same.
*
* This is helpful for the status bar so that, when the padding is adjusted by the safeArea
* we don't end up with extra padding at the bottom of the component, which would increase
* the height of the status bar.
* @param cmp
*/
private void reallocateVerticalPaddingAndMarginsToTop(Component cmp) {
Style allStyles = cmp.getAllStyles();
Style style = cmp.getStyle();
int topPadding = style.getPaddingTop();
int topMargin = style.getMarginTop();
int bottomPadding = style.getPaddingBottom();
int bottomMargin = style.getMarginBottom();
allStyles.setPaddingUnitTop(Style.UNIT_TYPE_PIXELS);
allStyles.setMarginUnitTop(Style.UNIT_TYPE_PIXELS);
allStyles.setPaddingUnitBottom(Style.UNIT_TYPE_PIXELS);
allStyles.setMarginUnitBottom(Style.UNIT_TYPE_PIXELS);
allStyles.setPaddingTop(topPadding + bottomPadding);
allStyles.setMarginTop(topMargin + bottomMargin);
allStyles.setPaddingBottom(0);
allStyles.setMarginBottom(0);
}


private void checkIfInitialized() {
if (!initialized) {
throw new IllegalStateException("Need to call "
Expand Down
48 changes: 48 additions & 0 deletions CodenameOne/src/com/codename1/ui/plaf/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,12 @@ private void initPaddingUnits() {
* @since 7.0
*/
public void setPaddingUnitLeft(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitLeft(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.LEFT] = unit;
}
Expand All @@ -1820,6 +1826,12 @@ public void setPaddingUnitLeft(byte unit) {
* @since 7.0
*/
public void setPaddingUnitRight(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitRight(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.RIGHT] = unit;
}
Expand All @@ -1831,6 +1843,12 @@ public void setPaddingUnitRight(byte unit) {
* @since 7.0
*/
public void setPaddingUnitTop(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitTop(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.TOP] = unit;
}
Expand All @@ -1842,6 +1860,12 @@ public void setPaddingUnitTop(byte unit) {
* @since 7.0
*/
public void setPaddingUnitBottom(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setPaddingUnitBottom(unit);
}
return;
}
initPaddingUnits();
paddingUnit[Component.BOTTOM] = unit;
}
Expand Down Expand Up @@ -3027,6 +3051,12 @@ private void initMarginUnits() {
* @since 7.0
*/
public void setMarginUnitLeft(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitLeft(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.LEFT] = unit;
}
Expand All @@ -3038,6 +3068,12 @@ public void setMarginUnitLeft(byte unit) {
* @since 7.0
*/
public void setMarginUnitRight(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitRight(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.RIGHT] = unit;
}
Expand All @@ -3049,6 +3085,12 @@ public void setMarginUnitRight(byte unit) {
* @since 7.0
*/
public void setMarginUnitTop(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitTop(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.TOP] = unit;
}
Expand All @@ -3060,6 +3102,12 @@ public void setMarginUnitTop(byte unit) {
* @since 7.0
*/
public void setMarginUnitBottom(byte unit) {
if(proxyTo != null) {
for(Style s : proxyTo) {
s.setMarginUnitBottom(unit);
}
return;
}
initMarginUnits();
marginUnit[Component.BOTTOM] = unit;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.codename1.ui.plaf;

import com.codename1.ui.Component;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class StyleProxyTest {
@Test
public void testSetMarginUnitLeft() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setMarginUnitLeft(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.LEFT]);
proxy.setMarginUnitLeft(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.LEFT]);
}

@Test
public void testSetMarginUnitRight() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setMarginUnitRight(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.RIGHT]);
proxy.setMarginUnitRight(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.RIGHT]);
}

@Test
public void testSetMarginUnitBottom() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setMarginUnitBottom(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.BOTTOM]);
proxy.setMarginUnitBottom(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.BOTTOM]);
}

@Test
public void testSetMarginUnitTop() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setMarginUnitTop(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.TOP]);
proxy.setMarginUnitTop(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.TOP]);
}

@Test
public void testSetPaddingUnitTop() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setPaddingUnitTop(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.TOP]);
proxy.setPaddingUnitTop(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.TOP]);
}

@Test
public void testSetPaddingUnitBottom() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setPaddingUnitBottom(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.BOTTOM]);
proxy.setPaddingUnitBottom(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.BOTTOM]);
}

@Test
public void testSetPaddingUnitLeft() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setPaddingUnitLeft(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.LEFT]);
proxy.setPaddingUnitLeft(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.LEFT]);
}

@Test
public void testSetPaddingUnitRight() {
Style s = new Style();
Style proxy = Style.createProxyStyle(s);
proxy.setPaddingUnitRight(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.RIGHT]);
proxy.setPaddingUnitRight(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.RIGHT]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.codename1.ui.plaf;

import com.codename1.ui.Component;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class StyleTest {
@Test
public void testSetMarginUnitLeft() {
Style s = new Style();
s.setMarginUnitLeft(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.LEFT]);
s.setMarginUnitLeft(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.LEFT]);
}

@Test
public void testSetMarginUnitRight() {
Style s = new Style();
s.setMarginUnitRight(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.RIGHT]);
s.setMarginUnitRight(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.RIGHT]);
}

@Test
public void testSetMarginUnitBottom() {
Style s = new Style();
s.setMarginUnitBottom(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.BOTTOM]);
s.setMarginUnitBottom(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.BOTTOM]);
}

@Test
public void testSetMarginUnitTop() {
Style s = new Style();
s.setMarginUnitTop(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getMarginUnit()[Component.TOP]);
s.setMarginUnitTop(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getMarginUnit()[Component.TOP]);
}

@Test
public void testSetPaddingUnitTop() {
Style s = new Style();
s.setPaddingUnitTop(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.TOP]);
s.setPaddingUnitTop(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.TOP]);
}

@Test
public void testSetPaddingUnitBottom() {
Style s = new Style();
s.setPaddingUnitBottom(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.BOTTOM]);
s.setPaddingUnitBottom(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.BOTTOM]);
}

@Test
public void testSetPaddingUnitLeft() {
Style s = new Style();
s.setPaddingUnitLeft(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.LEFT]);
s.setPaddingUnitLeft(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.LEFT]);
}

@Test
public void testSetPaddingUnitRight() {
Style s = new Style();
s.setPaddingUnitRight(Style.UNIT_TYPE_PIXELS);
assertEquals(Style.UNIT_TYPE_PIXELS, s.getPaddingUnit()[Component.RIGHT]);
s.setPaddingUnitRight(Style.UNIT_TYPE_DIPS);
assertEquals(Style.UNIT_TYPE_DIPS, s.getPaddingUnit()[Component.RIGHT]);
}

}
Loading
Loading