Daniel Zlotin 8 years ago
parent
commit
a356dd875f

+ 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

127
         layout.newStack(params);
127
         layout.newStack(params);
128
     }
128
     }
129
 
129
 
130
-    void setTopBarVisible(String screenInstanceID, boolean hidden, boolean animated) {
131
-        layout.setTopBarVisible(screenInstanceID, hidden, animated);
130
+    void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
131
+        layout.setTopBarVisible(screenInstanceId, hidden, animated);
132
+    }
133
+
134
+    void setTitleBarTitle(String screenInstanceId, String title) {
135
+        layout.setTitleBarTitle(screenInstanceId, title);
132
     }
136
     }
133
 
137
 
134
     void showModal(ScreenParams screenParams) {
138
     void showModal(ScreenParams screenParams) {

+ 16
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java View File

104
         });
104
         });
105
     }
105
     }
106
 
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
+    }
120
+
121
+
107
     public static void showModal(Bundle params) {
122
     public static void showModal(Bundle params) {
108
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
123
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
109
         if (currentActivity == null) {
124
         if (currentActivity == null) {
117
             public void run() {
132
             public void run() {
118
                 currentActivity.showModal(screenParams);
133
                 currentActivity.showModal(screenParams);
119
             }
134
             }
120
-        });
121
-    }
135
+        }
122
 }
136
 }

+ 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
example-redux/src/app.js View File

37
       case 'login':
37
       case 'login':
38
         Navigation.startSingleScreenApp({
38
         Navigation.startSingleScreenApp({
39
           screen: {
39
           screen: {
40
-            screen: 'example.ListScreen',
40
+            screen: 'example.FirstTabScreen',
41
             title: 'Login',
41
             title: 'Login',
42
             navigatorStyle: {}
42
             navigatorStyle: {}
43
           },
43
           },

+ 12
- 3
example-redux/src/screens/FirstTabScreen.js View File

9
 } from 'react-native';
9
 } from 'react-native';
10
 import {connect} from 'react-redux';
10
 import {connect} from 'react-redux';
11
 import * as counterActions from '../reducers/counter/actions';
11
 import * as counterActions from '../reducers/counter/actions';
12
+import _ from 'lodash';
12
 
13
 
13
-let navBarVisiable = true;
14
+let topBarVisible = true;
14
 
15
 
15
 // this is a traditional React component connected to the redux store
16
 // this is a traditional React component connected to the redux store
16
 class FirstTabScreen extends Component {
17
 class FirstTabScreen extends Component {
83
           <Text style={styles.button}>Toggle NavBar</Text>
84
           <Text style={styles.button}>Toggle NavBar</Text>
84
         </TouchableOpacity>
85
         </TouchableOpacity>
85
 
86
 
87
+        <TouchableOpacity onPress={ this.onSetTitlePress.bind(this) }>
88
+          <Text style={styles.button}>Set Title</Text>
89
+        </TouchableOpacity>
90
+
86
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
91
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
87
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
92
         <Text style={{fontWeight: '500'}}>Number prop: {this.props.num}</Text>
88
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
93
         <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
134
   }
139
   }
135
 
140
 
136
   onToggleNavBarPress() {
141
   onToggleNavBarPress() {
137
-    navBarVisiable = !navBarVisiable;
142
+    topBarVisible = !topBarVisible;
138
     this.props.navigator.toggleNavBar({
143
     this.props.navigator.toggleNavBar({
139
-      to: navBarVisiable ? 'shown' : 'hidden',
144
+      to: topBarVisible ? 'shown' : 'hidden',
140
       animated: true
145
       animated: true
141
     });
146
     });
142
   }
147
   }
148
+
149
+  onSetTitlePress() {
150
+    this.props.navigator.setTitle(_.random(0, 100).toString());
151
+  }
143
 }
152
 }
144
 
153
 
145
 const styles = StyleSheet.create({
154
 const styles = StyleSheet.create({

+ 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
 };