Browse Source

Add TitleBar subtitle support on Android

Guy Carmeli 8 years ago
parent
commit
7e0b9ed132

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

@@ -49,6 +49,11 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
49 49
         NavigationCommandsHandler.setScreenTitleBarTitle(screenInstanceId, title);
50 50
     }
51 51
 
52
+    @ReactMethod
53
+    public void setScreenTitleBarSubtitle(String screenInstanceId, String subtitle) {
54
+        NavigationCommandsHandler.setScreenTitleBarSubtitle(screenInstanceId, subtitle);
55
+    }
56
+
52 57
     @ReactMethod
53 58
     public void setScreenTitleBarButtons(String screenInstanceId, String navigatorEventId,
54 59
                                          ReadableArray rightButtonsParams, ReadableMap leftButtonParams) {

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java View File

@@ -31,6 +31,10 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
31 31
         layout.setTitleBarTitle(screenInstanceId, title);
32 32
     }
33 33
 
34
+    public void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
35
+        layout.setTitleBarSubtitle(screenInstanceId, subtitle);
36
+    }
37
+
34 38
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
35 39
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
36 40
     }

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java View File

@@ -86,6 +86,12 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
86 86
         }
87 87
     }
88 88
 
89
+    public void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
90
+        for (Modal modal : stack) {
91
+            modal.setTitleBarSubtitle(screenInstanceId, subtitle);
92
+        }
93
+    }
94
+
89 95
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
90 96
         for (Modal modal : stack) {
91 97
             modal.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -199,6 +199,11 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
199 199
         modalController.setTitleBarTitle(screenInstanceId, title);
200 200
     }
201 201
 
202
+    public void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
203
+        layout.setTitleBarSubtitle(screenInstanceId, subtitle);
204
+        modalController.setTitleBarSubtitle(screenInstanceId, subtitle);
205
+    }
206
+
202 207
     void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
203 208
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
204 209
         modalController.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java View File

@@ -136,6 +136,20 @@ public class NavigationCommandsHandler {
136 136
         });
137 137
     }
138 138
 
139
+    public static void setScreenTitleBarSubtitle(final String screenInstanceId, final String subtitle) {
140
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
141
+        if (currentActivity == null) {
142
+            return;
143
+        }
144
+
145
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
146
+            @Override
147
+            public void run() {
148
+                currentActivity.setTitleBarSubtitle(screenInstanceId, subtitle);
149
+            }
150
+        });
151
+    }
152
+
139 153
     public static void showModal(Bundle params) {
140 154
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
141 155
         if (currentActivity == null) {

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java View File

@@ -148,6 +148,13 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
148 148
         }
149 149
     }
150 150
 
151
+    @Override
152
+    public void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
153
+        for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
154
+            screenStacks[i].setScreenTitleBarSubtitle(screenInstanceId, subtitle);
155
+        }
156
+    }
157
+
151 158
     @Override
152 159
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
153 160
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java View File

@@ -17,6 +17,8 @@ public interface Layout extends ScreenStackContainer {
17 17
 
18 18
     void setTitleBarTitle(String screenInstanceId, String title);
19 19
 
20
+    void setTitleBarSubtitle(String screenInstanceId, String subtitle);
21
+
20 22
     void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons);
21 23
 
22 24
     void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams);

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java View File

@@ -140,6 +140,11 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
140 140
         stack.setScreenTitleBarTitle(screenInstanceId, title);
141 141
     }
142 142
 
143
+    @Override
144
+    public void setTitleBarSubtitle(String screenInstanceId, String subtitle) {
145
+        stack.setScreenTitleBarSubtitle(screenInstanceId, subtitle);
146
+    }
147
+
143 148
     @Override
