Browse Source

Display correct tab title in ToolBar

Guy Carmeli 8 years ago
parent
commit
df4750a361

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

38
     }
38
     }
39
 
39
 
40
     private void setupToolbar(ArrayList<Screen> screens) {
40
     private void setupToolbar(ArrayList<Screen> screens) {
41
-        setNavigationColors(screens.get(0));
41
+        Screen initialScreen = screens.get(0);
42
+        setNavigationColors(initialScreen);
42
         mToolbar.setScreens(screens);
43
         mToolbar.setScreens(screens);
44
+        mToolbar.setTitle(initialScreen.title == null ? "" : initialScreen.title);
43
         setSupportActionBar(mToolbar);
45
         setSupportActionBar(mToolbar);
44
     }
46
     }
45
 
47
 

+ 5
- 1
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java View File

92
 
92
 
93
     @Override
93
     @Override
94
     public CharSequence getPageTitle(int position) {
94
     public CharSequence getPageTitle(int position) {
95
-        return mScreenStacks.get(position).peek().title;
95
+        return mScreenStacks.get(position).peek().label;
96
     }
96
     }
97
 
97
 
98
     @Override
98
     @Override
101
         int position = tab.getPosition();
101
         int position = tab.getPosition();
102
         mViewPager.setCurrentItem(position);
102
         mViewPager.setCurrentItem(position);
103
 
103
 
104
+        // Set screen buttons
104
         Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
105
         Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
105
         Screen newScreen = mScreenStacks.get(position).peek();
106
         Screen newScreen = mScreenStacks.get(position).peek();
106
         mToolbar.setupToolbarButtonsAsync(prevScreen, newScreen);
107
         mToolbar.setupToolbarButtonsAsync(prevScreen, newScreen);
107
 
108
 
109
+        // Set title
110
+        mToolbar.setTitle(newScreen.title == null ? "" : newScreen.title);
111
+
108
         // Send tab selected event
112
         // Send tab selected event
109
         WritableMap params = Arguments.createMap();
113
         WritableMap params = Arguments.createMap();
110
         Screen screen = mScreenStacks.get(position).peek();
114
         Screen screen = mScreenStacks.get(position).peek();

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/core/objects/Screen.java View File

20
 
20
 
21
     private static final String KEY_TITLE = "title";
21
     private static final String KEY_TITLE = "title";
22
     private static final String KEY_SCREEN = "screen";
22
     private static final String KEY_SCREEN = "screen";
23
+    private static final String KEY_LABEL = "label";
23
     public static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
24
     public static final String KEY_SCREEN_INSTANCE_ID = "screenInstanceID";
24
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
25
     public static final String KEY_NAVIGATOR_ID = "navigatorID";
25
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
26
     public static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
36
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
37
     private static final String KEY_TAB_INDICATOR_COLOR = "tabIndicatorColor";
37
 
38
 
38
     public String title;
39
     public String title;
40
+    public String label;
39
     public String screenId;
41
     public String screenId;
40
     public String screenInstanceId;
42
     public String screenInstanceId;
41
     public String navigatorId;
43
     public String navigatorId;
60
 
62
 
61
     public Screen(ReadableMap screen) {
63
     public Screen(ReadableMap screen) {
62
         title = getString(screen, KEY_TITLE);
64
         title = getString(screen, KEY_TITLE);
65
+        label = getString(screen, KEY_LABEL);
63
         screenId = getString(screen, KEY_SCREEN);
66
         screenId = getString(screen, KEY_SCREEN);
64
         screenInstanceId = getString(screen, KEY_SCREEN_INSTANCE_ID);
67
         screenInstanceId = getString(screen, KEY_SCREEN_INSTANCE_ID);
65
         navigatorId = getString(screen, KEY_NAVIGATOR_ID);
68
         navigatorId = getString(screen, KEY_NAVIGATOR_ID);