Browse Source

Implement ContextualMenu in Modals

Guy Carmeli 8 years ago
parent
commit
08f4d4dc07

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

@@ -175,14 +175,14 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
175 175
     }
176 176
 
177 177
     @ReactMethod
178
-    public void showContextualMenu(final ReadableMap params, final Callback onButtonClicked) {
178
+    public void showContextualMenu(final String screenInstanceId, final ReadableMap params, final Callback onButtonClicked) {
179 179
         ContextualMenuParams contextualMenuParams =
180 180
                 new ContextualMenuParamsParser().parse(BundleConverter.toBundle(params));
181
-        NavigationCommandsHandler.showContextualMenu(contextualMenuParams, onButtonClicked);
181
+        NavigationCommandsHandler.showContextualMenu(screenInstanceId, contextualMenuParams, onButtonClicked);
182 182
     }
183 183
 
184 184
     @ReactMethod
185
-    public void dismissContextualMenu() {
186
-        NavigationCommandsHandler.dismissContextualMenu();
185
+    public void dismissContextualMenu(String screenInstanceId) {
186
+        NavigationCommandsHandler.dismissContextualMenu(screenInstanceId);
187 187
     }
188 188
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java View File

@@ -6,10 +6,12 @@ import android.support.v7.app.AppCompatActivity;
6 6
 import android.view.Window;
7 7
 import android.view.WindowManager;
8 8
 
9
+import com.facebook.react.bridge.Callback;
9 10
 import com.reactnativenavigation.R;
10 11
 import com.reactnativenavigation.layouts.Layout;
11 12
 import com.reactnativenavigation.layouts.ModalScreenLayout;
12 13
 import com.reactnativenavigation.layouts.ScreenStackContainer;
14
+import com.reactnativenavigation.params.ContextualMenuParams;
13 15
 import com.reactnativenavigation.params.ScreenParams;
14 16
 import com.reactnativenavigation.params.TitleBarButtonParams;
15 17
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
@@ -43,6 +45,14 @@ public class Modal extends Dialog implements DialogInterface.OnDismissListener,
43 45
         layout.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButton);
44 46
     }
45 47
 
48
+    public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
49
+        layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
50
+    }
51
+
52
+    public void dismissContextualMenu(String screenInstanceId) {
53
+        layout.dismissContextualMenu(screenInstanceId);
54
+    }
55
+
46 56
     @Override
47 57
     public boolean onTitleBarBackButtonClick() {
48 58
         if (!layout.onBackPressed()) {

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

@@ -2,9 +2,11 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.support.v7.app.AppCompatActivity;
4 4
 
5
+import com.facebook.react.bridge.Callback;
5 6
 import com.reactnativenavigation.events.EventBus;
6 7
 import com.reactnativenavigation.events.ModalDismissedEvent;
7 8
 import com.reactnativenavigation.layouts.ScreenStackContainer;
9
+import com.reactnativenavigation.params.ContextualMenuParams;
8 10
 import com.reactnativenavigation.params.ScreenParams;
9 11
 import com.reactnativenavigation.params.TitleBarButtonParams;
10 12
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
@@ -119,6 +121,18 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
119 121
         }
120 122
     }
121 123
 
124
+    public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
125
+        for (Modal modal : stack) {
126
+            modal.showContextualMenu(screenInstanceId, params, onButtonClicked);
127
+        }
128
+    }
129
+
130
+    public void dismissContextualMenu(String screenInstanceId) {
131
+        for (Modal modal : stack) {
132
+            modal.dismissContextualMenu(screenInstanceId);
133
+        }
134
+    }
135
+
122 136
     @Override
123 137
     public boolean onTitleBarBackButtonClick() {
124 138
         // Do nothing and let the layout handle the back button click

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

@@ -250,12 +250,14 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
250 250
         layout.showSnackbar(params);
251 251
     }
252 252
 
253
-    public void showContextualMenu(ContextualMenuParams params, Callback onButtonClicked) {
254
-        layout.showContextualMenu(params, onButtonClicked);
253
+    public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
254
+        layout.showContextualMenu(screenInstanceId, params, onButtonClicked);
255
+        modalController.showContextualMenu(screenInstanceId, params, onButtonClicked);
255 256
     }
256 257
 
257
-    public void dismissContextualMenu() {
258
-        layout.dismissContextualMenu();
258
+    public void dismissContextualMenu(String screenInstanceId) {
259
+        layout.dismissContextualMenu(screenInstanceId);
260
+        modalController.dismissContextualMenu(screenInstanceId);
259 261
     }
260 262
 
261 263
     @Override

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

@@ -331,7 +331,7 @@ public class NavigationCommandsHandler {
331 331
         });
332 332
     }
333 333
 
