Browse Source

Reformat file

Guy Carmeli 6 years ago
parent
commit
76a9329bab

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

@@ -12,6 +12,7 @@ import com.reactnativenavigation.presentation.NavigationOptionsListener;
12 12
 import com.reactnativenavigation.presentation.OverlayManager;
13 13
 import com.reactnativenavigation.utils.CompatUtils;
14 14
 import com.reactnativenavigation.utils.NoOpPromise;
15
+import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
15 16
 
16 17
 import java.util.Collection;
17 18
 import java.util.Collections;
@@ -19,47 +20,47 @@ import java.util.Collections;
19 20
 public class Navigator extends ParentController {
20 21
 
21 22
     private static final NoOpPromise NO_OP = new NoOpPromise();
22
-    private final ModalStack modalStack = new ModalStack();
23
-	private ViewController root;
23
+    private final ModalStack modalStack = new ModalStack(new ModalCreator());
24
+    private ViewController root;
24 25
     private OverlayManager overlayManager = new OverlayManager();
25 26
     private Options defaultOptions = new Options();
26 27
 
27 28
     public Navigator(final Activity activity) {
28
-		super(activity, "navigator" + CompatUtils.generateViewId(), new Options());
29
-	}
29
+        super(activity, "navigator" + CompatUtils.generateViewId(), new Options());
30
+    }
31
+
32
+    @NonNull
33
+    @Override
34
+    protected ViewGroup createView() {
35
+        return new FrameLayout(getActivity());
36
+    }
30 37
 
31 38
     @NonNull
32
-	@Override
33
-	protected ViewGroup createView() {
34
-		return new FrameLayout(getActivity());
35
-	}
36
-
37
-	@NonNull
38
-	@Override
39
-	public Collection<ViewController> getChildControllers() {
40
-		return root == null ? Collections.emptyList() : Collections.singletonList(root);
41
-	}
42
-
43
-	@Override
44
-	public boolean handleBack() {
45
-		return root != null && root.handleBack();
46
-	}
47
-
48
-	@Override
49
-	public void destroy() {
50
-		modalStack.dismissAll(NO_OP);
51
-		super.destroy();
52
-	}
53
-
54
-	public void setRoot(final ViewController viewController, Promise promise) {
55
-		if (root != null) {
56
-			root.destroy();
57
-		}
58
-
59
-		root = viewController;
60
-		getView().addView(viewController.getView());
39
+    @Override
40
+    public Collection<ViewController> getChildControllers() {
41
+        return root == null ? Collections.emptyList() : Collections.singletonList(root);
42
+    }
43
+
44
+    @Override
45
+    public boolean handleBack() {
46
+        return root != null && root.handleBack();
47
+    }
48
+
49
+    @Override
50
+    public void destroy() {
51
+        modalStack.dismissAll(NO_OP);
52
+        super.destroy();
53
+    }
54
+
55
+    public void setRoot(final ViewController viewController, Promise promise) {
56
+        if (root != null) {
57
+            root.destroy();
58
+        }
59
+
60
+        root = viewController;
61
+        getView().addView(viewController.getView());
61 62
         promise.resolve(viewController.getId());
62
-	}
63
+    }
63 64
 
