Sfoglia il codice sorgente

Update fab when modal is dismissed

Guy Carmeli 8 anni fa
parent
commit
01fbdd66f5

+ 3
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/ModalController.java Vedi File

@@ -2,6 +2,8 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.support.v7.app.AppCompatActivity;
4 4
 
5
+import com.reactnativenavigation.events.EventBus;
6
+import com.reactnativenavigation.events.ModalDismissedEvent;
5 7
 import com.reactnativenavigation.layouts.ScreenStackContainer;
6 8
 import com.reactnativenavigation.params.ScreenParams;
7 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
@@ -72,6 +74,7 @@ public class ModalController implements ScreenStackContainer, Modal.OnModalDismi
72 74
     @Override
73 75
     public void onModalDismissed(Modal modal) {
74 76
         stack.remove(modal);
77
+        EventBus.instance.post(new ModalDismissedEvent());
75 78
     }
76 79
 
77 80
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {

+ 14
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Vedi File

@@ -7,6 +7,10 @@ import android.view.KeyEvent;
7 7
 
8 8
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9 9
 import com.reactnativenavigation.NavigationApplication;
10
+import com.reactnativenavigation.events.Event;
11
+import com.reactnativenavigation.events.EventBus;
12
+import com.reactnativenavigation.events.ModalDismissedEvent;
13
+import com.reactnativenavigation.events.Subscriber;
10 14
 import com.reactnativenavigation.layouts.BottomTabsLayout;
11 15
 import com.reactnativenavigation.layouts.Layout;
12 16
 import com.reactnativenavigation.layouts.LayoutFactory;
@@ -21,7 +25,7 @@ import com.reactnativenavigation.react.RedboxPermission;
21 25
 
22 26
 import java.util.List;
23 27
 
24
-public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, ReactGateway.OnJsDevReloadListener {
28
+public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, ReactGateway.OnJsDevReloadListener, Subscriber {
25 29
 
26 30
     /**
27 31
      * Although we start multiple activities, we make sure to pass Intent.CLEAR_TASK | Intent.NEW_TASK
@@ -79,6 +83,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
79 83
 
80 84
         currentActivity = this;
81 85
         NavigationApplication.instance.getReactGateway().onResumeActivity(this, this, this);
86
+        EventBus.instance.register(this);
82 87
     }
83 88
 
84 89
     @Override
@@ -86,6 +91,7 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
86 91
         super.onPause();
87 92
         currentActivity = null;
88 93
         NavigationApplication.instance.getReactGateway().onPauseActivity();
94
+        EventBus.instance.unregister(this);
89 95
     }
90 96
 
91 97
     @Override
@@ -249,4 +255,11 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
249 255
     public void showSnackbar(SnackbarParams params) {
250 256
         layout.showSnackbar(params);
251 257
     }
258
+
259
+    @Override
260
+    public void onEvent(Event event) {
261
+        if (event.getType() == ModalDismissedEvent.TYPE) {
262
+            layout.onModalDismissed();
263
+        }
264
+    }
252 265
 }

+ 10
- 0
android/app/src/main/java/com/reactnativenavigation/events/ModalDismissedEvent.java Vedi File

@@ -0,0 +1,10 @@
1
+package com.reactnativenavigation.events;
2
+
3
+public class ModalDismissedEvent implements Event {
4
+    public static final String TYPE = "ModalDismissedEvent";
5
+
6
+    @Override
7
+    public String getType() {
8
+        return TYPE;
9
+    }
10
+}

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Vedi File

@@ -193,6 +193,11 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
193 193
         snackbarAndFabContainer.showSnackbar(eventId, params);
194 194
     }
195 195
 
196
+    @Override
197
+    public void onModalDismissed() {
198
+        EventBus.instance.post(new ScreenChangedEvent(getCurrentScreenStack().peek().getScreenParams()));
199
+    }
200
+
196 201
     public void selectBottomTabByTabIndex(Integer index) {
197 202
         bottomTabs.setCurrentItem(index);
198 203
     }

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

@@ -28,4 +28,6 @@ public interface Layout extends ScreenStackContainer {
28 28
     void setSideMenuVisible(boolean animated, boolean visible);
29 29
 
30 30
     void showSnackbar(SnackbarParams params);
31
+
32
+    void onModalDismissed();
31 33
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Vedi File

@@ -193,6 +193,11 @@ public class SingleScreenLayout extends RelativeLayout implements Layout {
193 193
         snackbarAndFabContainer.showSnackbar(navigatorEventId, params);
194 194
     }
195 195
 
196
+    @Override
197
+    public void onModalDismissed() {
198
+        EventBus.instance.post(new ScreenChangedEvent(stack.peek().getScreenParams()));
199
+    }
200
+
196 201
     @Override
197 202
     public boolean onTitleBarBackButtonClick() {
198 203
         if (leftButtonOnClickListener != null) {