Skip to content

Commit

Permalink
add missing default margin in component title bar (#6903)
Browse files Browse the repository at this point in the history
There was a missing margin at the start of the custom title, added into considerations to fix backwards compatibility with the default spaces
  • Loading branch information
swabbass authored and yogevbd committed Jan 17, 2021
1 parent 3ee7785 commit 0b8829a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ private void alignComponent() {
component.setX((getWidth() - component.getWidth() - direction * getStart()) / 2f);
} else if (lp.gravity == Gravity.START) {
boolean isRTL = getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
component.setX(isRTL ? getWidth() - component.getWidth() - getStart() : 0);
int defaultLeftMarginPx = UiUtils.dpToPx(getContext(), DEFAULT_LEFT_MARGIN);
component.setX(isRTL ? getWidth() - component.getWidth() - defaultLeftMarginPx : defaultLeftMarginPx);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.TestUtils;
import com.reactnativenavigation.utils.UiUtils;

import org.junit.Test;

Expand All @@ -19,6 +20,7 @@

import static com.reactnativenavigation.utils.Assertions.assertNotNull;
import static com.reactnativenavigation.utils.ViewUtils.findChildByClass;
import static com.reactnativenavigation.views.stack.topbar.titlebar.TitleBar.DEFAULT_LEFT_MARGIN;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.eq;
Expand Down Expand Up @@ -72,19 +74,20 @@ public void setComponent_doesNothingIfComponentIsAlreadyAdded() {
}

@Test
public void setComponent_alignedStartAfterMeasure() {
public void setComponent_alignedStartAfterMeasureWithDefaultMargin() {
uut.layout(0, 0, UUT_WIDTH, UUT_HEIGHT);

View component = new View(activity);
component.layout(0, 0, COMPONENT_WIDTH, COMPONENT_HEIGHT);
component.setLayoutParams(new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START));
uut.setComponent(component);
uut.onLayout(true, 0, 0, 0, 0);
assertThat(component.getX()).isEqualTo(0);
int defaultLeftMarginPx = UiUtils.dpToPx(activity, DEFAULT_LEFT_MARGIN);
assertThat(component.getX()).isEqualTo(defaultLeftMarginPx);
}

@Test
public void setComponent_alignedStartRTLAfterMeasure() {
public void setComponent_alignedStartRTLAfterMeasureWithDefaultMargin() {
ViewGroup parent = new FrameLayout(activity);
parent.layout(0, 0, UUT_WIDTH, UUT_HEIGHT);
when(uut.getParent()).thenReturn(parent);
Expand All @@ -95,7 +98,8 @@ public void setComponent_alignedStartRTLAfterMeasure() {
component.setLayoutParams(new Toolbar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START));
uut.setComponent(component);
uut.onLayout(true, 0, 0, 0, 0);
assertThat(component.getX()).isEqualTo(UUT_WIDTH - COMPONENT_WIDTH);
int defaultLeftMarginPx = UiUtils.dpToPx(activity, DEFAULT_LEFT_MARGIN);
assertThat(component.getX()).isEqualTo(UUT_WIDTH - COMPONENT_WIDTH - defaultLeftMarginPx);
}

@Test
Expand Down

0 comments on commit 0b8829a

Please sign in to comment.