|
@@ -1,4 +1,4 @@
|
1
|
|
-package com.reactnativenavigation.viewcontrollers;
|
|
1
|
+package com.reactnativenavigation.viewcontrollers.sidemenu;
|
2
|
2
|
|
3
|
3
|
import android.app.Activity;
|
4
|
4
|
import android.content.res.Resources;
|
|
@@ -13,6 +13,10 @@ import com.reactnativenavigation.parse.Options;
|
13
|
13
|
import com.reactnativenavigation.parse.SideMenuOptions;
|
14
|
14
|
import com.reactnativenavigation.presentation.OptionsPresenter;
|
15
|
15
|
import com.reactnativenavigation.presentation.SideMenuOptionsPresenter;
|
|
16
|
+import com.reactnativenavigation.utils.CommandListener;
|
|
17
|
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
|
|
18
|
+import com.reactnativenavigation.viewcontrollers.ParentController;
|
|
19
|
+import com.reactnativenavigation.viewcontrollers.ViewController;
|
16
|
20
|
import com.reactnativenavigation.views.Component;
|
17
|
21
|
|
18
|
22
|
import java.util.ArrayList;
|
|
@@ -25,10 +29,12 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
25
|
29
|
private ViewController centerController;
|
26
|
30
|
private ViewController leftController;
|
27
|
31
|
private ViewController rightController;
|
|
32
|
+ private SideMenuOptionsPresenter presenter;
|
28
|
33
|
|
29
|
|
- public SideMenuController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions, OptionsPresenter presenter) {
|
|
34
|
+ public SideMenuController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions, SideMenuOptionsPresenter sideMenuOptionsPresenter, OptionsPresenter presenter) {
|
30
|
35
|
super(activity, childRegistry, id, presenter, initialOptions);
|
31
|
|
- }
|
|
36
|
+ this.presenter = sideMenuOptionsPresenter;
|
|
37
|
+ }
|
32
|
38
|
|
33
|
39
|
@Override
|
34
|
40
|
protected ViewController getCurrentChild() {
|
|
@@ -43,7 +49,9 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
43
|
49
|
@NonNull
|
44
|
50
|
@Override
|
45
|
51
|
protected DrawerLayout createView() {
|
46
|
|
- return new DrawerLayout(getActivity());
|
|
52
|
+ DrawerLayout sideMenu = new DrawerLayout(getActivity());
|
|
53
|
+ presenter.bindView(sideMenu);
|
|
54
|
+ return sideMenu;
|
47
|
55
|
}
|
48
|
56
|
|
49
|
57
|
@Override
|
|
@@ -72,7 +80,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
72
|
80
|
@Override
|
73
|
81
|
public void mergeChildOptions(Options options, ViewController childController, Component child) {
|
74
|
82
|
super.mergeChildOptions(options, childController, child);
|
75
|
|
- new SideMenuOptionsPresenter(getView()).present(options.sideMenuRootOptions);
|
|
83
|
+ presenter.present(options.sideMenuRootOptions);
|
76
|
84
|
performOnParentController(parentController ->
|
77
|
85
|
((ParentController) parentController).mergeChildOptions(options.copy().clearSideMenuOptions(), childController, child)
|
78
|
86
|
);
|
|
@@ -81,7 +89,12 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
81
|
89
|
@Override
|
82
|
90
|
public void mergeOptions(Options options) {
|
83
|
91
|
super.mergeOptions(options);
|
84
|
|
- new SideMenuOptionsPresenter(getView()).present(this.options.sideMenuRootOptions);
|
|
92
|
+ presenter.present(this.options.sideMenuRootOptions);
|
|
93
|
+ }
|
|
94
|
+
|
|
95
|
+ @Override
|
|
96
|
+ public boolean handleBack(CommandListener listener) {
|
|
97
|
+ return presenter.handleBack() || super.handleBack(listener);
|
85
|
98
|
}
|
86
|
99
|
|
87
|
100
|
public void setCenterController(ViewController centerController) {
|
|
@@ -104,7 +117,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
104
|
117
|
getView().addView(controller.getView(), new LayoutParams(width, height, Gravity.RIGHT));
|
105
|
118
|
}
|
106
|
119
|
|
107
|
|
- protected int getWidth(SideMenuOptions sideMenuOptions) {
|
|
120
|
+ private int getWidth(SideMenuOptions sideMenuOptions) {
|
108
|
121
|
int width = MATCH_PARENT;
|
109
|
122
|
if (sideMenuOptions.width.hasValue()) {
|
110
|
123
|
width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sideMenuOptions.width.get(), Resources.getSystem().getDisplayMetrics());
|
|
@@ -112,7 +125,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
|
112
|
125
|
return width;
|
113
|
126
|
}
|
114
|
127
|
|
115
|
|
- protected int getHeight(SideMenuOptions sideMenuOptions) {
|
|
128
|
+ private int getHeight(SideMenuOptions sideMenuOptions) {
|
116
|
129
|
int height = MATCH_PARENT;
|
117
|
130
|
if (sideMenuOptions.height.hasValue()) {
|
118
|
131
|
height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sideMenuOptions.height.get(), Resources.getSystem().getDisplayMetrics());
|