Browse Source

Fix crash if titleView is null (#1025)

Rui Araújo 7 years ago
parent
commit
14f468f835

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

@@ -84,16 +84,16 @@ public class TitleBar extends Toolbar {
84 84
 
85 85
     private void centerTitle(final StyleParams params) {
86 86
         final View titleView = getTitleView();
87
+        if (titleView == null) {
88
+            return;
89
+        }
87 90
         ViewUtils.runOnPreDraw(titleView, new Runnable() {
88 91
             @Override
89 92
             public void run() {
90 93
                 if (params.titleBarTitleTextCentered) {
91
-                    if (titleView != null) {
92
-                        int[] location = new int[2];
93
-                        titleView.getLocationOnScreen(location);
94
-                        titleView.setTranslationX(titleView.getTranslationX() + (-location[0] + ViewUtils.getScreenWidth() / 2 - titleView.getWidth() / 2));
95
-                    }
96
-
94
+                    int[] location = new int[2];
95
+                    titleView.getLocationOnScreen(location);
96
+                    titleView.setTranslationX(titleView.getTranslationX() + (-location[0] + ViewUtils.getScreenWidth() / 2 - titleView.getWidth() / 2));
97 97
                 }
98 98
 
99 99
             }