Browse Source

Pass react instance manager to External Component

Guy Carmeli 6 years ago
parent
commit
36df96990d

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

@@ -117,6 +117,7 @@ public class LayoutFactory {
117 117
                 node.id,
118 118
                 externalComponent,
119 119
                 externalComponentCreators.get(externalComponent.name.get()),
120
+                reactInstanceManager,
120 121
                 getOptions(node)
121 122
         );
122 123
     }

+ 3
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/externalcomponent/ExternalComponentCreator.java View File

@@ -2,8 +2,10 @@ package com.reactnativenavigation.viewcontrollers.externalcomponent;
2 2
 
3 3
 import android.support.v4.app.FragmentActivity;
4 4
 
5
+import com.facebook.react.ReactInstanceManager;
6
+
5 7
 import org.json.JSONObject;
6 8
 
7 9
 public interface ExternalComponentCreator {
8
-    ExternalComponent create(FragmentActivity activity, JSONObject props);
10
+    ExternalComponent create(FragmentActivity activity, ReactInstanceManager reactInstanceManager, JSONObject props);
9 11
 }

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

@@ -3,6 +3,7 @@ package com.reactnativenavigation.viewcontrollers.externalcomponent;
3 3
 import android.app.Activity;
4 4
 import android.support.v4.app.FragmentActivity;
5 5
 
6
+import com.facebook.react.ReactInstanceManager;
6 7
 import com.reactnativenavigation.parse.ExternalComponent;
7 8
 import com.reactnativenavigation.parse.Options;
8 9
 import com.reactnativenavigation.viewcontrollers.ViewController;
@@ -11,11 +12,13 @@ import com.reactnativenavigation.views.ExternalComponentLayout;
11 12
 public class ExternalComponentViewController extends ViewController<ExternalComponentLayout> {
12 13
     private final ExternalComponent externalComponent;
13 14
     private final ExternalComponentCreator componentCreator;
15
+    private ReactInstanceManager reactInstanceManager;
14 16
 
15
-    public ExternalComponentViewController(Activity activity, String id, ExternalComponent externalComponent, ExternalComponentCreator componentCreator, Options initialOptions) {
17
+    public ExternalComponentViewController(Activity activity, String id, ExternalComponent externalComponent, ExternalComponentCreator componentCreator, ReactInstanceManager reactInstanceManager, Options initialOptions) {
16 18
         super(activity, id, initialOptions);
17 19
         this.externalComponent = externalComponent;
18 20
         this.componentCreator = componentCreator;
21
+        this.reactInstanceManager = reactInstanceManager;
19 22
     }
20 23
 
21 24
     @Override
@@ -26,7 +29,7 @@ public class ExternalComponentViewController extends ViewController<ExternalComp
26 29
     @Override
27 30
     protected ExternalComponentLayout createView() {
28 31
         ExternalComponentLayout content = new ExternalComponentLayout(getActivity());
29
-        content.addView(componentCreator.create(getActivity(), externalComponent.passProps).asView());
32
+        content.addView(componentCreator.create(getActivity(), reactInstanceManager, externalComponent.passProps).asView());
30 33
         return content;
31 34
     }
32 35
 

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

@@ -4,6 +4,7 @@ import android.app.Activity;
4 4
 import android.support.v4.app.FragmentActivity;
5 5
 import android.widget.FrameLayout;
6 6
 
7
+import com.facebook.react.ReactInstanceManager;
7 8
 import com.reactnativenavigation.BaseTest;
8 9
 import com.reactnativenavigation.parse.ExternalComponent;
9 10
 import com.reactnativenavigation.parse.Options;
@@ -14,6 +15,7 @@ import com.reactnativenavigation.views.ExternalComponentLayout;
14 15
 
15 16
 import org.json.JSONObject;
16 17
 import org.junit.Test;
18
+import org.mockito.Mockito;
17 19
 
18 20
 import static org.assertj.core.api.Java6Assertions.assertThat;
19 21
 import static org.mockito.Mockito.spy;
@@ -25,16 +27,19 @@ public class ExternalComponentViewControllerTest extends BaseTest {
25 27
     private FragmentCreatorMock componentCreator;
26 28
     private Activity activity;
27 29
     private ExternalComponent ec;
30
+    private ReactInstanceManager reactInstanceManager;
28 31
 
29 32
     @Override
30 33
     public void beforeEach() {
31 34
         componentCreator = spy(new FragmentCreatorMock());
32 35
         activity = newActivity();
33 36
         ec = createExternalComponent();
37
+        reactInstanceManager = Mockito.mock(ReactInstanceManager.class);
34 38
         uut = spy(new ExternalComponentViewController(activity,
35 39
                 "fragmentId",
36 40
                 ec,
37 41
                 componentCreator,
42
+                reactInstanceManager,
38 43
                 new Options())
39 44
         );
40 45
     }
@@ -55,7 +60,7 @@ public class ExternalComponentViewControllerTest extends BaseTest {
55 60
     @Test
56 61
     public void createView_createsExternalComponent() throws Exception {
57 62
         ExternalComponentLayout view = uut.getView();
58
-        verify(componentCreator, times(1)).create((FragmentActivity) activity, ec.passProps);
63
+        verify(componentCreator, times(1)).create((FragmentActivity) activity, reactInstanceManager, ec.passProps);
59 64
         assertThat(view.getChildCount()).isGreaterThan(0);
60 65
     }
61 66
 }

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/externalcomponent/FragmentCreatorMock.java View File

@@ -6,13 +6,14 @@ import android.app.FragmentTransaction;
6 6
 import android.support.v4.app.FragmentActivity;
7 7
 import android.widget.FrameLayout;
8 8
 
9
+import com.facebook.react.ReactInstanceManager;
9 10
 import com.reactnativenavigation.R;
10 11
 
11 12
 import org.json.JSONObject;
12 13
 
13 14
 public class FragmentCreatorMock implements ExternalComponentCreator {
14 15
     @Override
15
-    public ExternalComponent create(FragmentActivity activity, JSONObject props) {
16
+    public ExternalComponent create(FragmentActivity activity, ReactInstanceManager reactInstanceManager, JSONObject props) {
16 17
         return createContent(activity);
17 18
     }
18 19
 

+ 2
- 1
playground/android/app/src/main/java/com/reactnativenavigation/playground/FragmentCreator.java View File

@@ -2,6 +2,7 @@ package com.reactnativenavigation.playground;
2 2
 
3 3
 import android.support.v4.app.FragmentActivity;
4 4
 
5
+import com.facebook.react.ReactInstanceManager;
5 6
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponent;
6 7
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
7 8
 
@@ -9,7 +10,7 @@ import org.json.JSONObject;
9 10
 
10 11
 public class FragmentCreator implements ExternalComponentCreator {
11 12
     @Override
12
-    public ExternalComponent create(FragmentActivity activity, JSONObject props) {
13
+    public ExternalComponent create(FragmentActivity activity, ReactInstanceManager reactInstanceManager, JSONObject props) {
13 14
         return new FragmentComponent(activity, props);
14 15
     }
15 16
 }