-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathChildController.java
More file actions
104 lines (87 loc) · 3.45 KB
/
ChildController.java
File metadata and controls
104 lines (87 loc) · 3.45 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
package com.reactnativenavigation.viewcontrollers.child;
import android.app.Activity;
import android.content.res.Configuration;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.CallSuper;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import com.reactnativenavigation.options.Options;
import com.reactnativenavigation.viewcontrollers.navigator.Navigator;
import com.reactnativenavigation.viewcontrollers.viewcontroller.NoOpYellowBoxDelegate;
import com.reactnativenavigation.viewcontrollers.viewcontroller.Presenter;
import com.reactnativenavigation.viewcontrollers.viewcontroller.ViewController;
import com.reactnativenavigation.viewcontrollers.viewcontroller.overlay.ViewControllerOverlay;
import com.reactnativenavigation.views.component.Component;
public abstract class ChildController<T extends ViewGroup> extends ViewController<T> {
protected final Presenter presenter;
private final ChildControllersRegistry childRegistry;
public ChildControllersRegistry getChildRegistry() {
return childRegistry;
}
public ChildController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, Options initialOptions) {
super(activity, id, new NoOpYellowBoxDelegate(activity), initialOptions, new ViewControllerOverlay(activity));
this.presenter = presenter;
this.childRegistry = childRegistry;
}
@Override
public T getView() {
if (view == null) {
super.getView();
view.setFitsSystemWindows(true);
ViewCompat.setOnApplyWindowInsetsListener(view, this::onApplyWindowInsets);
}
return view;
}
@Override
@CallSuper
public void setDefaultOptions(Options defaultOptions) {
presenter.setDefaultOptions(defaultOptions);
}
@Override
public void onViewWillAppear() {
super.onViewWillAppear();
childRegistry.onViewAppeared(this);
}
@Override
public void onViewDisappear() {
super.onViewDisappear();
childRegistry.onViewDisappear(this);
}
public void onViewBroughtToFront() {
presenter.onViewBroughtToFront(this, resolveCurrentOptions());
}
@Override
public void applyOptions(Options options) {
super.applyOptions(options);
presenter.applyOptions(this, resolveCurrentOptions());
}
@Override
public void mergeOptions(Options options) {
if (options == Options.EMPTY) return;
if (isViewShown()) presenter.mergeOptions(this, options);
super.mergeOptions(options);
performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
}
@Override
public void destroy() {
if (!isDestroyed() && getView() instanceof Component) {
performOnParentController(parent -> parent.onChildDestroyed(this));
}
super.destroy();
childRegistry.onChildDestroyed(this);
}
public boolean isRoot() {
return getParentController() == null &&
!(this instanceof Navigator) &&
getView().getParent() != null;
}
protected WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat insets) {
return insets;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
presenter.onConfigurationChanged(this, options);
}
}