-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathParentController.java
More file actions
216 lines (173 loc) · 6.79 KB
/
ParentController.java
File metadata and controls
216 lines (173 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package com.reactnativenavigation.viewcontrollers.parent;
import android.app.Activity;
import android.content.res.Configuration;
import android.view.View;
import android.view.ViewGroup;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.options.params.Bool;
import com.reactnativenavigation.utils.CollectionUtils;
import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
import com.reactnativenavigation.viewcontrollers.child.ChildController;
import com.reactnativenavigation.viewcontrollers.child.ChildControllersRegistry;
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController;
import com.reactnativenavigation.views.component.Component;
import java.util.Collection;
import androidx.annotation.CallSuper;
import androidx.annotation.CheckResult;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import static com.reactnativenavigation.utils.CollectionUtils.*;
import static com.reactnativenavigation.utils.ObjectUtils.perform;
public abstract class ParentController<T extends ViewGroup> extends ChildController<T> {
public ParentController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, Options initialOptions) {
super(activity, childRegistry, id, presenter, initialOptions);
}
@Override
public void setWaitForRender(Bool waitForRender) {
super.setWaitForRender(waitForRender);
applyOnController(getCurrentChild(), currentChild -> currentChild.setWaitForRender(waitForRender));
}
@Override
public void setDefaultOptions(Options defaultOptions) {
super.setDefaultOptions(defaultOptions);
forEach(getChildControllers(), child -> child.setDefaultOptions(defaultOptions));
}
@Override
public void onViewDidAppear() {
super.onViewDidAppear();
ViewController<?> currentChild = getCurrentChild();
if (currentChild != null) currentChild.onViewDidAppear();
}
@Override
public void onViewDisappear() {
super.onViewDisappear();
ViewController<?> currentChild = getCurrentChild();
if (currentChild != null) currentChild.onViewDisappear();
}
@Override
@CheckResult
public Options resolveCurrentOptions() {
if (CollectionUtils.isNullOrEmpty(getChildControllers())) return initialOptions;
return getCurrentChild()
.resolveCurrentOptions()
.copy()
.withDefaultOptions(initialOptions);
}
public Options resolveChildOptions(ViewController<?> child) {
if (child == this) return resolveCurrentOptions();
return child
.resolveCurrentOptions()
.copy()
.withDefaultOptions(initialOptions);
}
@Override
@CheckResult
public Options resolveCurrentOptions(Options defaultOptions) {
return resolveCurrentOptions().withDefaultOptions(defaultOptions);
}
public boolean isCurrentChild(ViewController<?> child) {
return getCurrentChild() == child;
}
public abstract ViewController<?> getCurrentChild();
@NonNull
@Override
public abstract T createView();
@NonNull
public abstract Collection<? extends ViewController<?>> getChildControllers();
@Nullable
protected BottomTabsController getBottomTabsController() {
if (this instanceof BottomTabsController) {
return (BottomTabsController) this;
}
return perform(getParentController(), null, ParentController::getBottomTabsController);
}
@Nullable
@Override
public ViewController<?> findController(final String id) {
ViewController<?> fromSuper = super.findController(id);
if (fromSuper != null) return fromSuper;
for (ViewController<?> child : getChildControllers()) {
ViewController<?> fromChild = child.findController(id);
if (fromChild != null) return fromChild;
}
return null;
}
@Nullable
@Override
public ViewController<?> findController(View child) {
ViewController<?> fromSuper = super.findController(child);
if (fromSuper != null) return fromSuper;
for (ViewController<?> childController : getChildControllers()) {
ViewController<?> fromChild = childController.findController(child);
if (fromChild != null) return fromChild;
}
return null;
}
@Override
public boolean containsComponent(Component component) {
if (super.containsComponent(component)) {
return true;
}
for (ViewController<?> child : getChildControllers()) {
if (child.containsComponent(component)) return true;
}
return false;
}
@CallSuper
public void applyChildOptions(Options options, ViewController<?> child) {
this.options = initialOptions.mergeWith(options);
}
@CallSuper
public void mergeChildOptions(Options options, ViewController<?> child) {
}
@Override
public void destroy() {
super.destroy();
forEach(getChildControllers(), ViewController::destroy);
}
@SuppressWarnings("WeakerAccess")
@CallSuper
public void clearOptions() {
performOnParentController(ParentController::clearOptions);
options = initialOptions.copy().clearOneTimeOptions();
}
public void setupTopTabsWithViewPager(ViewPager viewPager) {
}
public void clearTopTabs() {
}
@Override
public boolean isRendered() {
return getCurrentChild() != null && getCurrentChild().isRendered();
}
public void onChildDestroyed(ViewController<?> child) {
}
@Override
public void applyTopInset() {
forEach(getChildControllers(), ViewController::applyTopInset);
}
public int getTopInset(ViewController<?> child) {
return perform(getParentController(), 0, p -> p.getTopInset(child));
}
@Override
public void applyBottomInset() {
forEach(getChildControllers(), ViewController::applyBottomInset);
}
public int getBottomInset(ViewController<?> child) {
return perform(getParentController(), 0, p -> p.getBottomInset(child));
}
@Override
public String getCurrentComponentName() {
return getCurrentChild().getCurrentComponentName();
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Collection<? extends ViewController<?>> childControllers = getChildControllers();
for(ViewController<?> controller: childControllers){
if (controller.isViewShown()) {
controller.onConfigurationChanged(newConfig);
}
}
}
}