浏览代码

Fix crash if titleView is null (#1025)

Rui Araújo 8 年前
父节点
当前提交
14f468f835
共有 1 个文件被更改,包括 6 次插入6 次删除
  1. 6
    6
      android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java

+ 6
- 6
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java 查看文件

@@ -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
             }