64 65
     public void setDefaultOptions(Options defaultOptions) {
65 66
         this.defaultOptions = defaultOptions;
@@ -69,78 +70,78 @@ public class Navigator extends ParentController {
69 70
         return defaultOptions;
70 71
     }
71 72
 
72
-	public void setOptions(final String componentId, Options options) {
73
-		ViewController target = findControllerById(componentId);
74
-		if (target instanceof NavigationOptionsListener) {
75
-			((NavigationOptionsListener) target).mergeOptions(options);
76
-		}
77
-		if (root instanceof NavigationOptionsListener) {
78
-			((NavigationOptionsListener) root).mergeOptions(options);
79
-		}
80
-	}
81
-
82
-	public void push(final String fromId, final ViewController viewController, Promise promise) {
83
-		ViewController from = findControllerById(fromId);
84
-		if (from != null) {
85
-		    from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, promise));
86
-		}
87
-	}
88
-
89
-	void pop(final String fromId, Promise promise) {
90
-		ViewController from = findControllerById(fromId);
91
-		if (from != null) {
92
-		    from.performOnParentStack(stack -> ((StackController) stack).pop(promise));
93
-		}
94
-	}
95
-
96
-	public void popSpecific(final String id, Promise promise) {
97
-		ViewController from = findControllerById(id);
98
-		if (from != null) {
99
-		    from.performOnParentStack(stack -> ((StackController) stack).popSpecific(from, promise), () -> rejectPromise(promise));
100
-		} else {
101
-			rejectPromise(promise);
102
-		}
103
-	}
104
-
105
-	public void popToRoot(final String id, Promise promise) {
106
-		ViewController from = findControllerById(id);
107
-		if (from != null) {
108
-		    from.performOnParentStack(stack -> ((StackController) stack).popToRoot(promise));
109
-		}
110
-	}
111
-
112
-	public void popTo(final String componentId, Promise promise) {
113
-		ViewController target = findControllerById(componentId);
114
-		if (target != null) {
115
-		    target.performOnParentStack(stack -> ((StackController) stack).popTo(target, promise), () -> rejectPromise(promise));
116
-		} else {
117
-			rejectPromise(promise);
118
-		}
119
-	}
120
-
121
-	public void showModal(final ViewController viewController, Promise promise) {
122
-		modalStack.showModal(viewController, promise);
123
-	}
124
-
125
-	public void dismissModal(final String componentId, Promise promise) {
126
-		modalStack.dismissModal(componentId, promise);
127
-	}
128
-
129
-	public void dismissAllModals(Promise promise) {
130
-		modalStack.dismissAll(promise);
131
-	}
132
-
133
-	public void showOverlay(ViewController overlay) {
73
+    public void setOptions(final String componentId, Options options) {
74
+        ViewController target = findControllerById(componentId);
75
+        if (target instanceof NavigationOptionsListener) {
76
+            ((NavigationOptionsListener) target).mergeOptions(options);
77
+        }
78
+        if (root instanceof NavigationOptionsListener) {
79
+            ((NavigationOptionsListener) root).mergeOptions(options);
80
+        }
81
+    }
82
+
83
+    public void push(final String fromId, final ViewController viewController, Promise promise) {
84
+        ViewController from = findControllerById(fromId);
85
+        if (from != null) {
86
+            from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, promise));
87
+        }
88
+    }
89
+
90
+    void pop(final String fromId, Promise promise) {
91
+        ViewController from = findControllerById(fromId);
92
+        if (from != null) {
93
+            from.performOnParentStack(stack -> ((StackController) stack).pop(promise));
94
+        }
95
+    }
96
+
97
+    public void popSpecific(final String id, Promise promise) {
98
+        ViewController from = findControllerById(id);
99
+        if (from != null) {
100
+            from.performOnParentStack(stack -> ((StackController) stack).popSpecific(from, promise), () -> rejectPromise(promise));
101
+        } else {
102
+            rejectPromise(promise);
103
+        }
104
+    }
105
+
106
+    public void popToRoot(final String id, Promise promise) {
107
+        ViewController from = findControllerById(id);
108
+        if (from != null) {
109
+            from.performOnParentStack(stack -> ((StackController) stack).popToRoot(promise));
110
+        }
111
+    }
112
+
113
+    public void popTo(final String componentId, Promise promise) {
114
+        ViewController target = findControllerById(componentId);
115
+        if (target != null) {
116
+            target.performOnParentStack(stack -> ((StackController) stack).popTo(target, promise), () -> rejectPromise(promise));
117
+        } else {
118
+            rejectPromise(promise);
119
+        }
120
+    }
121
+
122
+    public void showModal(final ViewController viewController, Promise promise) {
123
+        modalStack.showModal(viewController, promise);
124
+    }
125
+
126
+    public void dismissModal(final String componentId, Promise promise) {
127
+        modalStack.dismissModal(componentId, promise);
128
+    }
129
+
130
+    public void dismissAllModals(Promise promise) {
131
+        modalStack.dismissAll(promise);
132
+    }
133
+
134
+    public void showOverlay(ViewController overlay) {
134 135
         overlayManager.show(getView(), overlay);
135
-	}
136
+    }
136 137
 
137
-	public void dismissOverlay(final String componentId) {
138
-		overlayManager.dismiss(getView(), componentId);
139
-	}
138
+    public void dismissOverlay(final String componentId) {
139
+        overlayManager.dismiss(getView(), componentId);
140
+    }
140 141
 
141
-	static void rejectPromise(Promise promise) {
142
+    static void rejectPromise(Promise promise) {
142 143
         promise.reject(new Throwable("Nothing to pop"));
143
-	}
144
+    }
144 145
 
145 146
     @Nullable
146 147
     @Override