Browse Source

Fix custom title component not getting props

The wrong componentId was used to the Title's native react view, Since RNN
uses componentId to assign props to components, the component didn't get it's props.
Guy Carmeli 6 years ago
parent
commit
c7cb591c3f

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

33
 
33
 
34
     @Override
34
     @Override
35
     protected TitleBarReactView createView() {
35
     protected TitleBarReactView createView() {
36
-        return reactViewCreator.create(getActivity(), getId(), component.name.get());
36
+        return reactViewCreator.create(getActivity(), component.componentId.get(), component.name.get());
37
     }
37
     }
38
 
38
 
39
     @Override
39
     @Override

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

1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import android.app.Activity;
4
+
5
+import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
7
+import com.reactnativenavigation.parse.Component;
8
+import com.reactnativenavigation.parse.params.Text;
9
+
10
+import org.junit.Test;
11
+
12
+import static org.mockito.Mockito.spy;
13
+import static org.mockito.Mockito.verify;
14
+
15
+public class TitleBarReactViewControllerTest extends BaseTest {
16
+
17
+    private TitleBarReactViewController uut;
18
+    private TitleBarReactViewCreatorMock viewCreator;
19
+    private Activity activity;
20
+    private Component component;
21
+
22
+    @Override
23
+    public void beforeEach() {
24
+        viewCreator = spy(new TitleBarReactViewCreatorMock());
25
+        activity = newActivity();
26
+        uut = new TitleBarReactViewController(activity, viewCreator);
27
+        createComponent();
28
+        uut.setComponent(component);
29
+    }
30
+
31
+    @Test
32
+    public void createView() {
33
+        uut.createView();
34
+        verify(viewCreator).create(activity, component.componentId.get(), component.name.get());
35
+    }
36
+
37
+    private void createComponent() {
38
+        component = new Component();
39
+        component.componentId = new Text("compId");
40
+        component.name = new Text("compName");
41
+    }
42
+}

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

154
         Component component = new Component();
154
         Component component = new Component();
155
         component.name = new Text(name);
155
         component.name = new Text(name);
156
         component.alignment = alignment;
156
         component.alignment = alignment;
157
+        component.componentId = new Text("compId");
157
         return component;
158
         return component;
158
     }
159
     }
159
 
160