Browse Source

ExternalViewController extends ChildController (#5988)

This commit fixes a long lasting tech debt - ExternalViewController now extends ChildController.

Co-authored-by: Yogev Ben David <yogevbd@wix.com>
Guy Carmeli 4 years ago
parent
commit
c33ff1291d
No account linked to committer's email address

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

166
     private ViewController createExternalComponent(LayoutNode node) {
166
     private ViewController createExternalComponent(LayoutNode node) {
167
         final ExternalComponent externalComponent = ExternalComponent.parse(node.data);
167
         final ExternalComponent externalComponent = ExternalComponent.parse(node.data);
168
         return new ExternalComponentViewController(activity,
168
         return new ExternalComponentViewController(activity,
169
+                childRegistry,
169
                 node.id,
170
                 node.id,
171
+                new Presenter(activity, defaultOptions),
170
                 externalComponent,
172
                 externalComponent,
171
                 externalComponentCreators.get(externalComponent.name.get()),
173
                 externalComponentCreators.get(externalComponent.name.get()),
172
                 reactInstanceManager,
174
                 reactInstanceManager,

+ 7
- 14
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/externalcomponent/ExternalComponentViewController.java View File

7
 import com.reactnativenavigation.parse.ExternalComponent;
7
 import com.reactnativenavigation.parse.ExternalComponent;
8
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
9
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
10
+import com.reactnativenavigation.presentation.Presenter;
10
 import com.reactnativenavigation.react.events.ComponentType;
11
 import com.reactnativenavigation.react.events.ComponentType;
11
 import com.reactnativenavigation.react.events.EventEmitter;
12
 import com.reactnativenavigation.react.events.EventEmitter;
12
 import com.reactnativenavigation.utils.CoordinatorLayoutUtils;
13
 import com.reactnativenavigation.utils.CoordinatorLayoutUtils;
13
 import com.reactnativenavigation.utils.StatusBarUtils;
14
 import com.reactnativenavigation.utils.StatusBarUtils;
14
-import com.reactnativenavigation.viewcontrollers.NoOpYellowBoxDelegate;
15
-import com.reactnativenavigation.viewcontrollers.ViewController;
16
-import com.reactnativenavigation.viewcontrollers.viewcontrolleroverlay.ViewControllerOverlay;
15
+import com.reactnativenavigation.viewcontrollers.ChildController;
16
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
17
 import com.reactnativenavigation.views.BehaviourDelegate;
17
 import com.reactnativenavigation.views.BehaviourDelegate;
18
 import com.reactnativenavigation.views.ExternalComponentLayout;
18
 import com.reactnativenavigation.views.ExternalComponentLayout;
19
 
19
 
22
 
22
 
23
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
23
 import static com.reactnativenavigation.utils.ObjectUtils.perform;
24
 
24
 
25
-public class ExternalComponentViewController extends ViewController<ExternalComponentLayout> {
25
+public class ExternalComponentViewController extends ChildController<ExternalComponentLayout> {
26
     private final ExternalComponent externalComponent;
26
     private final ExternalComponent externalComponent;
27
     private final ExternalComponentCreator componentCreator;
27
     private final ExternalComponentCreator componentCreator;
28
     private ReactInstanceManager reactInstanceManager;
28
     private ReactInstanceManager reactInstanceManager;
29
     private final EventEmitter emitter;
29
     private final EventEmitter emitter;
30
     private final ExternalComponentPresenter presenter;
30
     private final ExternalComponentPresenter presenter;
31
 
31
 
32
-    public ExternalComponentViewController(Activity activity, String id, ExternalComponent externalComponent, ExternalComponentCreator componentCreator, ReactInstanceManager reactInstanceManager, EventEmitter emitter, ExternalComponentPresenter presenter, Options initialOptions) {
33
-        super(activity, id, new NoOpYellowBoxDelegate(), initialOptions, new ViewControllerOverlay(activity));
32
+    public ExternalComponentViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Presenter presenter, ExternalComponent externalComponent, ExternalComponentCreator componentCreator, ReactInstanceManager reactInstanceManager, EventEmitter emitter, ExternalComponentPresenter externalComponentPresenter, Options initialOptions) {
33
+        super(activity, childRegistry, id, presenter, initialOptions);
34
         this.externalComponent = externalComponent;
34
         this.externalComponent = externalComponent;
35
         this.componentCreator = componentCreator;
35
         this.componentCreator = componentCreator;
36
         this.reactInstanceManager = reactInstanceManager;
36
         this.reactInstanceManager = reactInstanceManager;
37
         this.emitter = emitter;
37
         this.emitter = emitter;
38
-        this.presenter = presenter;
38
+        this.presenter = externalComponentPresenter;
39
     }
39
     }
40
 
40
 
41
     @Override
41
     @Override
53
         emitter.emitOnNavigationButtonPressed(getId(), buttonId);
53
         emitter.emitOnNavigationButtonPressed(getId(), buttonId);
54
     }
54
     }
55
 
55
 
56
-    @Override
57
-    public void mergeOptions(Options options) {
58
-        if (options == Options.EMPTY) return;
59
-        performOnParentController(parentController -> parentController.mergeChildOptions(options, this));
60
-        super.mergeOptions(options);
61
-    }
62
-
63
     @Override
56
     @Override
64
     public void onViewAppeared() {
57
     public void onViewAppeared() {
65
         super.onViewAppeared();
58
         super.onViewAppeared();

+ 13
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ExternalComponentViewControllerTest.java View File

8
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.parse.params.Text;
9
 import com.reactnativenavigation.parse.params.Text;
10
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
10
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
11
+import com.reactnativenavigation.presentation.Presenter;
11
 import com.reactnativenavigation.react.events.ComponentType;
12
 import com.reactnativenavigation.react.events.ComponentType;
12
 import com.reactnativenavigation.react.events.EventEmitter;
13
 import com.reactnativenavigation.react.events.EventEmitter;
13
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController;
14
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController;
33
     private ExternalComponent ec;
34
     private ExternalComponent ec;
34
     private ReactInstanceManager reactInstanceManager;
35
     private ReactInstanceManager reactInstanceManager;
35
     private EventEmitter emitter;
36
     private EventEmitter emitter;
37
+    private ChildControllersRegistry childRegistry;
36
 
38
 
37
     @Override
39
     @Override
38
     public void beforeEach() {
40
     public void beforeEach() {
41
         ec = createExternalComponent();
43
         ec = createExternalComponent();
42
         reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
44
         reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
43
         emitter = Mockito.mock(EventEmitter.class);
45
         emitter = Mockito.mock(EventEmitter.class);
46
+        childRegistry = new ChildControllersRegistry();
44
         uut = spy(new ExternalComponentViewController(activity,
47
         uut = spy(new ExternalComponentViewController(activity,
48
+                childRegistry,
45
                 "fragmentId",
49
                 "fragmentId",
50
+                new Presenter(activity, Options.EMPTY),
46
                 ec,
51
                 ec,
47
                 componentCreator,
52
                 componentCreator,
48
                 reactInstanceManager,
53
                 reactInstanceManager,
77
         verify(emitter).emitComponentDidDisappear(uut.getId(), ec.name.get(), ComponentType.Component);
82
         verify(emitter).emitComponentDidDisappear(uut.getId(), ec.name.get(), ComponentType.Component);
78
     }
83
     }
79
 
84
 
85
+    @Test
86
+    public void registersInChildRegister() {
87
+        uut.onViewAppeared();
88
+        assertThat(childRegistry.size()).isOne();
89
+        uut.onViewDisappear();
90
+        assertThat(childRegistry.size()).isZero();
91
+    }
92
+
80
     private ExternalComponent createExternalComponent() {
93
     private ExternalComponent createExternalComponent() {
81
         ExternalComponent component = new ExternalComponent();
94
         ExternalComponent component = new ExternalComponent();
82
         component.name = new Text("fragmentComponent");
95
         component.name = new Text("fragmentComponent");