Browse Source

Snacker works in SingleScreenLayout

Guy Carmeli 8 years ago
parent
commit
4754164874

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

13
 import com.reactnativenavigation.screens.ScreenStack;
13
 import com.reactnativenavigation.screens.ScreenStack;
14
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
14
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
15
 import com.reactnativenavigation.views.SideMenu;
15
 import com.reactnativenavigation.views.SideMenu;
16
+import com.reactnativenavigation.views.SnackbarContainer;
16
 
17
 
17
 import java.util.List;
18
 import java.util.List;
18
 
19
 
19
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
20
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
21
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
20
 
22
 
21
 public class SingleScreenLayout extends RelativeLayout implements Layout {
23
 public class SingleScreenLayout extends RelativeLayout implements Layout {
22
 
24
 
24
     protected final ScreenParams screenParams;
26
     protected final ScreenParams screenParams;
25
     private final SideMenuParams sideMenuParams;
27
     private final SideMenuParams sideMenuParams;
26
     protected ScreenStack stack;
28
     protected ScreenStack stack;
29
+    private SnackbarContainer snackbarContainer;
27
     protected LeftButtonOnClickListener leftButtonOnClickListener;
30
     protected LeftButtonOnClickListener leftButtonOnClickListener;
28
     private @Nullable SideMenu sideMenu;
31
     private @Nullable SideMenu sideMenu;
29
 
32
 
37
 
40
 
38
     private void createLayout() {
41
     private void createLayout() {
39
         if (sideMenuParams == null) {
42
         if (sideMenuParams == null) {
40
-            createStack(this);
43
+            createStack(getScreenStackParent());
41
         } else {
44
         } else {
42
             sideMenu = createSideMenu();
45
             sideMenu = createSideMenu();
43
-            createStack(sideMenu.getContentContainer());
46
+            createStack(getScreenStackParent());
44
         }
47
         }
48
+        createSnackbarContainer();
49
+    }
50
+
51
+    private RelativeLayout getScreenStackParent() {
52
+        return sideMenu == null ? this : sideMenu.getContentContainer();
45
     }
53
     }
46
 
54
 
47
     private SideMenu createSideMenu() {
55
     private SideMenu createSideMenu() {
65
         stack.show();
73
         stack.show();
66
     }
74
     }
67
 
75
 
76
+    private void createSnackbarContainer() {
77
+        snackbarContainer = new SnackbarContainer(getContext());
78
+        RelativeLayout.LayoutParams lp = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);
79
+        lp.addRule(ALIGN_PARENT_BOTTOM);
80
+        snackbarContainer.setLayoutParams(lp);
81
+        getScreenStackParent().addView(snackbarContainer);
82
+    }
83
+
68
     @Override
84
     @Override
69
     public boolean onBackPressed() {
85
     public boolean onBackPressed() {
70
         if (stack.handleBackPressInJs()) {
86
         if (stack.handleBackPressInJs()) {
151
 
167
 
152
     @Override
168
     @Override
153
     public void showSnackbar(SnackbarParams params) {
169
     public void showSnackbar(SnackbarParams params) {
154
-        // TODO: implement me
170
+        final String navigatorEventId = stack.peek().getNavigatorEventId();
171
+        snackbarContainer.showSnackbar(navigatorEventId, params);
155
     }
172
     }
156
 
173
 
157
     @Override
174
     @Override

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java View File

92
     public String getScreenInstanceId() {
92
     public String getScreenInstanceId() {
93
         return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.screenInstanceId;
93
         return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.screenInstanceId;
94
     }
94
     }
95
+
96
+    @Override
97
+    public String getNavigatorEventId() {
98
+        return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.navigatorEventId;
99
+    }
95
 }
100
 }