Bläddra i källkod

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 år sedan
förälder
incheckning
c33ff1291d
No account linked to committer's email address

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

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

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

@@ -7,13 +7,13 @@ import com.facebook.react.ReactInstanceManager;
7 7
 import com.reactnativenavigation.parse.ExternalComponent;
8 8
 import com.reactnativenavigation.parse.Options;
9 9
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
10
+import com.reactnativenavigation.presentation.Presenter;
10 11
 import com.reactnativenavigation.react.events.ComponentType;
11 12
 import com.reactnativenavigation.react.events.EventEmitter;
12 13
 import com.reactnativenavigation.utils.CoordinatorLayoutUtils;
13 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 17
 import com.reactnativenavigation.views.BehaviourDelegate;
18 18
 import com.reactnativenavigation.views.ExternalComponentLayout;
19 19
 
@@ -22,20 +22,20 @@ import androidx.fragment.app.FragmentActivity;
22 22
 
23 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 26
     private final ExternalComponent externalComponent;
27 27
     private final ExternalComponentCreator componentCreator;
28 28
     private ReactInstanceManager reactInstanceManager;
29 29
     private final EventEmitter emitter;
30 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 34
         this.externalComponent = externalComponent;
35 35
         this.componentCreator = componentCreator;
36 36
         this.reactInstanceManager = reactInstanceManager;
37 37
         this.emitter = emitter;
38
-        this.presenter = presenter;
38
+        this.presenter = externalComponentPresenter;
39 39
     }
40 40
 
41 41
     @Override
@@ -53,13 +53,6 @@ public class ExternalComponentViewController extends ViewController<ExternalComp
53 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 56
     @Override
64 57
     public void onViewAppeared() {
65 58
         super.onViewAppeared();

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

@@ -8,6 +8,7 @@ import com.reactnativenavigation.parse.ExternalComponent;
8 8
 import com.reactnativenavigation.parse.Options;
9 9
 import com.reactnativenavigation.parse.params.Text;
10 10
 import com.reactnativenavigation.presentation.ExternalComponentPresenter;
11
+import com.reactnativenavigation.presentation.Presenter;
11 12
 import com.reactnativenavigation.react.events.ComponentType;
12 13
 import com.reactnativenavigation.react.events.EventEmitter;
13 14
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController;
@@ -33,6 +34,7 @@ public class ExternalComponentViewControllerTest extends BaseTest {
33 34
     private ExternalComponent ec;
34 35
     private ReactInstanceManager reactInstanceManager;
35 36
     private EventEmitter emitter;
37
+    private ChildControllersRegistry childRegistry;
36 38
 
37 39
     @Override
38 40
     public void beforeEach() {
@@ -41,8 +43,11 @@ public class ExternalComponentViewControllerTest extends BaseTest {
41 43
         ec = createExternalComponent();
42 44
         reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
43 45
         emitter = Mockito.mock(EventEmitter.class);
46
+        childRegistry = new ChildControllersRegistry();
44 47
         uut = spy(new ExternalComponentViewController(activity,
48
+                childRegistry,
45 49
                 "fragmentId",
50
+                new Presenter(activity, Options.EMPTY),
46 51
                 ec,
47 52
                 componentCreator,
48 53
                 reactInstanceManager,
@@ -77,6 +82,14 @@ public class ExternalComponentViewControllerTest extends BaseTest {
77 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 93
     private ExternalComponent createExternalComponent() {
81 94
         ExternalComponent component = new ExternalComponent();
82 95
         component.name = new Text("fragmentComponent");