Browse Source

Measure custom react view according to navBarHeight

Fixes #1844
Guy Carmeli 7 years ago
parent
commit
9a7d483450

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java View File

137
     public boolean hasTopBarCustomComponent() {
137
     public boolean hasTopBarCustomComponent() {
138
         return !TextUtils.isEmpty(topBarReactView);
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 View File

104
             }
104
             }
105
             unmountReactView();
105
             unmountReactView();
106
             reactView = new Pair<>(styleParams.topBarReactView, createReactView(styleParams));
106
             reactView = new Pair<>(styleParams.topBarReactView, createReactView(styleParams));
107
+            int height = styleParams.hasCustomTitleBarHeight() ? (int) ViewUtils.convertDpToPixel(styleParams.titleBarHeight) : ViewUtils.getToolBarHeight();
107
             if ("fill".equals(styleParams.topBarReactViewAlignment)) {
108
             if ("fill".equals(styleParams.topBarReactViewAlignment)) {
108
-                addReactViewFill(reactView.second);
109
+                addReactViewFill(reactView.second, height);
109
             } else {
110
             } else {
110
-                addCenteredReactView(reactView.second);
111
+                addCenteredReactView(reactView.second, height);
111
             }
112
             }
112
         } else {
113
         } else {
113
             unmountReactView();
114
             unmountReactView();
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
         titleBar.addView(view);
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
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
144
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
144
             @Override
145
             @Override
145
             public void onDisplay() {
146
             public void onDisplay() {