Browse Source

Add basic setNavigationTitle method

Jason Skuby 8 years ago
parent
commit
1d49d576ad

+ 9
- 0
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

@@ -45,6 +45,7 @@ import javax.annotation.Nullable;
45 45
  */
46 46
 public abstract class BaseReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
47 47
 
48
+    protected static final String KEY_TITLE = "title";
48 49
     private static final String TAG = "BaseReactActivity";
49 50
     private static final String REDBOX_PERMISSION_MESSAGE =
50 51
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
@@ -357,4 +358,12 @@ public abstract class BaseReactActivity extends AppCompatActivity implements Def
357 358
         getCurrentScreen().setButtons(buttons);
358 359
         mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
359 360
     }
361
+
362
+    public void setNavigationTitle(ReadableMap title) {
363
+        if (mToolbar == null) {
364
+            return;
365
+        }
366
+
367
+        mToolbar.setTitle(title.getString(KEY_TITLE));
368
+    }
360 369
 }

+ 15
- 1
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

@@ -51,7 +51,7 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
51 51
                 BridgeUtils.addMapToBundle(((ReadableNativeMap) style).toHashMap(), extras);
52 52
             }
53 53
             intent.putExtras(extras);
54
-            
54
+
55 55
             context.startActivity(intent);
56 56
             //TODO add abstract isRoot() instead of instanceof?
57 57
             if(ContextProvider.getActivityContext() instanceof RootActivity) {
@@ -106,6 +106,20 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
106 106
         });
107 107
     }
108 108
 
109
+    @ReactMethod
110
+    public void setNavigatorTitle(final ReadableMap title) {
111
+        final BaseReactActivity context = ContextProvider.getActivityContext();
112
+        if (context == null || context.isFinishing()) {
113
+            return;
114
+        }
115
+        context.runOnUiThread(new Runnable() {
116
+            @Override
117
+            public void run() {
118
+                context.setNavigationTitle(title);
119
+            }
120
+        });
121
+    }
122
+
109 123
     @ReactMethod
110 124
     public void navigatorPush(final ReadableMap skreen) {
111 125
         final Screen screen = new Screen(skreen);

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

@@ -84,6 +84,10 @@ function navigatorResetTo(navigator, params) {
84 84
   RctActivity.navigatorResetTo(params);
85 85
 }
86 86
 
87
+function navigatorSetTitle(navigator, params) {
88
+  RctActivity.setNavigatorTitle(params);
89
+}
90
+
87 91
 function showModal(params) {
88 92
   addNavigatorParams(params);
89 93
   addNavigatorButtons(params);
@@ -139,5 +143,6 @@ export default {
139 143
   showModal,
140 144
   dismissModal,
141 145
   dismissAllModals,
142
-  navigatorSetButtons
146
+  navigatorSetButtons,
147
+  navigatorSetTitle
143 148
 }