Quellcode durchsuchen

Display correct tab title in ToolBar

Guy Carmeli vor 8 Jahren
Ursprung
Commit
df4750a361

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java Datei anzeigen

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

+ 5
- 1
android/app/src/main/java/com/reactnativenavigation/adapters/ViewPagerAdapter.java Datei anzeigen

@@ -92,7 +92,7 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
92 92
 
93 93
     @Override
94 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 98
     @Override
@@ -101,10 +101,14 @@ public class ViewPagerAdapter extends PagerAdapter implements TabLayout.OnTabSel
101 101
         int position = tab.getPosition();
102 102
         mViewPager.setCurrentItem(position);
103 103
 
104
+        // Set screen buttons
104 105
         Screen prevScreen = mScreenStacks.get(mCurrentPage).peek();
105 106
         Screen newScreen = mScreenStacks.get(position).peek();
106 107
         mToolbar.setupToolbarButtonsAsync(prevScreen, newScreen);
107 108
 
109
+        // Set title
110
+        mToolbar.setTitle(newScreen.title == null ? "" : newScreen.title);
111
+
108 112
         // Send tab selected event
109 113
         WritableMap params = Arguments.createMap();
110 114
         Screen screen = mScreenStacks.get(position).peek();

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

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