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
  */
45
  */
46
 public abstract class BaseReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
46
 public abstract class BaseReactActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
47
 
47
 
48
+    protected static final String KEY_TITLE = "title";
48
     private static final String TAG = "BaseReactActivity";
49
     private static final String TAG = "BaseReactActivity";
49
     private static final String REDBOX_PERMISSION_MESSAGE =
50
     private static final String REDBOX_PERMISSION_MESSAGE =
50
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
51
             "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
357
         getCurrentScreen().setButtons(buttons);
358
         getCurrentScreen().setButtons(buttons);
358
         mToolbar.setupToolbarButtonsAsync(getCurrentScreen());
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
                 BridgeUtils.addMapToBundle(((ReadableNativeMap) style).toHashMap(), extras);
51
                 BridgeUtils.addMapToBundle(((ReadableNativeMap) style).toHashMap(), extras);
52
             }
52
             }
53
             intent.putExtras(extras);
53
             intent.putExtras(extras);
54
-            
54
+
55
             context.startActivity(intent);
55
             context.startActivity(intent);
56
             //TODO add abstract isRoot() instead of instanceof?
56
             //TODO add abstract isRoot() instead of instanceof?
57
             if(ContextProvider.getActivityContext() instanceof RootActivity) {
57
             if(ContextProvider.getActivityContext() instanceof RootActivity) {
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
     @ReactMethod
123
     @ReactMethod
110
     public void navigatorPush(final ReadableMap skreen) {
124
     public void navigatorPush(final ReadableMap skreen) {
111
         final Screen screen = new Screen(skreen);
125
         final Screen screen = new Screen(skreen);

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

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