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
         NavigationCommandsHandler.setScreenTitleBarTitle(screenInstanceId, title);
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
     @ReactMethod
57
     @ReactMethod
53
     public void setScreenTitleBarButtons(String screenInstanceId, String navigatorEventId,
58
     public void setScreenTitleBarButtons(String screenInstanceId, String navigatorEventId,
54
                                          ReadableArray rightButtonsParams, ReadableMap leftButtonParams) {
59
                                          ReadableArray rightButtonsParams, ReadableMap leftButtonParams) {

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

31
         layout.setTitleBarTitle(screenInstanceId, title);
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
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
38
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
35
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
39
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
36
     }
40
     }

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

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
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
95
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
90
         for (Modal modal : stack) {
96
         for (Modal modal : stack) {
91
             modal.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
97
             modal.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);

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

199
         modalController.setTitleBarTitle(screenInstanceId, title);
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
     void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
207
     void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
203
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
208
         layout.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
204
         modalController.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
209
         modalController.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);

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

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
     public static void showModal(Bundle params) {
153
     public static void showModal(Bundle params) {
140
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
154
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
141
         if (currentActivity == null) {
155
         if (currentActivity == null) {

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

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
     @Override
158
     @Override
152
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
159
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
153
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
160
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {

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

17
 
17
 
18
     void setTitleBarTitle(String screenInstanceId, String title);
18
     void setTitleBarTitle(String screenInstanceId, String title);
19
 
19
 
20
+    void setTitleBarSubtitle(String screenInstanceId, String subtitle);
21
+
20
     void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons);
22
     void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons);
21
 
23
 
22
     void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams);
24
     void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams);

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

140
         stack.setScreenTitleBarTitle(screenInstanceId, title);
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
     @Override
148
     @Override
144
     public View asView() {
149
     public View asView() {
145
         return this;
150
         return this;

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

144
         topBar.setTitle(title);
144
         topBar.setTitle(title);
145
     }
145
     }
146
 
146
 
147
+    public void setTitleBarSubtitle(String subtitle) {
148
+        topBar.setSubtitle(subtitle);
149
+    }
150
+
147
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
151
     public void setTitleBarRightButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
148
         setButtonColorFromScreen(titleBarButtons);
152
         setButtonColorFromScreen(titleBarButtons);
149
         topBar.setTitleBarRightButtons(navigatorEventId, titleBarButtons);
153
         topBar.setTitleBarRightButtons(navigatorEventId, titleBarButtons);

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

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
     public void setScreenTitleBarRightButtons(String screenInstanceId, final String navigatorEventId, final List<TitleBarButtonParams> titleBarButtons) {
224
     public void setScreenTitleBarRightButtons(String screenInstanceId, final String navigatorEventId, final List<TitleBarButtonParams> titleBarButtons) {
216
         performOnScreen(screenInstanceId, new Task<Screen>() {
225
         performOnScreen(screenInstanceId, new Task<Screen>() {
217
             @Override
226
             @Override

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

36
         titleBar.setTitle(title);
36
         titleBar.setTitle(title);
37
     }
37
     }
38
 
38
 
39
+    public void setSubtitle(String subtitle) {
40
+        titleBar.setSubtitle(subtitle);
41
+    }
42
+
39
     public void setStyle(StyleParams styleParams) {
43
     public void setStyle(StyleParams styleParams) {
40
         if (styleParams.topBarColor.hasColor()) {
44
         if (styleParams.topBarColor.hasColor()) {
41
             setBackgroundColor(styleParams.topBarColor.getColor());
45
             setBackgroundColor(styleParams.topBarColor.getColor());

+ 4
- 0
src/Screen.js View File

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

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

253
   newPlatformSpecific.setScreenTitleBarTitle(navigator.screenInstanceID, params.title);
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
 function navigatorSwitchToTab(navigator, params) {
260
 function navigatorSwitchToTab(navigator, params) {
257
   if (params.tabIndex >= 0) {
261
   if (params.tabIndex >= 0) {
258
     newPlatformSpecific.selectBottomTabByTabIndex(params.tabIndex);
262
     newPlatformSpecific.selectBottomTabByTabIndex(params.tabIndex);
435
   navigatorSetButtons,
439
   navigatorSetButtons,
436
   navigatorSetTabBadge,
440
   navigatorSetTabBadge,
437
   navigatorSetTitle,
441
   navigatorSetTitle,
442
+  navigatorSetSubtitle,
438
   navigatorSwitchToTab,
443
   navigatorSwitchToTab,
439
   navigatorToggleDrawer,
444
   navigatorToggleDrawer,
440
   navigatorToggleTabs,
445
   navigatorToggleTabs,

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

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