Browse Source

Implement statusBarBackgroundColor

* Set default statusBarBackgroundColor to Black
* Component and Parent controllers now extend ChildController
* Implement return to front logic for ChildControllers
* Apply statusBar color when view appears and returns to front
Guy Carmeli 6 years ago
parent
commit
46f9b65617
34 changed files with 341 additions and 96 deletions
  1. 5
    4
      docs/docs/styling.md
  2. 2
    1
      lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java
  3. 10
    5
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  4. 1
    2
      lib/android/app/src/main/java/com/reactnativenavigation/parse/StatusBarOptions.java
  5. 13
    0
      lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java
  6. 1
    0
      lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java
  7. 44
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildController.java
  8. 28
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildControllersRegistry.java
  9. 3
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java
  10. 10
    10
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java
  11. 3
    3
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java
  12. 2
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/SideMenuController.java
  13. 2
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  14. 7
    1
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackControllerBuilder.java
  15. 3
    4
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java
  16. 3
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java
  17. 6
    3
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java
  18. 2
    2
      lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleComponentViewController.java
  19. 5
    4
      lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java
  20. 9
    7
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  21. 1
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java
  22. 5
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  23. 13
    10
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  24. 1
    0
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  25. 11
    9
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  26. 5
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/SideMenuControllerTest.java
  27. 7
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  28. 6
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  29. 4
    2
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java
  30. 39
    0
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java
  31. 47
    0
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllersRegistryTest.java
  32. 19
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java
  33. 7
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java
  34. 17
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/overlay/OverlayManagerTest.java

+ 5
- 4
docs/docs/styling.md View File

56
 
56
 
57
 ```js
57
 ```js