144 149
     public View asView() {
145 150
         return this;

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

@@ -144,6 +144,10 @@ public abstract class Screen extends RelativeLayout {
144 144
         topBar.setTitle(title);
145 145
     }
146 146
 
147
+    public void setTitleBarSubtitle(String subtitle) {
148
+        topBar.setSubtitle(subtitle);
149
+    }
150
+
147 151
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
148 152
         setButtonColorFromScreen(titleBarButtons);
149 153
         topBar.setTitleBarRightButtons(navigatorEventId, titleBarButtons);

+ 9
- 0
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java View File

@@ -212,6 +212,15 @@ public class ScreenStack {
212 212
         });
213 213
     }
214 214
 
215
+    public void setScreenTitleBarSubtitle(String screenInstanceId, final String subtitle) {
216
+        performOnScreen(screenInstanceId, new Task<Screen>() {
217
+            @Override
218
+            public void run(Screen param) {
219
+                param.setTitleBarSubtitle(subtitle);
220
+            }
221
+        });
222
+    }
223
+
215 224
     public void setScreenTitleBarRightButtons(String screenInstanceId, final String navigatorEventId, final List<TitleBarButtonParams> titleBarButtons) {
216 225
         performOnScreen(screenInstanceId, new Task<Screen>() {
217 226
             @Override

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

@@ -36,6 +36,10 @@ public class TopBar extends AppBarLayout {
36 36
         titleBar.setTitle(title);
37 37
     }
38 38
 
39
+    public void setSubtitle(String subtitle) {
40
+        titleBar.setSubtitle(subtitle);
41
+    }
42
+
39 43
     public void setStyle(StyleParams styleParams) {
40 44
         if (styleParams.topBarColor.hasColor()) {
41 45
             setBackgroundColor(styleParams.topBarColor.getColor());

+ 4
- 0
src/Screen.js View File

@@ -77,6 +77,10 @@ class Navigator {
77 77
     return platformSpecific.navigatorSetTitle(this, params);
78 78
   }
79 79
 
80
+  setSubTitle(params = {}) {
81
+    return platformSpecific.navigatorSetSubtitle(this, params);
82
+  }
83
+
80 84
   setTitleImage(params = {}) {
81 85
     return platformSpecific.navigatorSetTitleImage(this, params);
82 86
   }

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

@@ -253,6 +253,10 @@ function navigatorSetTitle(navigator, params) {
253 253
   newPlatformSpecific.setScreenTitleBarTitle(navigator.screenInstanceID, params.title);
254 254
 }
255 255
 
256
+function navigatorSetSubtitle(navigator, params) {
257
+  newPlatformSpecific.setScreenTitleBarSubtitle(navigator.screenInstanceID, params.subtitle);
258
+}
259
+
256 260
 function navigatorSwitchToTab(navigator, params) {
257 261
   if (params.tabIndex >= 0) {
258 262
     newPlatformSpecific.selectBottomTabByTabIndex(params.tabIndex);
@@ -435,6 +439,7 @@ export default {
435 439
   navigatorSetButtons,
436 440
   navigatorSetTabBadge,
437 441
   navigatorSetTitle,
442
+  navigatorSetSubtitle,
438 443
   navigatorSwitchToTab,
439 444
   navigatorToggleDrawer,
440 445
   navigatorToggleTabs,

+ 5
- 0
src/platformSpecific.android.js View File

@@ -40,6 +40,10 @@ function setScreenTitleBarTitle(screenInstanceID, title) {
40 40
   NativeReactModule.setScreenTitleBarTitle(screenInstanceID, title);
41 41
 }
42 42
 
43
+function setScreenTitleBarSubtitle(screenInstanceID, subtitle) {
44
+  NativeReactModule.setScreenTitleBarSubtitle(screenInstanceID, subtitle);
45
+}
46
+
43 47
 function setScreenTitleBarButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton) {
44 48
   NativeReactModule.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, rightButtons, leftButton);
45 49
 }
@@ -121,6 +125,7 @@ module.exports = {
121 125
   toggleTopBarVisible,
122 126
   toggleBottomTabsVisible,
123 127
   setScreenTitleBarTitle,
128
+  setScreenTitleBarSubtitle,
124 129
   setScreenTitleBarButtons,
125 130
   showModal,
126 131
   dismissTopModal,