334
-    public static void showContextualMenu(final ContextualMenuParams params, final Callback onButtonClicked) {
334
+    public static void showContextualMenu(final String screenInstanceId, final ContextualMenuParams params, final Callback onButtonClicked) {
335 335
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
336 336
         if (currentActivity == null) {
337 337
             return;
@@ -340,12 +340,12 @@ public class NavigationCommandsHandler {
340 340
         NavigationApplication.instance.runOnMainThread(new Runnable() {
341 341
             @Override
342 342
             public void run() {
343
-                currentActivity.showContextualMenu(params, onButtonClicked);
343
+                currentActivity.showContextualMenu(screenInstanceId, params, onButtonClicked);
344 344
             }
345 345
         });
346 346
     }
347 347
 
348
-    public static void dismissContextualMenu() {
348
+    public static void dismissContextualMenu(final String screenInstanceId) {
349 349
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
350 350
         if (currentActivity == null) {
351 351
             return;
@@ -354,7 +354,7 @@ public class NavigationCommandsHandler {
354 354
         NavigationApplication.instance.runOnMainThread(new Runnable() {
355 355
             @Override
356 356
             public void run() {
357
-                currentActivity.dismissContextualMenu();
357
+                currentActivity.dismissContextualMenu(screenInstanceId);
358 358
             }
359 359
         });
360 360
     }

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

@@ -207,12 +207,12 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
207 207
     }
208 208
 
209 209
     @Override
210
-    public void showContextualMenu(ContextualMenuParams params, Callback onButtonClicked) {
210
+    public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
211 211
         getCurrentScreenStack().peek().showContextualMenu(params, onButtonClicked);
212 212
     }
213 213
 
214 214
     @Override
215
-    public void dismissContextualMenu() {
215
+    public void dismissContextualMenu(String screenInstanceId) {
216 216
         getCurrentScreenStack().peek().dismissContextualMenu();
217 217
     }
218 218
 

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

@@ -35,7 +35,7 @@ public interface Layout extends ScreenStackContainer {
35 35
 
36 36
     boolean containsNavigator(String navigatorId);
37 37
 
38
-    void showContextualMenu(ContextualMenuParams params, Callback onButtonClicked);
38
+    void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked);
39 39
 
40
-    void dismissContextualMenu();
40
+    void dismissContextualMenu(String screenInstanceId);
41 41
 }

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

@@ -212,13 +212,13 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
212 212
     }
213 213
 
214 214
     @Override
215
-    public void showContextualMenu(ContextualMenuParams params, Callback onButtonClicked) {
216
-        stack.peek().showContextualMenu(params, onButtonClicked);
215
+    public void showContextualMenu(String screenInstanceId, ContextualMenuParams params, Callback onButtonClicked) {
216
+        stack.showContextualMenu(screenInstanceId, params, onButtonClicked);
217 217
     }
218 218
 
219 219
     @Override
220
-    public void dismissContextualMenu() {
221
-        stack.peek().dismissContextualMenu();
220
+    public void dismissContextualMenu(String screenInstanceId) {
221
+        stack.dismissContextualMenu(screenInstanceId);
222 222
     }
223 223
 
224 224
     @Override

+ 20
- 0
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java View File

@@ -7,7 +7,9 @@ import android.view.View;
7 7
 import android.widget.RelativeLayout;
8 8
 import android.widget.RelativeLayout.LayoutParams;
9 9
 
10
+import com.facebook.react.bridge.Callback;
10 11
 import com.reactnativenavigation.NavigationApplication;
12
+import com.reactnativenavigation.params.ContextualMenuParams;
11 13
 import com.reactnativenavigation.params.ScreenParams;
12 14
 import com.reactnativenavigation.params.StyleParams;
13 15
 import com.reactnativenavigation.params.TitleBarButtonParams;
@@ -236,6 +238,24 @@ public class ScreenStack {
236 238
         });
237 239
     }
238 240
 
241
+    public void showContextualMenu(String screenInstanceId, final ContextualMenuParams params, final Callback onButtonClicked) {
242
+        performOnScreen(screenInstanceId, new Task<Screen>() {
243
+            @Override
244
+            public void run(Screen screen) {
245
+                screen.showContextualMenu(params, onButtonClicked);
246
+            }
247
+        });
248
+    }
249
+
250
+    public void dismissContextualMenu(String screenInstanceId) {
251
+        performOnScreen(screenInstanceId, new Task<Screen>() {
252
+            @Override
253
+            public void run(Screen screen) {
254
+                screen.dismissContextualMenu();
255
+            }
256
+        });
257
+    }
258
+
239 259
     public StyleParams getCurrentScreenStyleParams() {
240 260
         return stack.peek().getStyleParams();
241 261
     }

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

@@ -466,7 +466,7 @@ function showSnackbar(navigator, params) {
466 466
   return newPlatformSpecific.showSnackbar(params);
467 467
 }
468 468
 
469
-function showContextualMenu(navigator, params, onButtonPressed) {
469
+function showContextualMenu(navigator, params) {
470 470
   const contextualMenu = {
471 471
     buttons: [],
472 472
     backButton: {id: 'back'},
@@ -483,7 +483,7 @@ function showContextualMenu(navigator, params, onButtonPressed) {
483 483
     contextualMenu.buttons.push(btn);
484 484
   });
485 485
 
486
-  newPlatformSpecific.showContextualMenu(contextualMenu, onButtonPressed);
486
+  newPlatformSpecific.showContextualMenu(navigator.screenInstanceID, contextualMenu, params.onButtonPressed);
487 487
 }
488 488
 
489 489
 function dismissContextualMenu() {

+ 4
- 4
src/platformSpecific.android.js View File

@@ -120,12 +120,12 @@ function showSnackbar(params) {
120 120
   NativeReactModule.showSnackbar(params);
121 121
 }
122 122
 
123
-function showContextualMenu(params, onButtonPressed) {
124
-  NativeReactModule.showContextualMenu(params, onButtonPressed);
123
+function showContextualMenu(screenInstanceID, params, onButtonPressed) {
124
+  NativeReactModule.showContextualMenu(screenInstanceID, params, onButtonPressed);
125 125
 }
126 126
 
127
-function dismissContextualMenu() {
128
-  NativeReactModule.dismissContextualMenu();
127
+function dismissContextualMenu(screenInstanceID) {
128
+  NativeReactModule.dismissContextualMenu(screenInstanceID);
129 129
 }
130 130
 
131 131
 module.exports = {