Explorar el Código

Measure custom react view according to navBarHeight

Fixes #1844
Guy Carmeli hace 7 años
padre
commit
9a7d483450

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java Ver fichero

@@ -137,4 +137,8 @@ public class StyleParams {
137 137
     public boolean hasTopBarCustomComponent() {
138 138
         return !TextUtils.isEmpty(topBarReactView);
139 139
     }
140
+
141
+    public boolean hasCustomTitleBarHeight() {
142
+        return titleBarHeight != -1;
143
+    }
140 144
 }

+ 7
- 6
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Ver fichero

@@ -104,10 +104,11 @@ public class TopBar extends AppBarLayout {
104 104
             }
105 105
             unmountReactView();
106 106
             reactView = new Pair<>(styleParams.topBarReactView, createReactView(styleParams));
107
+            int height = styleParams.hasCustomTitleBarHeight() ? (int) ViewUtils.convertDpToPixel(styleParams.titleBarHeight) : ViewUtils.getToolBarHeight();
107 108
             if ("fill".equals(styleParams.topBarReactViewAlignment)) {
108
-                addReactViewFill(reactView.second);
109
+                addReactViewFill(reactView.second, height);
109 110
             } else {
110
-                addCenteredReactView(reactView.second);
111
+                addCenteredReactView(reactView.second, height);
111 112
             }
112 113
         } else {
113 114
             unmountReactView();
@@ -133,13 +134,13 @@ public class TopBar extends AppBarLayout {
133 134
         );
134 135
     }
135 136
 
136
-    private void addReactViewFill(ContentView view) {
137
-        view.setLayoutParams(new LayoutParams(MATCH_PARENT, ViewUtils.getToolBarHeight()));
137
+    private void addReactViewFill(ContentView view, int height) {
138
+        view.setLayoutParams(new LayoutParams(MATCH_PARENT, height));
138 139
         titleBar.addView(view);
139 140
     }
140 141
 
141
-    private void addCenteredReactView(final ContentView view) {
142
-        titleBar.addView(view, new LayoutParams(WRAP_CONTENT, ViewUtils.getToolBarHeight()));
142
+    private void addCenteredReactView(final ContentView view, int height) {
143
+        titleBar.addView(view, new LayoutParams(WRAP_CONTENT, height));
143 144
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
144 145
             @Override
145 146
             public void onDisplay() {