Browse Source

Add screen events for side menus on Android (#1324)

Matt Davies 7 years ago
parent
commit
d74751dd80

+ 22
- 0
android/app/src/main/java/com/reactnativenavigation/views/SideMenu.java View File

@@ -4,9 +4,11 @@ import android.content.Context;
4 4
 import android.support.annotation.Nullable;
5 5
 import android.support.v4.widget.DrawerLayout;
6 6
 import android.view.Gravity;
7
+import android.view.View;
7 8
 import android.view.ViewGroup;
8 9
 import android.widget.RelativeLayout;
9 10
 
11
+import com.reactnativenavigation.NavigationApplication;
10 12
 import com.reactnativenavigation.params.SideMenuParams;
11 13
 import com.reactnativenavigation.screens.Screen;
12 14
 import com.reactnativenavigation.utils.ViewUtils;
@@ -29,6 +31,7 @@ public class SideMenu extends DrawerLayout {
29 31
     private ContentView leftSideMenuView;
30 32
     private ContentView rightSideMenuView;
31 33
     private RelativeLayout contentContainer;
34
+    private SimpleDrawerListener sideMenuListener;
32 35
 
33 36
     public RelativeLayout getContentContainer() {
34 37
         return contentContainer;
@@ -43,6 +46,7 @@ public class SideMenu extends DrawerLayout {
43 46
         if (sideMenuView == null) {
44 47
             return;
45 48
         }
49
+        removeDrawerListener(sideMenuListener);
46 50
         sideMenuView.unmountReactView();
47 51
         removeView(sideMenuView);
48 52
     }
@@ -84,6 +88,7 @@ public class SideMenu extends DrawerLayout {
84 88
         rightSideMenuView = createSideMenu(rightMenuParams);
85 89
         setStyle(leftMenuParams);
86 90
         setStyle(rightMenuParams);
91
+        setScreenEventListener();
87 92
     }
88 93
 
89 94
     private void createContentContainer() {
@@ -116,6 +121,23 @@ public class SideMenu extends DrawerLayout {
116 121
         });
117 122
     }
118 123
 
124
+    public void setScreenEventListener() {
125
+        sideMenuListener = new SimpleDrawerListener() {
126
+            @Override
127
+            public void onDrawerOpened(View drawerView) {
128
+                NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willAppear", ((ContentView)drawerView).getNavigatorEventId());
129
+                NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didAppear", ((ContentView)drawerView).getNavigatorEventId());
130
+            }
131
+
132
+            @Override
133
+            public void onDrawerClosed(View drawerView) {
134
+                NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("willDisappear", ((ContentView)drawerView).getNavigatorEventId());
135
+                NavigationApplication.instance.getEventEmitter().sendScreenChangedEvent("didDisappear", ((ContentView)drawerView).getNavigatorEventId());
136
+            }
137
+        };
138
+        addDrawerListener(sideMenuListener);
139
+    }
140
+
119 141
     private void setStyle(SideMenuParams params) {
120 142
         if (params == null) {
121 143
             return;