Skip to content

Commit

Permalink
Fix overflow visible for react button components in TopBar (#4802)
Browse files Browse the repository at this point in the history
React button components now support overflow: visible. This property is especially useful when displaying buttons with a badge
which exceeds the button bounds.
  • Loading branch information
guyca authored Feb 28, 2019
1 parent e50906d commit 54ff1cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public TitleBar(Context context) {
setContentDescription("titleBar");
}

@Override
public void onViewAdded(View child) {
super.onViewAdded(child);
enableOverflowForReactButtonViews(child);
}

@Override
public void setTitle(CharSequence title) {
clearComponent();
Expand Down Expand Up @@ -210,4 +216,10 @@ public void setOverflowButtonColor(int color) {
}
}
}

private void enableOverflowForReactButtonViews(View child) {
if (child instanceof ActionMenuView) {
((ViewGroup) child).setClipChildren(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
package com.reactnativenavigation.viewcontrollers;

import android.app.Activity;
import android.view.View;

import com.reactnativenavigation.BaseTest;
import com.reactnativenavigation.parse.params.Button;
import com.reactnativenavigation.parse.params.Text;
import com.reactnativenavigation.react.Constants;
import com.reactnativenavigation.react.ReactView;
import com.reactnativenavigation.utils.CollectionUtils;
import com.reactnativenavigation.views.titlebar.TitleBar;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.reactnativenavigation.utils.TitleBarHelper.createButtonController;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.app.*;
import android.support.v7.widget.*;
import android.view.*;

import com.reactnativenavigation.*;
import com.reactnativenavigation.parse.params.*;
import com.reactnativenavigation.react.*;
import com.reactnativenavigation.utils.*;
import com.reactnativenavigation.views.titlebar.*;

import org.junit.*;

import java.util.*;

import static com.reactnativenavigation.utils.TitleBarHelper.*;
import static org.assertj.core.api.Java6Assertions.*;
import static org.mockito.Mockito.*;

public class TitleBarTest extends BaseTest {

private TitleBar uut;
private Button leftButton;
private Button textButton;
private Button customButton;
private Map<String, TitleBarButtonController> buttonControllers;
private Activity activity;

@Override
public void beforeEach() {
activity = newActivity();
createButtons();
buttonControllers = new HashMap<>();
uut = spy(new TitleBar(activity));
}

Expand Down Expand Up @@ -105,6 +96,13 @@ public void setComponent_addsComponentToTitleBar() {
verify(uut).addView(component);
}

@Test
public void addView_overflowIsEnabledForButtonsContainer() {
ActionMenuView buttonsContainer = mock(ActionMenuView.class);
uut.addView(buttonsContainer);
verify(buttonsContainer).setClipChildren(false);
}

@Test
public void clear() {
View title = new View(activity);
Expand Down

1 comment on commit 54ff1cd

@davidbilik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discovered that this lead to #4870. ActionMenuView is probably not ok with clipChildren = false in initial phase of its button rendering

Please sign in to comment.