58
 {
58
 {
59
-  statusBarHidden: false,
59
+  statusBarHidden: false, // iOS only
60
+  statusBarBackgroundColor: 'red', // Android only
61
+  statusBarHideWithTopBar: false, // iOS only
62
+  statusBarBlur: true, // iOS only
63
+  statusBarStyle: 'light', // iOS only
60
   screenBackgroundColor: 'white',
64
   screenBackgroundColor: 'white',
61
   orientation: ['portrait', 'landscape'],
65
   orientation: ['portrait', 'landscape'],
62
-  statusBarBlur: true,
63
-  statusBarHideWithTopBar: false,
64
-  statusBarStyle: 'light',
65
   popGesture: true,
66
   popGesture: true,
66
   backgroundImage: require('background.png'),
67
   backgroundImage: require('background.png'),
67
   rootBackgroundImage: require('rootBackground.png'),
68
   rootBackgroundImage: require('rootBackground.png'),

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java View File

10
 import com.reactnativenavigation.presentation.OverlayManager;
10
 import com.reactnativenavigation.presentation.OverlayManager;
11
 import com.reactnativenavigation.react.ReactGateway;
11
 import com.reactnativenavigation.react.ReactGateway;
12
 import com.reactnativenavigation.utils.CommandListenerAdapter;
12
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
13
 import com.reactnativenavigation.viewcontrollers.Navigator;
14
 import com.reactnativenavigation.viewcontrollers.Navigator;
14
 
15
 
15
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
16
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
18
     @Override
19
     @Override
19
     protected void onCreate(@Nullable Bundle savedInstanceState) {
20
     protected void onCreate(@Nullable Bundle savedInstanceState) {
20
         super.onCreate(savedInstanceState);
21
         super.onCreate(savedInstanceState);
21
-        navigator = new Navigator(this, new OverlayManager());
22
+        navigator = new Navigator(this, new ChildControllersRegistry(), new OverlayManager());
22
         getReactGateway().onActivityCreated(this);
23
         getReactGateway().onActivityCreated(this);
23
         getReactGateway().addReloadListener(navigator);
24
         getReactGateway().addReloadListener(navigator);
24
         setContentView(navigator.getView());
25
         setContentView(navigator.getView());

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

7
 import com.reactnativenavigation.utils.CommandListenerAdapter;
7
 import com.reactnativenavigation.utils.CommandListenerAdapter;
8
 import com.reactnativenavigation.utils.ImageLoader;
8
 import com.reactnativenavigation.utils.ImageLoader;
9
 import com.reactnativenavigation.utils.TypefaceLoader;
9
 import com.reactnativenavigation.utils.TypefaceLoader;
10
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
10
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
11
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
11
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
12
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
12
 import com.reactnativenavigation.viewcontrollers.StackController;
13
 import com.reactnativenavigation.viewcontrollers.StackController;
31
 public class LayoutFactory {
32
 public class LayoutFactory {
32
 
33
 
33
 	private final Activity activity;
34
 	private final Activity activity;
35
+    private final ChildControllersRegistry childRegistry;
34
 	private final ReactInstanceManager reactInstanceManager;
36
 	private final ReactInstanceManager reactInstanceManager;
35
     private EventEmitter eventEmitter;
37
     private EventEmitter eventEmitter;
36
     private Map<String, ExternalComponentCreator> externalComponentCreators;
38
     private Map<String, ExternalComponentCreator> externalComponentCreators;
37
     private Options defaultOptions;
39
     private Options defaultOptions;
38
     private final TypefaceLoader typefaceManager;
40
     private final TypefaceLoader typefaceManager;
39
 
41
 
40
-    public LayoutFactory(Activity activity, final ReactInstanceManager reactInstanceManager, EventEmitter eventEmitter, Map<String, ExternalComponentCreator> externalComponentCreators, Options defaultOptions) {
42
+    public LayoutFactory(Activity activity, ChildControllersRegistry childRegistry, final ReactInstanceManager reactInstanceManager, EventEmitter eventEmitter, Map<String, ExternalComponentCreator> externalComponentCreators, Options defaultOptions) {
41
 		this.activity = activity;
43
 		this.activity = activity;
42
-		this.reactInstanceManager = reactInstanceManager;
44
+        this.childRegistry = childRegistry;
45
+        this.reactInstanceManager = reactInstanceManager;
43
         this.eventEmitter = eventEmitter;
46
         this.eventEmitter = eventEmitter;
44
         this.externalComponentCreators = externalComponentCreators;
47
         this.externalComponentCreators = externalComponentCreators;
45
         this.defaultOptions = defaultOptions;
48
         this.defaultOptions = defaultOptions;
72
 	}
75
 	}
73
 
76
 
74
     private ViewController createSideMenuRoot(LayoutNode node) {
77
     private ViewController createSideMenuRoot(LayoutNode node) {
75
-        SideMenuController sideMenuController = new SideMenuController(activity, node.id, parseNodeOptions(node));
78
+        SideMenuController sideMenuController = new SideMenuController(activity, childRegistry, node.id, parseNodeOptions(node));
76
 		for (LayoutNode child : node.children) {
79
 		for (LayoutNode child : node.children) {
77
 			ViewController childController = create(child);
80
 			ViewController childController = create(child);
78
             childController.setParentController(sideMenuController);
81
             childController.setParentController(sideMenuController);
109
 		String id = node.id;
112
 		String id = node.id;
110
 		String name = node.data.optString("name");
113
 		String name = node.data.optString("name");
111
         return new ComponentViewController(activity,
114
         return new ComponentViewController(activity,
115
+                childRegistry,
112
                 id,
116
                 id,
113
                 name,
117
                 name,
114
                 new ComponentViewCreator(reactInstanceManager),
118
                 new ComponentViewCreator(reactInstanceManager),
129
 
133
 
130
 	private ViewController createStack(LayoutNode node) {
134
 	private ViewController createStack(LayoutNode node) {
131
         StackController stackController = new StackControllerBuilder(activity)
135
         StackController stackController = new StackControllerBuilder(activity)
136
+                .setChildRegistry(childRegistry)
132
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
137
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
133
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreator(reactInstanceManager))
138
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreator(reactInstanceManager))
134
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)))
139
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)))
147
     }
152
     }
148
 
153
 
149
     private ViewController createBottomTabs(LayoutNode node) {
154
     private ViewController createBottomTabs(LayoutNode node) {
150
-        final BottomTabsController tabsComponent = new BottomTabsController(activity, eventEmitter, new ImageLoader(), node.id, parseNodeOptions(node));
155
+        final BottomTabsController tabsComponent = new BottomTabsController(activity, childRegistry, eventEmitter, new ImageLoader(), node.id, parseNodeOptions(node));
151
 		List<ViewController> tabs = new ArrayList<>();
156
 		List<ViewController> tabs = new ArrayList<>();
152
 		for (int i = 0; i < node.children.size(); i++) {
157
 		for (int i = 0; i < node.children.size(); i++) {
153
             tabs.add(create(node.children.get(i)));
158
             tabs.add(create(node.children.get(i)));
164
             options.setTopTabIndex(i);
169
             options.setTopTabIndex(i);
165
             tabs.add(tabController);
170
             tabs.add(tabController);
166
         }
171
         }
167
-        return new TopTabsController(activity, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), parseNodeOptions(node));
172
+        return new TopTabsController(activity, childRegistry, node.id, tabs, new TopTabsLayoutCreator(activity, tabs), parseNodeOptions(node));
168
     }
173
     }
169
 
174
 
170
     private Options parseNodeOptions(LayoutNode node) {
175
     private Options parseNodeOptions(LayoutNode node) {

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

1
 package com.reactnativenavigation.parse;
1
 package com.reactnativenavigation.parse;
2
 
2
 
3
 import com.reactnativenavigation.parse.params.Color;
3
 import com.reactnativenavigation.parse.params.Color;
4
-import com.reactnativenavigation.parse.params.NullColor;
5
 import com.reactnativenavigation.parse.parsers.ColorParser;
4
 import com.reactnativenavigation.parse.parsers.ColorParser;
6
 
5
 
7
 import org.json.JSONObject;
6
 import org.json.JSONObject;
16
         return result;
15
         return result;
17
     }
16
     }
18
 
17
 
19
-    public Color backgroundColor = new NullColor();
18
+    public Color backgroundColor = new Color(android.graphics.Color.BLACK);
20
 
19
 
21
     public void mergeWith(StatusBarOptions other) {
20
     public void mergeWith(StatusBarOptions other) {
22
         if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
21
         if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;

+ 13
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/OptionsPresenter.java View File

1
 package com.reactnativenavigation.presentation;
1
 package com.reactnativenavigation.presentation;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
+import android.os.Build;
4
 import android.view.View;
5
 import android.view.View;
5
 
6
 
6
 import com.reactnativenavigation.parse.Options;
7
 import com.reactnativenavigation.parse.Options;
7
 import com.reactnativenavigation.parse.OrientationOptions;
8
 import com.reactnativenavigation.parse.OrientationOptions;
9
+import com.reactnativenavigation.parse.StatusBarOptions;
8
 
10
 
11
+@SuppressWarnings("FieldCanBeLocal")
9
 public class OptionsPresenter {
12
 public class OptionsPresenter {
10
 
13
 
11
     private Activity activity;
14
     private Activity activity;
17
     public void present(View view, Options options) {
20
     public void present(View view, Options options) {
18
         applyOrientation(options.orientationOptions);
21
         applyOrientation(options.orientationOptions);
19
         applyViewOptions(view, options);
22
         applyViewOptions(view, options);
23
+        applyStatusBarOptions(options.statusBar);
20
     }
24
     }
21
 
25
 
22
     private void applyOrientation(OrientationOptions options) {
26
     private void applyOrientation(OrientationOptions options) {
29
         }
33
         }
30
     }
34
     }
31
 
35
 
36
+    public void onViewBroughtToFront(Options options) {
37
+        applyStatusBarOptions(options.statusBar);
38
+    }
39
+
40
+    private void applyStatusBarOptions(StatusBarOptions statusBar) {
41
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
42
+            activity.getWindow().setStatusBarColor(statusBar.backgroundColor.get());
43
+        }
44
+    }
32
 }
45
 }

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

139
 	@NonNull
139
 	@NonNull
140
 	private LayoutFactory newLayoutFactory() {
140
 	private LayoutFactory newLayoutFactory() {
141
 		return new LayoutFactory(activity(),
141
 		return new LayoutFactory(activity(),
142
+                navigator().getChildRegistry(),
142
                 reactInstanceManager,
143
                 reactInstanceManager,
143
                 eventEmitter,
144
                 eventEmitter,
144
                 externalComponentCreator(),
145
                 externalComponentCreator(),

+ 44
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildController.java View File

1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import android.app.Activity;
4
+import android.view.ViewGroup;
5
+
6
+import com.reactnativenavigation.parse.Options;
7
+import com.reactnativenavigation.presentation.OptionsPresenter;
8
+
9
+public abstract class ChildController<T extends ViewGroup> extends ViewController<T>  {
10
+    private final OptionsPresenter presenter;
11
+    private final ChildControllersRegistry childRegistry;
12
+
13
+    public ChildControllersRegistry getChildRegistry() {
14
+        return childRegistry;
15
+    }
16
+
17
+    public ChildController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
18
+        super(activity, id, initialOptions);
19
+        presenter = new OptionsPresenter(activity);
20
+        this.childRegistry = childRegistry;
21
+    }
22
+
23
+    @Override
24
+    public void onViewAppeared() {
25
+        super.onViewAppeared();
26
+        childRegistry.onViewAppeared(this);
27
+    }
28
+
29
+    @Override
30
+    public void onViewDisappear() {
31
+        super.onViewDisappear();
32
+        childRegistry.onViewDisappear(this);
33
+    }
34
+
35
+    public void onViewBroughtToFront() {
36
+        presenter.onViewBroughtToFront(options);
37
+    }
38
+
39
+    @Override
40
+    public void applyOptions(Options options) {
41
+        super.applyOptions(options);
42
+        presenter.present(getView(), options);
43
+    }
44
+}

+ 28
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ChildControllersRegistry.java View File

1
+package com.reactnativenavigation.viewcontrollers;
2
+
3
+import java.util.ArrayDeque;
4
+
5
+public class ChildControllersRegistry {
6
+    private ArrayDeque<ChildController> children = new ArrayDeque<>();
7
+
8
+    public void onViewAppeared(ChildController child) {
9
+        children.push(child);
10
+    }
11
+
12
+    public void onViewDisappear(ChildController child) {
13
+        if (isTopChild(child)) {
14
+            children.pop();
15
+            if (!children.isEmpty()) children.peek().onViewBroughtToFront();
16
+        } else {
17
+            children.remove(child);
18
+        }
19
+    }
20
+
21
+    private boolean isTopChild(ChildController child) {
22
+        return children.peek().equals(child);
23
+    }
24
+
25
+    public int size() {
26
+        return children.size();
27
+    }
28
+}

+ 3
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java View File

7
 import com.reactnativenavigation.views.ComponentLayout;
7
 import com.reactnativenavigation.views.ComponentLayout;
8
 import com.reactnativenavigation.views.ReactComponent;
8
 import com.reactnativenavigation.views.ReactComponent;
9
 
9
 
10
-public class ComponentViewController extends ViewController<ComponentLayout> {
10
+public class ComponentViewController extends ChildController<ComponentLayout> {
11
 
11
 
12
     private final String componentName;
12
     private final String componentName;
13
 
13
 
14
     private final ReactViewCreator viewCreator;
14
     private final ReactViewCreator viewCreator;
15
 
15
 
16
     public ComponentViewController(final Activity activity,
16
     public ComponentViewController(final Activity activity,
17
+                                   final ChildControllersRegistry childRegistry,
17
                                    final String id,
18
                                    final String id,
18
                                    final String componentName,
19
                                    final String componentName,
19
                                    final ReactViewCreator viewCreator,
20
                                    final ReactViewCreator viewCreator,
20
                                    final Options initialOptions) {
21
                                    final Options initialOptions) {
21
-        super(activity, id, initialOptions);
22
+        super(activity, childRegistry, id, initialOptions);
22
         this.componentName = componentName;
23
         this.componentName = componentName;
23
         this.viewCreator = viewCreator;
24
         this.viewCreator = viewCreator;
24
     }
25
     }

+ 10
- 10
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

32
     private final OverlayManager overlayManager;
32
     private final OverlayManager overlayManager;
33
     private Options defaultOptions = new Options();
33
     private Options defaultOptions = new Options();
34
 
34
 
35
-    public Navigator(final Activity activity, OverlayManager overlayManager) {
36
-        super(activity, "navigator" + CompatUtils.generateViewId(), new Options());
35
+    public void setDefaultOptions(Options defaultOptions) {
36
+        this.defaultOptions = defaultOptions;
37
+    }
38
+
39
+    public Options getDefaultOptions() {
40
+        return defaultOptions;
41
+    }
42
+
43
+    public Navigator(final Activity activity, ChildControllersRegistry childRegistry, OverlayManager overlayManager) {
44
+        super(activity, childRegistry,"navigator" + CompatUtils.generateViewId(), new Options());
37
         modalStack = new ModalStack(new ModalPresenter(new ModalAnimator(activity)));
45
         modalStack = new ModalStack(new ModalPresenter(new ModalAnimator(activity)));
38
         this.overlayManager = overlayManager;
46
         this.overlayManager = overlayManager;
39
     }
47
     }
108
         }
116
         }
109
     }
117
     }
110
 
118
 
111
-    public void setDefaultOptions(Options defaultOptions) {
112
-        this.defaultOptions = defaultOptions;
113
-    }
114
-
115
-    public Options getDefaultOptions() {
116
-        return defaultOptions;
117
-    }
118
-
119
     public void mergeOptions(final String componentId, Options options) {
119
     public void mergeOptions(final String componentId, Options options) {
120
         ViewController target = findControllerById(componentId);
120
         ViewController target = findControllerById(componentId);
121
         if (target != null) {
121
         if (target != null) {

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

12
 
12
 
13
 import java.util.Collection;
13
 import java.util.Collection;
14
 
14
 
15
-public abstract class ParentController<T extends ViewGroup> extends ViewController {
15
+public abstract class ParentController<T extends ViewGroup> extends ChildController {
16
 
16
 
17
-	public ParentController(final Activity activity, final String id, Options initialOptions) {
18
-		super(activity, id, initialOptions);
17
+	public ParentController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
18
+		super(activity, childRegistry, id, initialOptions);
19
 	}
19
 	}
20
 
20
 
21
 	@NonNull
21
 	@NonNull

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

22
 	private ViewController leftController;
22
 	private ViewController leftController;
23
 	private ViewController rightController;
23
 	private ViewController rightController;
24
 
24
 
25
-	public SideMenuController(final Activity activity, final String id, Options initialOptions) {
26
-		super(activity, id, initialOptions);
25
+	public SideMenuController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
26
+		super(activity, childRegistry, id, initialOptions);
27
 	}
27
 	}
28
 
28
 
29
 	@NonNull
29
 	@NonNull

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

31
     private TopBarBackgroundViewController topBarBackgroundViewController;
31
     private TopBarBackgroundViewController topBarBackgroundViewController;
32
     private TopBarController topBarController;
32
     private TopBarController topBarController;
33
 
33
 
34
-    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, NavigationAnimator animator, String id, Options initialOptions) {
35
-        super(activity, id, initialOptions);
34
+    public StackController(Activity activity, ChildControllersRegistry childRegistry, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, NavigationAnimator animator, String id, Options initialOptions) {
35
+        super(activity, childRegistry, id, initialOptions);
36
         this.topBarController = topBarController;
36
         this.topBarController = topBarController;
37
         this.topBarButtonCreator = topBarButtonCreator;
37
         this.topBarButtonCreator = topBarButtonCreator;
38
         this.titleBarReactViewCreator = titleBarReactViewCreator;
38
         this.titleBarReactViewCreator = titleBarReactViewCreator;

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

10
 
10
 
11
 public class StackControllerBuilder {
11
 public class StackControllerBuilder {
12
     private Activity activity;
12
     private Activity activity;
13
+    private ChildControllersRegistry childRegistry;
13
     private ReactViewCreator topBarButtonCreator;
14
     private ReactViewCreator topBarButtonCreator;
14
     private TitleBarReactViewCreator titleBarReactViewCreator;
15
     private TitleBarReactViewCreator titleBarReactViewCreator;
15
     private TopBarBackgroundViewController topBarBackgroundViewController;
16
     private TopBarBackgroundViewController topBarBackgroundViewController;
23
         animator = new NavigationAnimator(activity);
24
         animator = new NavigationAnimator(activity);
24
     }
25
     }
25
 
26
 
27
+    public StackControllerBuilder setChildRegistry(ChildControllersRegistry childRegistry) {
28
+        this.childRegistry = childRegistry;
29
+        return this;
30
+    }
31
+
26
     public StackControllerBuilder setTopBarButtonCreator(ReactViewCreator topBarButtonCreator) {
32
     public StackControllerBuilder setTopBarButtonCreator(ReactViewCreator topBarButtonCreator) {
27
         this.topBarButtonCreator = topBarButtonCreator;
33
         this.topBarButtonCreator = topBarButtonCreator;
28
         return this;
34
         return this;
59
     }
65
     }
60
 
66
 
61
     public StackController createStackController() {
67
     public StackController createStackController() {
62
-        return new StackController(activity, topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, animator, id, initialOptions);
68
+        return new StackController(activity, childRegistry, topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, animator, id, initialOptions);
63
     }
69
     }
64
 }
70
 }

+ 3
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java View File

12
 
12
 
13
 import com.reactnativenavigation.parse.Options;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.presentation.FabOptionsPresenter;
14
 import com.reactnativenavigation.presentation.FabOptionsPresenter;
15
-import com.reactnativenavigation.presentation.OptionsPresenter;
16
 import com.reactnativenavigation.utils.CommandListener;
15
 import com.reactnativenavigation.utils.CommandListener;
17
 import com.reactnativenavigation.utils.StringUtils;
16
 import com.reactnativenavigation.utils.StringUtils;
18
 import com.reactnativenavigation.utils.Task;
17
 import com.reactnativenavigation.utils.Task;
43
     private boolean isShown;
42
     private boolean isShown;
44
     private boolean isDestroyed;
43
     private boolean isDestroyed;
45
     private ViewVisibilityListener viewVisibilityListener = new ViewVisibilityListenerAdapter();
44
     private ViewVisibilityListener viewVisibilityListener = new ViewVisibilityListenerAdapter();
46
-    private OptionsPresenter presenter;
47
     FabOptionsPresenter fabOptionsPresenter;
45
     FabOptionsPresenter fabOptionsPresenter;
48
 
46
 
49
     public ViewController(Activity activity, String id, Options initialOptions) {
47
     public ViewController(Activity activity, String id, Options initialOptions) {
50
         this.activity = activity;
48
         this.activity = activity;
51
         this.id = id;
49
         this.id = id;
52
-        presenter = new OptionsPresenter(activity);
53
         fabOptionsPresenter = new FabOptionsPresenter();
50
         fabOptionsPresenter = new FabOptionsPresenter();
54
         this.initialOptions = initialOptions;
51
         this.initialOptions = initialOptions;
55
         options = initialOptions.copy();
52
         options = initialOptions.copy();
79
 
76
 
80
     @CallSuper
77
     @CallSuper
81
     public void applyOptions(Options options) {
78
     public void applyOptions(Options options) {
82
-        presenter.present(getView(), options);
79
+
83
     }
80
     }
84
 
81
 
85
     public Activity getActivity() {
82
     public Activity getActivity() {
157
 
154
 
158
     }
155
     }
159
 
156
 
157
+    @CallSuper
160
     public void onViewAppeared() {
158
     public void onViewAppeared() {
161
         isShown = true;
159
         isShown = true;
162
         applyOptions(options);
160
         applyOptions(options);
170
 
168
 
171
     }
169
     }
172
 
170
 
171
+    @CallSuper
173
     public void onViewDisappear() {
172
     public void onViewDisappear() {
174
         isShown = false;
173
         isShown = false;
175
     }
174
     }

+ 3
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java View File

14
 import com.reactnativenavigation.react.EventEmitter;
14
 import com.reactnativenavigation.react.EventEmitter;
15
 import com.reactnativenavigation.utils.CommandListener;
15
 import com.reactnativenavigation.utils.CommandListener;
16
 import com.reactnativenavigation.utils.ImageLoader;
16
 import com.reactnativenavigation.utils.ImageLoader;
17
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
17
 import com.reactnativenavigation.viewcontrollers.ParentController;
18
 import com.reactnativenavigation.viewcontrollers.ParentController;
18
 import com.reactnativenavigation.viewcontrollers.ViewController;
19
 import com.reactnativenavigation.viewcontrollers.ViewController;
19
 import com.reactnativenavigation.views.BottomTabs;
20
 import com.reactnativenavigation.views.BottomTabs;
36
     private BottomTabsOptionsPresenter presenter;
37
     private BottomTabsOptionsPresenter presenter;
37
     private final BottomTabFinder bottomTabFinder = new BottomTabFinder();
38
     private final BottomTabFinder bottomTabFinder = new BottomTabFinder();
38
 
39
 
39
-    public BottomTabsController(final Activity activity, EventEmitter eventEmitter, ImageLoader imageLoader, final String id, Options initialOptions) {
40
-		super(activity, id, initialOptions);
40
+    public BottomTabsController(Activity activity, ChildControllersRegistry childRegistry, EventEmitter eventEmitter, ImageLoader imageLoader, String id, Options initialOptions) {
41
+		super(activity, childRegistry, id, initialOptions);
41
         this.eventEmitter = eventEmitter;
42
         this.eventEmitter = eventEmitter;
42
         this.imageLoader = imageLoader;
43
         this.imageLoader = imageLoader;
43
     }
44
     }

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java View File

6
 
6
 
7
 import com.reactnativenavigation.parse.Options;
7
 import com.reactnativenavigation.parse.Options;
8
 import com.reactnativenavigation.utils.Task;
8
 import com.reactnativenavigation.utils.Task;
9
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
9
 import com.reactnativenavigation.viewcontrollers.ParentController;
10
 import com.reactnativenavigation.viewcontrollers.ParentController;
10
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 import com.reactnativenavigation.viewcontrollers.ViewController;
11
 import com.reactnativenavigation.viewcontrollers.ViewVisibilityListenerAdapter;
12
 import com.reactnativenavigation.viewcontrollers.ViewVisibilityListenerAdapter;
21
     private List<ViewController> tabs;
22
     private List<ViewController> tabs;
22
     private TopTabsLayoutCreator viewCreator;
23
     private TopTabsLayoutCreator viewCreator;
23
 
24
 
24
-    public TopTabsController(Activity activity, String id, List<ViewController> tabs, TopTabsLayoutCreator viewCreator, Options options) {
25
-        super(activity, id, options);
25
+    public TopTabsController(Activity activity, ChildControllersRegistry childRegistry, String id, List<ViewController> tabs, TopTabsLayoutCreator viewCreator, Options options) {
26
+        super(activity, childRegistry, id, options);
26
         this.viewCreator = viewCreator;
27
         this.viewCreator = viewCreator;
27
         this.tabs = tabs;
28
         this.tabs = tabs;
28
         for (ViewController tab : tabs) {
29
         for (ViewController tab : tabs) {
51
 
52
 
52
     @Override
53
     @Override
53
     public void onViewAppeared() {
54
     public void onViewAppeared() {
54
-        applyOptions(options);
55
+        super.onViewAppeared();
55
         applyOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
56
         applyOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
56
         performOnCurrentTab(ViewController::onViewAppeared);
57
         performOnCurrentTab(ViewController::onViewAppeared);
57
     }
58
     }
63
 
64
 
64
     @Override
65
     @Override
65
     public void onViewDisappear() {
66
     public void onViewDisappear() {
67
+        super.onViewDisappear();
66
         performOnCurrentTab(ViewController::onViewDisappear);
68
         performOnCurrentTab(ViewController::onViewDisappear);
67
         applyOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
69
         applyOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
68
     }
70
     }
74
 
76
 
75
     @Override
77
     @Override
76
     public void applyOptions(Options options) {
78
     public void applyOptions(Options options) {
79
+        super.applyOptions(options);
77
         getView().applyOptions(options);
80
         getView().applyOptions(options);
78
     }
81
     }
79
 
82
 

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleComponentViewController.java View File

6
 import com.reactnativenavigation.viewcontrollers.*;
6
 import com.reactnativenavigation.viewcontrollers.*;
7
 
7
 
8
 public class SimpleComponentViewController extends ComponentViewController {
8
 public class SimpleComponentViewController extends ComponentViewController {
9
-    public SimpleComponentViewController(final Activity activity, final String id, Options initialOptions) {
10
-        super(activity, id, "theComponentName", new TestComponentViewCreator(), initialOptions);
9
+    public SimpleComponentViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
10
+        super(activity, childRegistry,id, "theComponentName", new TestComponentViewCreator(), initialOptions);
11
     }
11
     }
12
 }
12
 }

+ 5
- 4
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java View File

9
 
9
 
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
-import com.reactnativenavigation.viewcontrollers.ViewController;
12
+import com.reactnativenavigation.viewcontrollers.ChildController;
13
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
13
 import com.reactnativenavigation.views.Component;
14
 import com.reactnativenavigation.views.Component;
14
 import com.reactnativenavigation.views.ReactComponent;
15
 import com.reactnativenavigation.views.ReactComponent;
15
 import com.reactnativenavigation.views.topbar.TopBar;
16
 import com.reactnativenavigation.views.topbar.TopBar;
16
 
17
 
17
-public class SimpleViewController extends ViewController<FrameLayout> {
18
+public class SimpleViewController extends ChildController<FrameLayout> {
18
 
19
 
19
     private SimpleView simpleView;
20
     private SimpleView simpleView;
20
 
21
 
21
-    public SimpleViewController(final Activity activity, String id, Options options) {
22
-        super(activity, id, options);
22
+    public SimpleViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options options) {
23
+        super(activity, childRegistry, id, options);
23
     }
24
     }
24
 
25
 
25
     @Override
26
     @Override

+ 9
- 7
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

50
     private Options tabOptions = OptionHelper.createBottomTabOptions();
50
     private Options tabOptions = OptionHelper.createBottomTabOptions();
51
     private ImageLoader imageLoaderMock = ImageLoaderMock.mock();
51
     private ImageLoader imageLoaderMock = ImageLoaderMock.mock();
52
     private EventEmitter eventEmitter;
52
     private EventEmitter eventEmitter;
53
+    private ChildControllersRegistry childRegistry;
53
 
54
 
54
     @Override
55
     @Override
55
     public void beforeEach() {
56
     public void beforeEach() {
56
         activity = newActivity();
57
         activity = newActivity();
58
+        childRegistry = new ChildControllersRegistry();
57
         eventEmitter = Mockito.mock(EventEmitter.class);
59
         eventEmitter = Mockito.mock(EventEmitter.class);
58
-        uut = spy(new BottomTabsController(activity, eventEmitter, imageLoaderMock, "uut", new Options()));
59
-        child1 = spy(new SimpleViewController(activity, "child1", tabOptions));
60
-        child2 = spy(new SimpleViewController(activity, "child2", tabOptions));
61
-        child3 = spy(new SimpleViewController(activity, "child3", tabOptions));
62
-        child4 = spy(new SimpleViewController(activity, "child4", tabOptions));
63
-        child5 = spy(new SimpleViewController(activity, "child5", tabOptions));
60
+        uut = spy(new BottomTabsController(activity, childRegistry, eventEmitter, imageLoaderMock, "uut", new Options()));
61
+        child1 = spy(new SimpleViewController(activity, childRegistry, "child1", tabOptions));
62
+        child2 = spy(new SimpleViewController(activity, childRegistry, "child2", tabOptions));
63
+        child3 = spy(new SimpleViewController(activity, childRegistry, "child3", tabOptions));
64
+        child4 = spy(new SimpleViewController(activity, childRegistry, "child4", tabOptions));
65
+        child5 = spy(new SimpleViewController(activity, childRegistry, "child5", tabOptions));
64
     }
66
     }
65
 
67
 
66
     @Test
68
     @Test
72
     @Test(expected = RuntimeException.class)
74
     @Test(expected = RuntimeException.class)
73
     public void setTabs_ThrowWhenMoreThan5() {
75
     public void setTabs_ThrowWhenMoreThan5() {
74
         List<ViewController> tabs = createTabs();
76
         List<ViewController> tabs = createTabs();
75
-        tabs.add(new SimpleViewController(activity, "6", tabOptions));
77
+        tabs.add(new SimpleViewController(activity, childRegistry, "6", tabOptions));
76
         uut.setTabs(tabs);
78
         uut.setTabs(tabs);
77
     }
79
     }
78
 
80
 

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

38
                 .setId("stack")
38
                 .setId("stack")
39
                 .setInitialOptions(new Options())
39
                 .setInitialOptions(new Options())
40
                 .createStackController();
40
                 .createStackController();
41
-        uut = new ComponentViewController(activity, "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
41
+        uut = new ComponentViewController(activity, new ChildControllersRegistry(), "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
42
         uut.setParentController(parentController);
42
         uut.setParentController(parentController);
43
         parentController.ensureViewIsCreated();
43
         parentController.ensureViewIsCreated();
44
     }
44
     }

+ 5
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java View File

32
     private SimpleViewController childFab;
32
     private SimpleViewController childFab;
33
     private SimpleViewController childNoFab;
33
     private SimpleViewController childNoFab;
34
     private Activity activity;
34
     private Activity activity;
35
+    private ChildControllersRegistry childRegistry;
35
 
36
 
36
     @Override
37
     @Override
37
     public void beforeEach() {
38
     public void beforeEach() {
38
         super.beforeEach();
39
         super.beforeEach();
39
         activity = newActivity();
40
         activity = newActivity();
41
+        childRegistry = new ChildControllersRegistry();
40
         stackController = new StackControllerBuilder(activity)
42
         stackController = new StackControllerBuilder(activity)
41
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
43
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
42
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
44
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
46
                 .setInitialOptions(new Options())
48
                 .setInitialOptions(new Options())
47
                 .createStackController();
49
                 .createStackController();
48
         Options options = getOptionsWithFab();
50
         Options options = getOptionsWithFab();
49
-        childFab = new SimpleViewController(activity, "child1", options);
50
-        childNoFab = new SimpleViewController(activity, "child2", new Options());
51
+        childFab = new SimpleViewController(activity, childRegistry, "child1", options);
52
+        childNoFab = new SimpleViewController(activity, childRegistry, "child2", new Options());
51
     }
53
     }
52
 
54
 
53
     @NonNull
55
     @NonNull
129
 
131
 
130
     @Test
132
     @Test
131
     public void hasChildren() {
133
     public void hasChildren() {
132
-        childFab = new SimpleViewController(activity, "child1", getOptionsWithFabActions());
134
+        childFab = new SimpleViewController(activity, childRegistry, "child1", getOptionsWithFabActions());
133
         stackController.push(childFab, new CommandListenerAdapter());
135
         stackController.push(childFab, new CommandListenerAdapter());
134
         childFab.onViewAppeared();
136
         childFab.onViewAppeared();
135
         assertThat(hasFab()).isTrue();
137
         assertThat(hasFab()).isTrue();

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

39
 
39
 
40
 public class NavigatorTest extends BaseTest {
40
 public class NavigatorTest extends BaseTest {
41
     private TestActivity activity;
41
     private TestActivity activity;
42
+    private ChildControllersRegistry childRegistry;
42
     private Navigator uut;
43
     private Navigator uut;
43
     private StackController parentController;
44
     private StackController parentController;
44
     private SimpleViewController child1;
45
     private SimpleViewController child1;
54
 
55
 
55
     @Override
56
     @Override
56
     public void beforeEach() {
57
     public void beforeEach() {
58
+        childRegistry = new ChildControllersRegistry();
57
         eventEmitter = Mockito.mock(EventEmitter.class);
59
         eventEmitter = Mockito.mock(EventEmitter.class);
58
         overlayManager = Mockito.mock(OverlayManager.class);
60
         overlayManager = Mockito.mock(OverlayManager.class);
59
         imageLoaderMock = ImageLoaderMock.mock();
61
         imageLoaderMock = ImageLoaderMock.mock();
60
         activityController = newActivityController(TestActivity.class);
62
         activityController = newActivityController(TestActivity.class);
61
         activity = activityController.create().get();
63
         activity = activityController.create().get();
62
-        uut = new Navigator(activity, overlayManager);
64
+        uut = new Navigator(activity, childRegistry, overlayManager);
63
         activity.setNavigator(uut);
65
         activity.setNavigator(uut);
64
 
66
 
65
         parentController = spy(newStack());
67
         parentController = spy(newStack());
66
         parentController.ensureViewIsCreated();
68
         parentController.ensureViewIsCreated();
67
-        child1 = new SimpleViewController(activity, "child1", tabOptions);
68
-        child2 = new SimpleViewController(activity, "child2", tabOptions);
69
-        child3 = new SimpleViewController(activity, "child3", tabOptions);
70
-        child4 = new SimpleViewController(activity, "child4", tabOptions);
71
-        child5 = new SimpleViewController(activity, "child5", tabOptions);
69
+        child1 = new SimpleViewController(activity, childRegistry, "child1", tabOptions);
70
+        child2 = new SimpleViewController(activity, childRegistry, "child2", tabOptions);
71
+        child3 = new SimpleViewController(activity, childRegistry, "child3", tabOptions);
72
+        child4 = new SimpleViewController(activity, childRegistry, "child4", tabOptions);
73
+        child5 = new SimpleViewController(activity, childRegistry, "child5", tabOptions);
72
         activity.setContentView(uut.getView());
74
         activity.setContentView(uut.getView());
73
 
75
 
74
         activityController.visible();
76
         activityController.visible();
91
     @Test
93
     @Test
92
     public void hasUniqueId() {
94
     public void hasUniqueId() {
93
         assertThat(uut.getId()).startsWith("navigator");
95
         assertThat(uut.getId()).startsWith("navigator");
94
-        assertThat(new Navigator(activity, overlayManager).getId()).isNotEqualTo(uut.getId());
96
+        assertThat(new Navigator(activity, childRegistry, overlayManager).getId()).isNotEqualTo(uut.getId());
95
     }
97
     }
96
 
98
 
97
     @Test
99
     @Test
126
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
128
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
127
         uut.setRoot(bottomTabsController, new CommandListenerAdapter());
129
         uut.setRoot(bottomTabsController, new CommandListenerAdapter());
128
 
130
 
129
-        SimpleViewController newChild = new SimpleViewController(activity, "new child", tabOptions);
131
+        SimpleViewController newChild = new SimpleViewController(activity, childRegistry, "new child", tabOptions);
130
         uut.push(child2.getId(), newChild, new CommandListenerAdapter());
132
         uut.push(child2.getId(), newChild, new CommandListenerAdapter());
131
 
133
 
132
         assertThat(stack1.getChildControllers()).doesNotContain(newChild);
134
         assertThat(stack1.getChildControllers()).doesNotContain(newChild);
257
 
259
 
258
     @Test
260
     @Test
259
     public void mergeOptions_CallsApplyNavigationOptions() {
261
     public void mergeOptions_CallsApplyNavigationOptions() {
260
-        ComponentViewController componentVc = new SimpleComponentViewController(activity, "theId", new Options());
262
+        ComponentViewController componentVc = new SimpleComponentViewController(activity, childRegistry, "theId", new Options());
261
         componentVc.setParentController(parentController);
263
         componentVc.setParentController(parentController);
262
         assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
264
         assertThat(componentVc.options.topBar.title.text.get("")).isEmpty();
263
         uut.setRoot(componentVc, new CommandListenerAdapter());
265
         uut.setRoot(componentVc, new CommandListenerAdapter());
276
 
278
 
277
     @NonNull
279
     @NonNull
278
     private BottomTabsController newTabs() {
280
     private BottomTabsController newTabs() {
279
-        return new BottomTabsController(activity, eventEmitter, imageLoaderMock, "tabsController", new Options());
281
+        return new BottomTabsController(activity, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options());
280
     }
282
     }
281
 
283
 
282
     @NonNull
284
     @NonNull
283
     private StackController newStack() {
285
     private StackController newStack() {
284
         return new StackControllerBuilder(activity)
286
         return new StackControllerBuilder(activity)
287
+                .setChildRegistry(childRegistry)
285
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
288
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
286
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
289
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
287
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
290
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))

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

48
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
48
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
49
         view.asView().setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
49
         view.asView().setLayoutParams(new RelativeLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
50
         uut = new ComponentViewController(activity,
50
         uut = new ComponentViewController(activity,
51
+                new ChildControllersRegistry(),
51
                 "componentId1",
52
                 "componentId1",
52
                 "componentName",
53
                 "componentName",
53
                 (activity1, componentId, componentName) -> view,
54
                 (activity1, componentId, componentName) -> view,

+ 11
- 9
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java View File

33
 
33
 
34
     private static final String INITIAL_TITLE = "initial title";
34
     private static final String INITIAL_TITLE = "initial title";
35
     private Activity activity;
35
     private Activity activity;
36
+    private ChildControllersRegistry childRegistry;
36
     private List<ViewController> children;
37
     private List<ViewController> children;
37
     private ParentController uut;
38
     private ParentController uut;
38
 
39
 
40
     public void beforeEach() {
41
     public void beforeEach() {
41
         super.beforeEach();
42
         super.beforeEach();
42
         activity = newActivity();
43
         activity = newActivity();
44
+        childRegistry = new ChildControllersRegistry();
43
         children = new ArrayList<>();
45
         children = new ArrayList<>();
44
         Options initialOptions = new Options();
46
         Options initialOptions = new Options();
45
         initialOptions.topBar.title.text = new Text(INITIAL_TITLE);
47
         initialOptions.topBar.title.text = new Text(INITIAL_TITLE);
46
-        uut = spy(new ParentController(activity, "uut", initialOptions) {
48
+        uut = spy(new ParentController(activity, childRegistry, "uut", initialOptions) {
47
 
49
 
48
             @NonNull
50
             @NonNull
49
             @Override
51
             @Override
81
 
83
 
82
     @Test
84
     @Test
83
     public void findControllerById_ChildById() {
85
     public void findControllerById_ChildById() {
84
-        SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
85
-        SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
86
+        SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
87
+        SimpleViewController child2 = new SimpleViewController(activity, childRegistry, "child2", new Options());
86
         children.add(child1);
88
         children.add(child1);
87
         children.add(child2);
89
         children.add(child2);
88
 
90
 
93
     @Test
95
     @Test
94
     public void findControllerById_Recursive() {
96
     public void findControllerById_Recursive() {
95
         StackController stackController = createStack();
97
         StackController stackController = createStack();
96
-        SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
97
-        SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
98
+        SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
99
+        SimpleViewController child2 = new SimpleViewController(activity, childRegistry, "child2", new Options());
98
         stackController.push(child1, new CommandListenerAdapter());
100
         stackController.push(child1, new CommandListenerAdapter());
99
         stackController.push(child2, new CommandListenerAdapter());
101
         stackController.push(child2, new CommandListenerAdapter());
100
         children.add(stackController);
102
         children.add(stackController);
104
 
106
 
105
     @Test
107
     @Test
106
     public void destroy_DestroysChildren() {
108
     public void destroy_DestroysChildren() {
107
-        ViewController child1 = spy(new SimpleViewController(activity, "child1", new Options()));
109
+        ViewController child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
108
         children.add(child1);
110
         children.add(child1);
109
 
111
 
110
         verify(child1, times(0)).destroy();
112
         verify(child1, times(0)).destroy();
115
     @Test
117
     @Test
116
     public void optionsAreClearedWhenChildIsAppeared() {
118
     public void optionsAreClearedWhenChildIsAppeared() {
117
         StackController stackController = spy(createStack());
119
         StackController stackController = spy(createStack());
118
-        SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
120
+        SimpleViewController child1 = new SimpleViewController(activity, childRegistry, "child1", new Options());
119
         stackController.push(child1, new CommandListenerAdapter());
121
         stackController.push(child1, new CommandListenerAdapter());
120
 
122
 
121
         child1.onViewAppeared();
123
         child1.onViewAppeared();
126
     public void mergeOptions_optionsAreMergedWhenChildAppears() {
128
     public void mergeOptions_optionsAreMergedWhenChildAppears() {
127
         Options options = new Options();
129
         Options options = new Options();
128
         options.topBar.title.text = new Text("new title");
130
         options.topBar.title.text = new Text("new title");
129
-        ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
131
+        ViewController child1 = spy(new SimpleViewController(activity, childRegistry, "child1", options));
130
         children.add(child1);
132
         children.add(child1);
131
         uut.ensureViewIsCreated();
133
         uut.ensureViewIsCreated();
132
 
134
 
144
     public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() {
146
     public void mergeOptions_initialParentOptionsAreNotMutatedWhenChildAppears() {
145
         Options options = new Options();
147
         Options options = new Options();
146
         options.topBar.title.text = new Text("new title");
148
         options.topBar.title.text = new Text("new title");
147
-        ViewController child1 = spy(new SimpleViewController(activity, "child1", options));
149
+        ViewController child1 = spy(new SimpleViewController(activity, childRegistry, "child1", options));
148
         children.add(child1);
150
         children.add(child1);
149
 
151
 
150
         uut.ensureViewIsCreated();
152
         uut.ensureViewIsCreated();

+ 5
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/SideMenuControllerTest.java View File

15
 public class SideMenuControllerTest extends BaseTest {
15
 public class SideMenuControllerTest extends BaseTest {
16
     private SideMenuController uut;
16
     private SideMenuController uut;
17
     private Activity activity;
17
     private Activity activity;
18
+    private ChildControllersRegistry childRegistry;
18
 
19
 
19
     @Override
20
     @Override
20
     public void beforeEach() {
21
     public void beforeEach() {
21
         activity = newActivity();
22
         activity = newActivity();
22
-        uut = new SideMenuController(activity, "sideMenu", new Options());
23
+        childRegistry = new ChildControllersRegistry();
24
+        uut = new SideMenuController(activity, childRegistry, "sideMenu", new Options());
23
     }
25
     }
24
 
26
 
25
     @Test
27
     @Test
26
     public void mergeOptions_openLeftSideMenu() {
28
     public void mergeOptions_openLeftSideMenu() {
27
-        uut.setLeftController(new SimpleComponentViewController(activity, "left", new Options()));
29
+        uut.setLeftController(new SimpleComponentViewController(activity, childRegistry, "left", new Options()));
28
 
30
 
29
         Options options = new Options();
31
         Options options = new Options();
30
         options.sideMenuRootOptions.left.visible = new Bool(true);
32
         options.sideMenuRootOptions.left.visible = new Bool(true);
35
 
37
 
36
     @Test
38
     @Test
37
     public void mergeOptions_openRightSideMenu() {
39
     public void mergeOptions_openRightSideMenu() {
38
-        uut.setRightController(new SimpleComponentViewController(activity, "right", new Options()));
40
+        uut.setRightController(new SimpleComponentViewController(activity, childRegistry, "right", new Options()));
39
 
41
 
40
         Options options = new Options();
42
         Options options = new Options();
41
         options.sideMenuRootOptions.right.visible = new Bool(true);
43
         options.sideMenuRootOptions.right.visible = new Bool(true);

+ 7
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java View File

41
 public class StackControllerTest extends BaseTest {
41
 public class StackControllerTest extends BaseTest {
42
 
42
 
43
     private Activity activity;
43
     private Activity activity;
44
+    private ChildControllersRegistry childRegistry;
44
     private StackController uut;
45
     private StackController uut;
45
     private ViewController child1;
46
     private ViewController child1;
46
     private ViewController child2;
47
     private ViewController child2;
54
         super.beforeEach();
55
         super.beforeEach();
55
         animator = Mockito.mock(NavigationAnimator.class);
56
         animator = Mockito.mock(NavigationAnimator.class);
56
         activity = newActivity();
57
         activity = newActivity();
58
+        childRegistry = new ChildControllersRegistry();
57
         uut = createStackController();
59
         uut = createStackController();
58
-        child1 = spy(new SimpleViewController(activity, "child1", new Options()));
59
-        child2 = spy(new SimpleViewController(activity, "child2", new Options()));
60
-        child3 = spy(new SimpleViewController(activity, "child3", new Options()));
61
-        child4 = spy(new SimpleViewController(activity, "child4", new Options()));
60
+        child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
61
+        child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
62
+        child3 = spy(new SimpleViewController(activity, childRegistry, "child3", new Options()));
63
+        child4 = spy(new SimpleViewController(activity, childRegistry, "child4", new Options()));
62
     }
64
     }
63
 
65
 
64
     @Test
66
     @Test
728
             }
730
             }
729
         });
731
         });
730
         return new StackControllerBuilder(activity)
732
         return new StackControllerBuilder(activity)
733
+                .setChildRegistry(childRegistry)
731
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
734
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
732
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
735
                 .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
733
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
736
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))

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

48
     private final Options options = new Options();
48
     private final Options options = new Options();
49
     private TopTabsViewPager topTabsLayout;
49
     private TopTabsViewPager topTabsLayout;
50
     private Activity activity;
50
     private Activity activity;
51
+    private ChildControllersRegistry childRegistry;
51
 
52
 
52
     @Override
53
     @Override
53
     public void beforeEach() {
54
     public void beforeEach() {
54
         super.beforeEach();
55
         super.beforeEach();
55
 
56
 
56
         activity = newActivity();
57
         activity = newActivity();
58
+        childRegistry = new ChildControllersRegistry();
57
         tabOptions = createOptions();
59
         tabOptions = createOptions();
58
         tabControllers = createTabsControllers(activity, tabOptions);
60
         tabControllers = createTabsControllers(activity, tabOptions);
59
 
61
 
60
         topTabsLayout = spy(new TopTabsViewPager(activity, tabControllers, new TopTabsAdapter(tabControllers)));
62
         topTabsLayout = spy(new TopTabsViewPager(activity, tabControllers, new TopTabsAdapter(tabControllers)));
61
         TopTabsLayoutCreator layoutCreator = Mockito.mock(TopTabsLayoutCreator.class);
63
         TopTabsLayoutCreator layoutCreator = Mockito.mock(TopTabsLayoutCreator.class);
62
         Mockito.when(layoutCreator.create()).thenReturn(topTabsLayout);
64
         Mockito.when(layoutCreator.create()).thenReturn(topTabsLayout);
63
-        uut = spy(new TopTabsController(activity, "componentId", tabControllers, layoutCreator, options));
65
+        uut = spy(new TopTabsController(activity, childRegistry, "componentId", tabControllers, layoutCreator, options));
64
         tabControllers.forEach(viewController -> viewController.setParentController(uut));
66
         tabControllers.forEach(viewController -> viewController.setParentController(uut));
65
 
67
 
66
         parentController = spy(createStackController("stackId"));
68
         parentController = spy(createStackController("stackId"));
97
         for (int i = 0; i < SIZE; i++) {
99
         for (int i = 0; i < SIZE; i++) {
98
             ComponentViewController viewController = new ComponentViewController(
100
             ComponentViewController viewController = new ComponentViewController(
99
                     activity,
101
                     activity,
102
+                    childRegistry,
100
                     "idTab" + i,
103
                     "idTab" + i,
101
                     "theComponentName",
104
                     "theComponentName",
102
                     new TestComponentViewCreator(),
105
                     new TestComponentViewCreator(),
233
         StackController stackController = spy(createStackController("stack"));
236
         StackController stackController = spy(createStackController("stack"));
234
         ComponentViewController first = new ComponentViewController(
237
         ComponentViewController first = new ComponentViewController(
235
                 activity,
238
                 activity,
239
+                childRegistry,
236
                 "firstScreen",
240
                 "firstScreen",
237
                 "comp1",
241
                 "comp1",
238
                 new TestComponentViewCreator(),
242
                 new TestComponentViewCreator(),
259
     @Test
263
     @Test
260
     public void onNavigationButtonPressInvokedOnCurrentTab() {
264
     public void onNavigationButtonPressInvokedOnCurrentTab() {
261
         uut.ensureViewIsCreated();
265
         uut.ensureViewIsCreated();
266
+        uut.onViewAppeared();
262
         uut.switchToTab(1);
267
         uut.switchToTab(1);
263
         uut.sendOnNavigationButtonPressed("btn1");
268
         uut.sendOnNavigationButtonPressed("btn1");
264
         verify(tabControllers.get(1), times(1)).sendOnNavigationButtonPressed("btn1");
269
         verify(tabControllers.get(1), times(1)).sendOnNavigationButtonPressed("btn1");

+ 4
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java View File

32
 
32
 
33
     private ViewController uut;
33
     private ViewController uut;
34
     private Activity activity;
34
     private Activity activity;
35
+    private ChildControllersRegistry childRegistry;
35
 
36
 
36
     @Override
37
     @Override
37
     public void beforeEach() {
38
     public void beforeEach() {
38
         super.beforeEach();
39
         super.beforeEach();
39
         activity = newActivity();
40
         activity = newActivity();
40
-        uut = new SimpleViewController(activity, "uut", new Options());
41
+        childRegistry = new ChildControllersRegistry();
42
+        uut = new SimpleViewController(activity, childRegistry, "uut", new Options());
41
     }
43
     }
42
 
44
 
43
     @Test
45
     @Test
161
 
163
 
162
     @Test
164
     @Test
163
     public void onDestroy_RemovesGlobalLayoutListener() throws Exception {
165
     public void onDestroy_RemovesGlobalLayoutListener() throws Exception {
164
-        new SimpleViewController(activity, "ensureNotNull", new Options()).destroy();
166
+        new SimpleViewController(activity, childRegistry, "ensureNotNull", new Options()).destroy();
165
 
167
 
166
         ViewController spy = spy(uut);
168
         ViewController spy = spy(uut);
167
         View view = spy.getView();
169
         View view = spy.getView();

+ 39
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllerTest.java View File

1
+package com.reactnativenavigation.viewcontrollers.child;
2
+
3
+import com.reactnativenavigation.BaseTest;
4
+import com.reactnativenavigation.mocks.SimpleViewController;
5
+import com.reactnativenavigation.parse.Options;
6
+import com.reactnativenavigation.viewcontrollers.ChildController;
7
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
8
+
9
+import org.junit.Test;
10
+
11
+import static org.mockito.Mockito.spy;
12
+import static org.mockito.Mockito.times;
13
+import static org.mockito.Mockito.verify;
14
+
15
+public class ChildControllerTest extends BaseTest {
16
+
17
+    private ChildController uut;
18
+    private ChildControllersRegistry childRegistry;
19
+
20
+    @Override
21
+    public void beforeEach() {
22
+        childRegistry = spy(new ChildControllersRegistry());
23
+        uut = new SimpleViewController(newActivity(), childRegistry, "childId", new Options());
24
+    }
25
+
26
+    @Test
27
+    public void onViewAppeared() {
28
+        uut.onViewAppeared();
29
+        verify(childRegistry, times(1)).onViewAppeared(uut);
30
+    }
31
+
32
+    @Test
33
+    public void onViewDisappear() {
34
+        uut.onViewAppeared();
35
+
36
+        uut.onViewDisappear();
37
+        verify(childRegistry, times(1)).onViewDisappear(uut);
38
+    }
39
+}

+ 47
- 0
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/child/ChildControllersRegistryTest.java View File

1
+package com.reactnativenavigation.viewcontrollers.child;
2
+
3
+import android.app.Activity;
4
+
5
+import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.mocks.SimpleViewController;
7
+import com.reactnativenavigation.parse.Options;
8
+import com.reactnativenavigation.viewcontrollers.ChildController;
9
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
10
+
11
+import org.junit.Test;
12
+
13
+import static org.assertj.core.api.Java6Assertions.assertThat;
14
+import static org.mockito.Mockito.spy;
15
+import static org.mockito.Mockito.times;
16
+import static org.mockito.Mockito.verify;
17
+
18
+public class ChildControllersRegistryTest extends BaseTest {
19
+    private ChildControllersRegistry uut;
20
+    private ChildController child1;
21
+    private ChildController child2;
22
+
23
+    @Override
24
+    public void beforeEach() {
25
+        Activity activity = newActivity();
26
+        uut = new ChildControllersRegistry();
27
+        child1 = spy(new SimpleViewController(activity, uut, "child1", new Options()));
28
+        child2 = spy(new SimpleViewController(activity, uut, "child2", new Options()));
29
+    }
30
+
31
+    @Test
32
+    public void onViewAppeared() {
33
+        child1.onViewAppeared();
34
+        verify(child1, times(0)).onViewBroughtToFront();
35
+        assertThat(uut.size()).isOne();
36
+    }
37
+
38
+    @Test
39
+    public void onViewDisappear() {
40
+        child1.onViewAppeared();
41
+        child2.onViewAppeared();
42
+        assertThat(uut.size()).isEqualTo(2);
43
+        child2.onViewDisappear();
44
+        verify(child1, times(1)).onViewBroughtToFront();
45
+        assertThat(uut.size()).isOne();
46
+    }
47
+}

+ 19
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalPresenterTest.java View File

11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.utils.CommandListener;
13
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
 import com.reactnativenavigation.utils.CommandListenerAdapter;
14
+import com.reactnativenavigation.viewcontrollers.ChildController;
15
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
14
 import com.reactnativenavigation.viewcontrollers.ParentController;
16
 import com.reactnativenavigation.viewcontrollers.ParentController;
15
 import com.reactnativenavigation.viewcontrollers.ViewController;
17
 import com.reactnativenavigation.viewcontrollers.ViewController;
16
 
18
 
29
     private static final String MODAL_ID_1 = "modalId1";
31
     private static final String MODAL_ID_1 = "modalId1";
30
     private static final String MODAL_ID_2 = "modalId2";
32
     private static final String MODAL_ID_2 = "modalId2";
31
 
33
 
32
-    private ViewController modal1;
33
-    private ViewController modal2;
34
+    private ChildController modal1;
35
+    private ChildController modal2;
34
     private ModalPresenter uut;
36
     private ModalPresenter uut;
35
     private FrameLayout contentLayout;
37
     private FrameLayout contentLayout;
36
     private ModalAnimator animator;
38
     private ModalAnimator animator;
37
     private ViewController rootController;
39
     private ViewController rootController;
40
+    private ChildControllersRegistry childRegistry;
38
 
41
 
39
     @Override
42
     @Override
40
     public void beforeEach() {
43
     public void beforeEach() {
41
         Activity activity = newActivity();
44
         Activity activity = newActivity();
45
+        childRegistry = new ChildControllersRegistry();
42
 
46
 
43
         ViewGroup root = new FrameLayout(activity);
47
         ViewGroup root = new FrameLayout(activity);
44
         rootController = Mockito.mock(ParentController.class);
48
         rootController = Mockito.mock(ParentController.class);
50
         animator = spy(new ModalAnimator(activity));
54
         animator = spy(new ModalAnimator(activity));
51
         uut = new ModalPresenter(animator);
55
         uut = new ModalPresenter(animator);
52
         uut.setContentLayout(contentLayout);
56
         uut.setContentLayout(contentLayout);
53
-        modal1 = spy(new SimpleViewController(activity, MODAL_ID_1, new Options()));
54
-        modal2 = spy(new SimpleViewController(activity, MODAL_ID_2, new Options()));
57
+        modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
58
+        modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
55
     }
59
     }
56
 
60
 
57
     @Test
61
     @Test
130
         verify(spy, times(1)).addView(modal2.getView(), 0);
134
         verify(spy, times(1)).addView(modal2.getView(), 0);
131
     }
135
     }
132
 
136
 
137
+    @Test
138
+    public void dismissModal_onViewBroughtToFront_invokedOnPreviousView() {
139
+        disableShowModalAnimation(modal1, modal2);
140
+        disableDismissModalAnimation(modal1, modal2);
141
+
142
+        uut.showModal(modal1, rootController, new CommandListenerAdapter());
143
+        uut.showModal(modal2, rootController, new CommandListenerAdapter());
144
+        uut.dismissModal(modal2, modal1, new CommandListenerAdapter());
145
+        verify(modal1, times(1)).onViewBroughtToFront();
146
+    }
147
+
133
     @Test
148
     @Test
134
     public void dismissModal_noAnimation() {
149
     public void dismissModal_noAnimation() {
135
         disableShowModalAnimation(modal1);
150
         disableShowModalAnimation(modal1);

+ 7
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/modal/ModalStackTest.java View File

10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.utils.CommandListener;
11
 import com.reactnativenavigation.utils.CommandListener;
12
 import com.reactnativenavigation.utils.CommandListenerAdapter;
12
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
13
 import com.reactnativenavigation.viewcontrollers.ParentController;
14
 import com.reactnativenavigation.viewcontrollers.ParentController;
14
 import com.reactnativenavigation.viewcontrollers.ViewController;
15
 import com.reactnativenavigation.viewcontrollers.ViewController;
15
 
16
 
39
     private ViewController modal2;
40
     private ViewController modal2;
40
     private ViewController modal3;
41
     private ViewController modal3;
41
     private Activity activity;
42
     private Activity activity;
43
+    private ChildControllersRegistry childRegistry;
42
     private ModalPresenter presenter;
44
     private ModalPresenter presenter;
43
     private ModalAnimator animator;
45
     private ModalAnimator animator;
44
     private ViewController rootController;
46
     private ViewController rootController;
46
     @Override
48
     @Override
47
     public void beforeEach() {
49
     public void beforeEach() {
48
         activity = newActivity();
50
         activity = newActivity();
51
+        childRegistry = new ChildControllersRegistry();
49
 
52
 
50
         ViewGroup root = new FrameLayout(activity);
53
         ViewGroup root = new FrameLayout(activity);
51
         rootController = Mockito.mock(ParentController.class);
54
         rootController = Mockito.mock(ParentController.class);
58
         presenter = spy(new ModalPresenter(animator));
61
         presenter = spy(new ModalPresenter(animator));
59
         uut = new ModalStack(presenter);
62
         uut = new ModalStack(presenter);
60
         uut.setContentLayout(activityContentView);
63
         uut.setContentLayout(activityContentView);
61
-        modal1 = spy(new SimpleViewController(activity, MODAL_ID_1, new Options()));
62
-        modal2 = spy(new SimpleViewController(activity, MODAL_ID_2, new Options()));
63
-        modal3 = spy(new SimpleViewController(activity, MODAL_ID_3, new Options()));
64
+        modal1 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_1, new Options()));
65
+        modal2 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_2, new Options()));
66
+        modal3 = spy(new SimpleViewController(activity, childRegistry, MODAL_ID_3, new Options()));
64
     }
67
     }
65
 
68
 
66
     @Test
69
     @Test
224
 
227
 
225
     @Test
228
     @Test
226
     public void handleBack_ViewControllerTakesPrecedenceOverModal() {
229
     public void handleBack_ViewControllerTakesPrecedenceOverModal() {
227
-        ViewController backHandlingModal = spy(new SimpleViewController(activity, "stack", new Options()){
230
+        ViewController backHandlingModal = spy(new SimpleViewController(activity, childRegistry, "stack", new Options()){
228
             @Override
231
             @Override
229
             public boolean handleBack(CommandListener listener) {
232
             public boolean handleBack(CommandListener listener) {
230
                 return true;
233
                 return true;

+ 17
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/overlay/OverlayManagerTest.java View File

9
 import com.reactnativenavigation.presentation.OverlayManager;
9
 import com.reactnativenavigation.presentation.OverlayManager;
10
 import com.reactnativenavigation.utils.CommandListener;
10
 import com.reactnativenavigation.utils.CommandListener;
11
 import com.reactnativenavigation.utils.CommandListenerAdapter;
11
 import com.reactnativenavigation.utils.CommandListenerAdapter;
12
+import com.reactnativenavigation.viewcontrollers.ChildControllersRegistry;
12
 
13
 
13
 import org.junit.Test;
14
 import org.junit.Test;
14
 
15
 
20
 
21
 
21
 public class OverlayManagerTest extends BaseTest {
22
 public class OverlayManagerTest extends BaseTest {
22
     private static final String OVERLAY_ID_1 = "OVERLAY_1";
23
     private static final String OVERLAY_ID_1 = "OVERLAY_1";
24
+    private static final String OVERLAY_ID_2 = "OVERLAY_2";
25
+
23
     private OverlayManager uut;
26
     private OverlayManager uut;
24
     private SimpleViewController overlay1;
27
     private SimpleViewController overlay1;
28
+    private SimpleViewController overlay2;
25
     private FrameLayout root;
29
     private FrameLayout root;
26
 
30
 
27
     @Override
31
     @Override
31
         root.layout(0, 0, 1000, 1000);
35
         root.layout(0, 0, 1000, 1000);
32
         activity.setContentView(root);
36
         activity.setContentView(root);
33
 
37
 
34
-        overlay1 = spy(new SimpleViewController(activity, OVERLAY_ID_1, new Options()));
38
+        ChildControllersRegistry childRegistry = new ChildControllersRegistry();
39
+        overlay1 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_1, new Options()));
40
+        overlay2 = spy(new SimpleViewController(activity, childRegistry, OVERLAY_ID_2, new Options()));
35
         uut = new OverlayManager();
41
         uut = new OverlayManager();
36
     }
42
     }
37
 
43
 
60
         uut.dismiss(overlay1.getId(), listener);
66
         uut.dismiss(overlay1.getId(), listener);
61
         verify(listener, times(1)).onError(any());
67
         verify(listener, times(1)).onError(any());
62
     }
68
     }
69
+
70
+    @Test
71
+    public void dismiss_onViewReturnedToFront() {
72
+        uut.show(root, overlay1, new CommandListenerAdapter());
73
+        uut.show(root, overlay2, new CommandListenerAdapter());
74
+        verify(overlay1, times(0)).onViewBroughtToFront();
75
+
76
+        uut.dismiss(OVERLAY_ID_2, new CommandListenerAdapter());
77
+        verify(overlay1, times(1)).onViewBroughtToFront();
78
+    }
63
 }
79
 }