Procházet zdrojové kódy

set TitleBar title

Guy Carmeli před 8 roky
rodič
revize
f6a768afd0

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Zobrazit soubor

@@ -34,7 +34,8 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
34 34
     }
35 35
 
36 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 41
     @ReactMethod

+ 6
- 2
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Zobrazit soubor

@@ -122,7 +122,11 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
122 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 Zobrazit soubor

@@ -103,4 +103,18 @@ public class NavigationCommandsHandler {
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 Zobrazit soubor

@@ -17,5 +17,7 @@ public interface Layout {
17 17
 
18 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 Zobrazit soubor

@@ -115,4 +115,8 @@ public abstract class Screen extends RelativeLayout implements ScrollDirectionLi
115 115
     public void setTopBarVisible(boolean visible, boolean animate) {
116 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 Zobrazit soubor

@@ -85,8 +85,8 @@ public class ScreenStack extends FrameLayout {
85 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 90
         if (screen != null) {
91 91
             screen.setTopBarVisible(visible, animate);
92 92
         }
@@ -106,6 +106,13 @@ public class ScreenStack extends FrameLayout {
106 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 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 Zobrazit soubor

@@ -71,4 +71,9 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
71 71
     public void setTopBarVisible(String screenInstanceID, boolean visible, boolean animate) {
72 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 Zobrazit soubor

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

+ 6
- 1
src/platformSpecific.android.js Zobrazit soubor

@@ -36,11 +36,16 @@ function toggleTopBarVisible(screenInstanceID, visible, animated) {
36 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 43
 module.exports = {
40 44
   startApp,
41 45
   push,
42 46
   pop,
43 47
   popToRoot,
44 48
   newStack,
45
-  toggleTopBarVisible
49
+  toggleTopBarVisible,
50
+  setScreenTitleBarTitle
46 51
 };