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
 import android.support.annotation.Nullable;
4
 import android.support.annotation.Nullable;
5
 import android.support.v4.widget.DrawerLayout;
5
 import android.support.v4.widget.DrawerLayout;
6
 import android.view.Gravity;
6
 import android.view.Gravity;
7
+import android.view.View;
7
 import android.view.ViewGroup;
8
 import android.view.ViewGroup;
8
 import android.widget.RelativeLayout;
9
 import android.widget.RelativeLayout;
9
 
10
 
11
+import com.reactnativenavigation.NavigationApplication;
10
 import com.reactnativenavigation.params.SideMenuParams;
12
 import com.reactnativenavigation.params.SideMenuParams;
11
 import com.reactnativenavigation.screens.Screen;
13
 import com.reactnativenavigation.screens.Screen;
12
 import com.reactnativenavigation.utils.ViewUtils;
14
 import com.reactnativenavigation.utils.ViewUtils;
29
     private ContentView leftSideMenuView;
31
     private ContentView leftSideMenuView;
30
     private ContentView rightSideMenuView;
32
     private ContentView rightSideMenuView;
31
     private RelativeLayout contentContainer;
33
     private RelativeLayout contentContainer;
34
+    private SimpleDrawerListener sideMenuListener;
32
 
35
 
33
     public RelativeLayout getContentContainer() {
36
     public RelativeLayout getContentContainer() {
34
         return contentContainer;
37
         return contentContainer;
43
         if (sideMenuView == null) {
46
         if (sideMenuView == null) {
44
             return;
47
             return;
45
         }
48
         }
49
+        removeDrawerListener(sideMenuListener);
46
         sideMenuView.unmountReactView();
50
         sideMenuView.unmountReactView();
47
         removeView(sideMenuView);
51
         removeView(sideMenuView);
48
     }
52
     }
84
         rightSideMenuView = createSideMenu(rightMenuParams);
88
         rightSideMenuView = createSideMenu(rightMenuParams);
85
         setStyle(leftMenuParams);
89
         setStyle(leftMenuParams);
86
         setStyle(rightMenuParams);
90
         setStyle(rightMenuParams);
91
+        setScreenEventListener();
87
     }
92
     }
88
 
93
 
89
     private void createContentContainer() {
94
     private void createContentContainer() {
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
     private void setStyle(SideMenuParams params) {
141
     private void setStyle(SideMenuParams params) {
120
         if (params == null) {
142
         if (params == null) {
121
             return;
143
             return;