ソースを参照

Fix overflow visible for react button components in TopBar (#4802)

React button components now support overflow: visible. This property is especially useful when displaying buttons with a badge
which exceeds the button bounds.
Guy Carmeli 5 年 前
コミット
54ff1cd049
No account linked to committer's email address

+ 12
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBar.java ファイルの表示

@@ -38,6 +38,12 @@ public class TitleBar extends Toolbar {
38 38
         setContentDescription("titleBar");
39 39
     }
40 40
 
41
+    @Override
42
+    public void onViewAdded(View child) {
43
+        super.onViewAdded(child);
44
+        enableOverflowForReactButtonViews(child);
45
+    }
46
+
41 47
     @Override
42 48
     public void setTitle(CharSequence title) {
43 49
         clearComponent();
@@ -210,4 +216,10 @@ public class TitleBar extends Toolbar {
210 216
             }
211 217
         }
212 218
     }
219
+
220
+    private void enableOverflowForReactButtonViews(View child) {
221
+        if (child instanceof ActionMenuView) {
222
+            ((ViewGroup) child).setClipChildren(false);
223
+        }
224
+    }
213 225
 }

+ 24
- 26
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TitleBarTest.java ファイルの表示

@@ -1,29 +1,22 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3
-import android.app.Activity;
4
-import android.view.View;
5
-
6
-import com.reactnativenavigation.BaseTest;
7
-import com.reactnativenavigation.parse.params.Button;
8
-import com.reactnativenavigation.parse.params.Text;
9
-import com.reactnativenavigation.react.Constants;
10
-import com.reactnativenavigation.react.ReactView;
11
-import com.reactnativenavigation.utils.CollectionUtils;
12
-import com.reactnativenavigation.views.titlebar.TitleBar;
13
-
14
-import org.junit.Test;
15
-
16
-import java.util.ArrayList;
17
-import java.util.Arrays;
18
-import java.util.Collections;
19
-import java.util.HashMap;
20
-import java.util.List;
21
-import java.util.Map;
22
-
23
-import static com.reactnativenavigation.utils.TitleBarHelper.createButtonController;
24
-import static org.assertj.core.api.Java6Assertions.assertThat;
25
-import static org.mockito.Mockito.spy;
26
-import static org.mockito.Mockito.verify;
3
+import android.app.*;
4
+import android.support.v7.widget.*;
5
+import android.view.*;
6
+
7
+import com.reactnativenavigation.*;
8
+import com.reactnativenavigation.parse.params.*;
9
+import com.reactnativenavigation.react.*;
10
+import com.reactnativenavigation.utils.*;
11
+import com.reactnativenavigation.views.titlebar.*;
12
+
13
+import org.junit.*;
14
+
15
+import java.util.*;
16
+
17
+import static com.reactnativenavigation.utils.TitleBarHelper.*;
18
+import static org.assertj.core.api.Java6Assertions.*;
19
+import static org.mockito.Mockito.*;
27 20
 
28 21
 public class TitleBarTest extends BaseTest {
29 22
 
@@ -31,14 +24,12 @@ public class TitleBarTest extends BaseTest {
31 24
     private Button leftButton;
32 25
     private Button textButton;
33 26
     private Button customButton;
34
-    private Map<String, TitleBarButtonController> buttonControllers;
35 27
     private Activity activity;
36 28
 
37 29
     @Override
38 30
     public void beforeEach() {
39 31
         activity = newActivity();
40 32
         createButtons();
41
-        buttonControllers = new HashMap<>();
42 33
         uut = spy(new TitleBar(activity));
43 34
     }
44 35
 
@@ -105,6 +96,13 @@ public class TitleBarTest extends BaseTest {
105 96
         verify(uut).addView(component);
106 97
     }
107 98
 
99
+    @Test
100
+    public void addView_overflowIsEnabledForButtonsContainer() {
101
+        ActionMenuView buttonsContainer = mock(ActionMenuView.class);
102
+        uut.addView(buttonsContainer);
103
+        verify(buttonsContainer).setClipChildren(false);
104
+    }
105
+
108 106
     @Test
109 107
     public void clear() {
110 108
         View title = new View(activity);