Browse Source

Set titleBarSubTitleTextCentered as navigator style for android (#2611)

* Set titleBarSubTitleTextCentered as navigator style

- Adapt title center

* fixed false declaration
Michael Kuczera 7 years ago
parent
commit
e437b7a23a

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

120
     public int titleBarTitleFontSize;
120
     public int titleBarTitleFontSize;
121
     public boolean titleBarTitleFontBold;
121
     public boolean titleBarTitleFontBold;
122
     public boolean titleBarTitleTextCentered;
122
     public boolean titleBarTitleTextCentered;
123
+    public boolean titleBarSubTitleTextCentered;
123
     public int titleBarHeight;
124
     public int titleBarHeight;
124
     public boolean backButtonHidden;
125
     public boolean backButtonHidden;
125
     public Font titleBarButtonFontFamily;
126
     public Font titleBarButtonFontFamily;

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java View File

66
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
66
         result.titleBarTitleFontSize = getInt("titleBarTitleFontSize", getDefaultTitleTextFontSize());
67
         result.titleBarTitleFontBold = getBoolean("titleBarTitleFontBold", getDefaultTitleTextFontBold());
67
         result.titleBarTitleFontBold = getBoolean("titleBarTitleFontBold", getDefaultTitleTextFontBold());
68
         result.titleBarTitleTextCentered = getBoolean("titleBarTitleTextCentered", getDefaultTitleBarTextCentered());
68
         result.titleBarTitleTextCentered = getBoolean("titleBarTitleTextCentered", getDefaultTitleBarTextCentered());
69
+        result.titleBarSubTitleTextCentered = getBoolean("titleBarSubTitleTextCentered", getDefaultTitleBarTextCentered());
69
         result.titleBarHeight = getInt("titleBarHeight", getDefaultTitleBarHeight());
70
         result.titleBarHeight = getInt("titleBarHeight", getDefaultTitleBarHeight());
70
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
71
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
71
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
72
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
326
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleTextCentered;
327
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarTitleTextCentered;
327
     }
328
     }
328
 
329
 
330
+    private boolean getDefaultSubTitleBarTextCentered() {
331
+        return AppStyle.appStyle != null && AppStyle.appStyle.titleBarSubTitleTextCentered;
332
+    }
333
+
329
     private int getDefaultTitleBarHeight() {
334
     private int getDefaultTitleBarHeight() {
330
         return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarHeight;
335
         return AppStyle.appStyle == null ? -1 : AppStyle.appStyle.titleBarHeight;
331
     }
336
     }

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

84
         setSubtitleFont(params);
84
         setSubtitleFont(params);
85
         colorOverflowButton(params);
85
         colorOverflowButton(params);
86
         setBackground(params);
86
         setBackground(params);
87
-        centerTitle(params);
87
+        centerTopBarContent(params);
88
         setTopPadding(params);
88
         setTopPadding(params);
89
     }
89
     }
90
 
90
 
102
         super.setSubtitle(subtitle);
102
         super.setSubtitle(subtitle);
103
         setSubtitleFontSize(styleParams);
103
         setSubtitleFontSize(styleParams);
104
         setSubtitleFont(styleParams);
104
         setSubtitleFont(styleParams);
105
+        centerSubTitle(styleParams);
105
     }
106
     }
106
 
107
 
107
     private void setSubtitleFontSize(StyleParams params) {
108
     private void setSubtitleFontSize(StyleParams params) {
120
         }
121
         }
121
     }
122
     }
122
 
123
 
124
+    private void centerTopBarContent(final StyleParams params) {
125
+        centerTitle(params);
126
+        centerSubTitle(params);
127
+    }
128
+
123
     private void centerTitle(final StyleParams params) {
129
     private void centerTitle(final StyleParams params) {
124
         final View titleView = getTitleView();
130
         final View titleView = getTitleView();
125
         if (titleView == null) {
131
         if (titleView == null) {
135
         });
141
         });
136
     }
142
     }
137
 
143
 
144
+    private void centerSubTitle(final StyleParams params) {
145
+        final TextView subTitleView = getSubtitleView();
146
+        if (subTitleView == null) {
147
+            return;
148
+        }
149
+        ViewUtils.runOnPreDraw(subTitleView, new Runnable() {
150
+            @Override
151
+            public void run() {
152
+                if (params.titleBarSubTitleTextCentered) {
153
+                    subTitleView.setX(ViewUtils.getWindowWidth((Activity) getContext()) / 2 - subTitleView.getWidth() / 2);
154
+                }
155
+            }
156
+        });
157
+    }
158
+
138
     private void setTopPadding(final StyleParams params) {
159
     private void setTopPadding(final StyleParams params) {
139
         setPadding(0, (int) ViewUtils.convertDpToPixel(params.titleBarTopPadding), 0,0);
160
         setPadding(0, (int) ViewUtils.convertDpToPixel(params.titleBarTopPadding), 0,0);
140
     }
161
     }

+ 1
- 0
docs/styling-the-navigator.md View File

108
   // Android only
108
   // Android only
109
   navigationBarColor: '#000000', // change the background color of the bottom native navigation bar.
109
   navigationBarColor: '#000000', // change the background color of the bottom native navigation bar.
110
   navBarTitleTextCentered: true, // default: false. centers the title.
110
   navBarTitleTextCentered: true, // default: false. centers the title.
111
+  navBarSubTitleTextCentered: true, // (Android - default: false, iOS - default: depending on navBarTitleTextCentered). centers the subTitle.
111
   navBarButtonFontFamily: 'sans-serif-thin', // Change the font family of textual buttons
112
   navBarButtonFontFamily: 'sans-serif-thin', // Change the font family of textual buttons
112
   statusBarColor: '#000000', // change the color of the status bar.
113
   statusBarColor: '#000000', // change the color of the status bar.
113
   drawUnderStatusBar: false, // default: false, will draw the screen underneath the statusbar. Useful togheter with statusBarColor: transparent
114
   drawUnderStatusBar: false, // default: false, will draw the screen underneath the statusbar. Useful togheter with statusBarColor: transparent

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

180
     titleBarTitleFontSize: originalStyleObject.navBarTextFontSize,
180
     titleBarTitleFontSize: originalStyleObject.navBarTextFontSize,
181
     titleBarTitleFontBold: originalStyleObject.navBarTextFontBold,
181
     titleBarTitleFontBold: originalStyleObject.navBarTextFontBold,
182
     titleBarTitleTextCentered: originalStyleObject.navBarTitleTextCentered,
182
     titleBarTitleTextCentered: originalStyleObject.navBarTitleTextCentered,
183
+    titleBarSubTitleTextCentered: originalStyleObject.navBarSubTitleTextCentered,
183
     titleBarHeight: originalStyleObject.navBarHeight,
184
     titleBarHeight: originalStyleObject.navBarHeight,
184
     titleBarTopPadding: originalStyleObject.navBarTopPadding,
185
     titleBarTopPadding: originalStyleObject.navBarTopPadding,
185
     backButtonHidden: originalStyleObject.backButtonHidden,
186
     backButtonHidden: originalStyleObject.backButtonHidden,