Browse Source

Center title when setting title dynamically

Fixes #1609
Guy Carmeli 7 years ago
parent
commit
40fb03ccac

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java View File

@@ -130,7 +130,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
130 130
         if (screenParams.styleParams.hasTopBarCustomComponent()) {
131 131
             topBar.setReactView(screenParams.styleParams);
132 132
         } else {
133
-            topBar.setTitle(screenParams.title);
133
+            topBar.setTitle(screenParams.title, styleParams);
134 134
             topBar.setSubtitle(screenParams.subtitle);
135 135
         }
136 136
     }
@@ -207,7 +207,7 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
207 207
     }
208 208
 
209 209
     public void setTitleBarTitle(String title) {
210
-        topBar.setTitle(title);
210
+       topBar.setTitle(title, styleParams);
211 211
     }
212 212
 
213 213
     public void setTitleBarSubtitle(String subtitle) {

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

@@ -90,6 +90,11 @@ public class TitleBar extends Toolbar {
90 90
         setVisibility(titleBarHidden ? GONE : VISIBLE);
91 91
     }
92 92
 
93
+    public void setTitle(String title, StyleParams styleParams) {
94
+        setTitle(title);
95
+        centerTitle(styleParams);
96
+    }
97
+
93 98
     private Activity getActivity() {
94 99
         Context context = getContext();
95 100
         while (context instanceof ContextWrapper) {

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

@@ -81,8 +81,8 @@ public class TopBar extends AppBarLayout {
81 81
         titleBar.setLeftButton(leftButton, leftButtonOnClickListener, navigatorEventId, overrideBackPressInJs);
82 82
     }
83 83
 
84
-    public void setTitle(String title) {
85
-        titleBar.setTitle(title);
84
+    public void setTitle(String title, StyleParams styleParams) {
85
+        titleBar.setTitle(title, styleParams);
86 86
     }
87 87
 
88 88
     public void setSubtitle(String subtitle) {