Browse Source

set TitleBar title

Guy Carmeli 8 years ago
parent
commit
f6a768afd0

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java View File

34
     }
34
     }
35
 
35
 
36
     @ReactMethod
36
     @ReactMethod
37
-    public void setScreenTitleBarTitle(final ReadableMap params) {
37
+    public void setScreenTitleBarTitle(String screenInstanceId, String title) {
38
+        NavigationCommandsHandler.setScreenTitleBarTitle(screenInstanceId, title);
38
     }
39
     }
39
 
40
 
40
     @ReactMethod
41
     @ReactMethod

+ 6
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

122
         layout.newStack(params);
122
         layout.newStack(params);
123
     }
123
     }
124
 
124
 
125
-    void setTopBarVisible(String screenInstanceID, boolean hidden, boolean animated) {
126
-        layout.setTopBarVisible(screenInstanceID, hidden, animated);
125
+    void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
126
+        layout.setTopBarVisible(screenInstanceId, hidden, animated);
127
+    }
128
+
129
+    void setTitleBarTitle(String screenInstanceId, String title) {
130
+        layout.setTitleBarTitle(screenInstanceId, title);
127
     }
131
     }
128
 }
132
 }

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

103
             }
103
             }
104
         });
104
         });
105
     }
105
     }
106
+
107
+    public static void setScreenTitleBarTitle(final String screenInstanceId, final String title) {
108
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
109
+        if (currentActivity == null) {
110
+            return;
111
+        }
112
+
113
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
114
+            @Override
115
+            public void run() {
116
+                currentActivity.setTitleBarTitle(screenInstanceId, title);
117
+            }
118
+        });
119
+    }
106
 }
120
 }

+ 3
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java View File

17
 
17
 
18
     void newStack(ScreenParams params);
18
     void newStack(ScreenParams params);
19
 
19
 
20
-    void setTopBarVisible(String screenInstanceID, boolean hidden, boolean animated);
20
+    void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated);
21
+
22
+    void setTitleBarTitle(String screenInstanceId, String title);
21
 }
23
 }

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

115
     public void setTopBarVisible(boolean visible, boolean animate) {
115
     public void setTopBarVisible(boolean visible, boolean animate) {
116
         topBarVisibilityAnimator.setVisible(visible, animate);
116
         topBarVisibilityAnimator.setVisible(visible, animate);
117
     }
117
     }
118
+
119
+    public void setTitleBarTitle(String title) {
120
+        topBar.setTitle(title);
121
+    }
118
 }
122
 }

+ 9
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java View File

85
         return getStackSize() > 1;
85
         return getStackSize() > 1;
86
     }
86
     }
87
 
87
 
88
-    public void setTopBarVisible(String screenInstanceID, boolean visible, boolean animate) {
89
-        Screen screen = findScreenByScreenInstanceId(screenInstanceID);
88
+    public void setTopBarVisible(String screenInstanceId, boolean visible, boolean animate) {
89
+        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
90
         if (screen != null) {
90
         if (screen != null) {
91
             screen.setTopBarVisible(visible, animate);
91
             screen.setTopBarVisible(visible, animate);
92
         }
92
         }
106
         return null;
106
         return null;
107
     }
107
     }
108
 
108
 
109
+    public void setTitleBarTitle(String screenInstanceId, String title) {
110
+        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
111
+        if (screen != null) {
112
+            screen.setTitleBarTitle(title);
113
+        }
114
+    }
115
+
109
 
116
 
110
     //    /**
117
     //    /**
111
 //     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted
118
 //     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted

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

71
     public void setTopBarVisible(String screenInstanceID, boolean visible, boolean animate) {
71
     public void setTopBarVisible(String screenInstanceID, boolean visible, boolean animate) {
72
         stack.setTopBarVisible(screenInstanceID, visible, animate);
72
         stack.setTopBarVisible(screenInstanceID, visible, animate);
73
     }
73
     }
74
+
75
+    @Override
76
+    public void setTitleBarTitle(String screenInstanceId, String title) {
77
+        stack.setTitleBarTitle(screenInstanceId, title);
78
+    }
74
 }
79
 }

+ 1
- 1
src/deprecated/platformSpecificDeprecated.android.js View File

159
 }
159
 }
160
 
160
 
161
 function navigatorSetTitle(navigator, params) {
161
 function navigatorSetTitle(navigator, params) {
162
-  //RctActivity.setNavigatorTitle(params);
162
+  newPlatformSpecific.setScreenTitleBarTitle(navigator.screenInstanceID, params);
163
 }
163
 }
164
 
164
 
165
 function navigatorSwitchToTab(navigator, params) {
165
 function navigatorSwitchToTab(navigator, params) {

+ 6
- 1
src/platformSpecific.android.js View File

36
   NativeModules.NavigationReactModule.setTopBarVisible(screenInstanceID, visible, animated);
36
   NativeModules.NavigationReactModule.setTopBarVisible(screenInstanceID, visible, animated);
37
 }
37
 }
38
 
38
 
39
+function setScreenTitleBarTitle(screenInstanceID, title) {
40
+  NativeModules.NavigationReactModule.setScreenTitleBarTitle(screenInstanceID, title);
41
+}
42
+
39
 module.exports = {
43
 module.exports = {
40
   startApp,
44
   startApp,
41
   push,
45
   push,
42
   pop,
46
   pop,
43
   popToRoot,
47
   popToRoot,
44
   newStack,
48
   newStack,
45
-  toggleTopBarVisible
49
+  toggleTopBarVisible,
50
+  setScreenTitleBarTitle
46
 };
51
 };