Daniel Zlotin 6 years ago
parent
commit
929b26c0fa

+ 0
- 39
lib/android/app/src/main/java/com/reactnativenavigation/anim/ModalAnimator.java View File

@@ -1,39 +0,0 @@
1
-package com.reactnativenavigation.anim;
2
-
3
-
4
-import android.animation.AnimatorListenerAdapter;
5
-import android.animation.AnimatorSet;
6
-import android.content.Context;
7
-import android.view.View;
8
-
9
-import com.reactnativenavigation.parse.AnimationsOptions;
10
-
11
-public class ModalAnimator extends BaseAnimator {
12
-
13
-    public ModalAnimator(Context context, AnimationsOptions options) {
14
-        super(context);
15
-        this.options = options;
16
-    }
17
-
18
-    public void animateShow(View contentView, AnimatorListenerAdapter listener) {
19
-        AnimatorSet animatorSet;
20
-        if (options.showModal.hasValue()) {
21
-            animatorSet = options.showModal.getAnimation(contentView);
22
-        } else {
23
-            animatorSet = getDefaultPushAnimation(contentView);
24
-        }
25
-        animatorSet.addListener(listener);
26
-        animatorSet.start();
27
-    }
28
-
29
-    public void animateDismiss(View contentView, AnimatorListenerAdapter listener) {
30
-        AnimatorSet animatorSet;
31
-        if (options.dismissModal.hasValue()) {
32
-            animatorSet = options.dismissModal.getAnimation(contentView);
33
-        } else {
34
-            animatorSet = getDefaultPopAnimation(contentView);
35
-        }
36
-        animatorSet.addListener(listener);
37
-        animatorSet.start();
38
-    }
39
-}

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

@@ -1,108 +0,0 @@
1
-package com.reactnativenavigation.viewcontrollers;
2
-
3
-import android.support.annotation.Nullable;
4
-
5
-import com.reactnativenavigation.utils.CommandListenerAdapter;
6
-import com.reactnativenavigation.utils.Task;
7
-import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
8
-import com.reactnativenavigation.viewcontrollers.modal.Modal;
9
-import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
10
-import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
11
-
12
-import java.util.ArrayList;
13
-import java.util.List;
14
-
15
-class ModalStack implements ModalListener {
16
-
17
-    private List<Modal> modals = new ArrayList<>();
18
-    private ModalCreator creator;
19
-    private ModalListener modalListener;
20
-
21
-    ModalStack(ModalCreator creator, ModalListener modalListener) {
22
-        this.creator = creator;
23
-        this.modalListener = modalListener;
24
-    }
25
-
26
-    void showModal(final ViewController viewController, CommandListener listener) {
27
-        Modal modal = creator.create(viewController, this);
28
-        modals.add(modal);
29
-        modal.show();
30
-        listener.onSuccess(viewController.getId());
31
-    }
32
-
33
-    void dismissModal(final String componentId, CommandListener listener) {
34
-        applyOnModal(componentId, (modal) -> modal.dismiss(listener), () -> listener.onError("Nothing to dismiss"));
35
-    }
36
-
37
-    void dismissAll(CommandListener listener) {
38
-        for (Modal modal : modals) {
39
-            modal.dismiss(size() == 1 ? listener : new CommandListenerAdapter());
40
-        }
41
-        modals.clear();
42
-    }
43
-
44
-    boolean isEmpty() {
45
-        return modals.isEmpty();
46
-    }
47
-
48
-    public int size() {
49
-        return modals.size();
50
-    }
51
-
52
-    @Nullable
53
-    Modal findModalByComponentId(String componentId) {
54
-        for (Modal modal : modals) {
55
-            if (modal.containsDeepComponentId(componentId)) {
56
-                return modal;
57
-            }
58
-        }
59
-        return null;
60
-    }
61
-
62
-    @Nullable
63
-    ViewController findControllerById(String id) {
64
-        Modal modal = findModalByComponentId(id);
65
-        return modal != null ? modal.viewController.findControllerById(id) : null;
66
-    }
67
-
68
-    @Override
69
-    public void onModalDismiss(Modal modal) {
70
-        if (peek() == modal) {
71
-            modals.remove(modal);
72
-            applyOnModal(peek(), peek -> peek.viewController.onViewAppeared(), null);
73
-        } else {
74
-            modals.remove(modal);
75
-        }
76
-        modalListener.onModalDismiss(modal);
77
-    }
78
-
79
-    @Override
80
-    public void onModalDisplay(Modal modal) {
81
-        modalListener.onModalDisplay(modal);
82
-    }
83
-
84
-    private Modal peek() {
85
-        return isEmpty() ? null : modals.get(modals.size() - 1);
86
-    }
87
-
88
-    public boolean handleBack(CommandListener listener) {
89
-        return !modals.isEmpty() && peek().handleBack(listener);
90
-    }
91
-
92
-    private void applyOnModal(String componentId, Task<Modal> accept, Runnable reject) {
93
-        Modal modal = findModalByComponentId(componentId);
94
-        if (modal != null) {
95
-            if (accept != null) accept.run(modal);
96
-        } else {
97
-            if (reject != null) reject.run();
98
-        }
99
-    }
100
-
101
-    private void applyOnModal(Modal modal, Task<Modal> accept, Runnable reject) {
102
-        if (modal != null) {
103
-            if (accept != null) accept.run(modal);
104
-        } else {
105
-            if (reject != null) reject.run();
106
-        }
107
-    }
108
-}

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

@@ -16,15 +16,13 @@ import com.reactnativenavigation.presentation.NavigationOptionsListener;
16 16
 import com.reactnativenavigation.presentation.OverlayManager;
17 17
 import com.reactnativenavigation.utils.CommandListenerAdapter;
18 18
 import com.reactnativenavigation.utils.CompatUtils;
19
-import com.reactnativenavigation.viewcontrollers.modal.Modal;
20
-import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
21 19
 import com.reactnativenavigation.viewcontrollers.modal.ModalPresenter;
22 20
 import com.reactnativenavigation.viewcontrollers.modal.ModalStack2;
23 21
 
24 22
 import java.util.Collection;
25 23
 import java.util.Collections;
26 24
 
27
-public class Navigator extends ParentController implements ModalListener {
25
+public class Navigator extends ParentController {
28 26
 
29 27
     public interface CommandListener {
30 28
         void onSuccess(String childId);
@@ -32,7 +30,6 @@ public class Navigator extends ParentController implements ModalListener {
32 30
         void onError(String message);
33 31
     }
34 32
 
35
-//    private final ModalStack modalStack;
36 33
     private final ModalStack2 modalStack;
37 34
     private ViewController root;
38 35
     private FrameLayout rootLayout;
@@ -42,7 +39,6 @@ public class Navigator extends ParentController implements ModalListener {
42 39
 
43 40
     public Navigator(final Activity activity) {
44 41
         super(activity, "navigator" + CompatUtils.generateViewId(), new Options());
45
-//        modalStack = new ModalStack(new ModalCreator(), this);
46 42
         modalStack = new ModalStack2(new ModalPresenter(new ModalAnimator2(activity)));
47 43
     }
48 44
 
@@ -202,20 +198,6 @@ public class Navigator extends ParentController implements ModalListener {
202 198
         });
203 199
     }
204 200
 
205
-    @Override
206
-    public void onModalDisplay(Modal modal) {
207
-        if (modalStack.size() == 1) {
208
-            root.onViewLostFocus();
209
-        }
210
-    }
211
-
212
-    @Override
213
-    public void onModalDismiss(Modal modal) {
214
-        if (modalStack.isEmpty()) {
215
-            root.onViewRegainedFocus();
216
-        }
217
-    }
218
-
219 201
     public void dismissAllModals(CommandListener listener) {
220 202
         if (!modalStack.isEmpty()) contentLayout.addView(root.getView(), 0);
221 203
         modalStack.dismissAllModals(listener);

+ 0
- 98
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/Modal.java View File

@@ -1,98 +0,0 @@
1
-package com.reactnativenavigation.viewcontrollers.modal;
2
-
3
-import android.animation.Animator;
4
-import android.animation.AnimatorListenerAdapter;
5
-import android.app.Dialog;
6
-import android.content.DialogInterface;
7
-import android.support.annotation.Nullable;
8
-import android.view.KeyEvent;
9
-import android.view.View;
10
-
11
-import com.reactnativenavigation.R;
12
-import com.reactnativenavigation.anim.ModalAnimator;
13
-import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
14
-import com.reactnativenavigation.viewcontrollers.ViewController;
15
-
16
-import static android.view.View.MeasureSpec.EXACTLY;
17
-import static android.view.View.MeasureSpec.makeMeasureSpec;
18
-
19
-public class Modal implements DialogInterface.OnKeyListener, DialogInterface.OnDismissListener, DialogInterface.OnShowListener {
20
-    public final ViewController viewController;
21
-    private final Dialog dialog;
22
-    private ModalListener modalListener;
23
-    @Nullable private CommandListener dismissCommandListener;
24
-
25
-    private ModalAnimator animator;
26
-
27
-    public Modal(final ViewController viewController, ModalListener modalListener) {
28
-        this.viewController = viewController;
29
-        dialog = new Dialog(viewController.getActivity(), R.style.Modal);
30
-        this.modalListener = modalListener;
31
-        dialog.setOnKeyListener(this);
32
-        dialog.setOnDismissListener(this);
33
-        dialog.setOnShowListener(this);
34
-        animator = new ModalAnimator(viewController.getActivity(), viewController.options.animations);
35
-    }
36
-
37
-    public void show() {
38
-        preMeasureView();
39
-        final View contentView = viewController.getView();
40
-        dialog.show();
41
-        animator.animateShow(contentView, new AnimatorListenerAdapter() {
42
-            @Override
43
-            public void onAnimationStart(Animator animation) {
44
-                dialog.setContentView(contentView);
45
-            }
46
-        });
47
-    }
48
-
49
-    public void dismiss(CommandListener listener) {
50
-        dismissCommandListener = listener;
51
-        animator.animateDismiss(viewController.getView(), new AnimatorListenerAdapter() {
52
-            @Override
53
-            public void onAnimationEnd(Animator animation) {
54
-                dialog.dismiss();
55
-            }
56
-        });
57
-    }
58
-
59
-    public boolean containsDeepComponentId(String componentId) {
60
-        return viewController.findControllerById(componentId) != null;
61
-    }
62
-
63
-    private void preMeasureView() {
64
-        View decorView = viewController.getActivity().getWindow().getDecorView();
65
-        viewController.getView().measure(makeMeasureSpec(decorView.getMeasuredWidth(), EXACTLY), makeMeasureSpec(decorView.getMeasuredHeight(), EXACTLY));
66
-    }
67
-
68
-    @Override
69
-    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
70
-        if (keyCode == KeyEvent.KEYCODE_BACK) {
71
-            if (event.getAction() == KeyEvent.ACTION_UP) {
72
-                viewController.getActivity().onBackPressed();
73
-            }
74
-            return true;
75
-        }
76
-        return false;
77
-    }
78
-
79
-    @Override
80
-    public void onDismiss(DialogInterface dialog) {
81
-        modalListener.onModalDismiss(this);
82
-        if (dismissCommandListener != null) {
83
-            dismissCommandListener.onSuccess(viewController.getId());
84
-        }
85
-    }
86
-
87
-    @Override
88
-    public void onShow(DialogInterface dialog) {
89
-        modalListener.onModalDisplay(this);
90
-    }
91
-
92
-    public boolean handleBack(CommandListener listener) {
93
-        if (!viewController.handleBack(listener)) {
94
-            dialog.dismiss();
95
-        }
96
-        return true;
97
-    }
98
-}

+ 0
- 9
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalCreator.java View File

@@ -1,9 +0,0 @@
1
-package com.reactnativenavigation.viewcontrollers.modal;
2
-
3
-import com.reactnativenavigation.viewcontrollers.ViewController;
4
-
5
-public class ModalCreator {
6
-    public Modal create(ViewController viewController, ModalListener dismissListener) {
7
-        return new Modal(viewController, dismissListener);
8
-    }
9
-}

+ 0
- 7
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/ModalListener.java View File

@@ -1,7 +0,0 @@
1
-package com.reactnativenavigation.viewcontrollers.modal;
2
-
3
-public interface ModalListener {
4
-    void onModalDismiss(Modal modal);
5
-
6
-    void onModalDisplay(Modal modal);
7
-}

+ 0
- 15
lib/android/app/src/test/java/com/reactnativenavigation/mocks/ModalCreatorMock.java View File

@@ -1,15 +0,0 @@
1
-package com.reactnativenavigation.mocks;
2
-
3
-import com.reactnativenavigation.viewcontrollers.ViewController;
4
-import com.reactnativenavigation.viewcontrollers.modal.Modal;
5
-import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
6
-import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
7
-
8
-import static org.mockito.Mockito.spy;
9
-
10
-public class ModalCreatorMock extends ModalCreator {
11
-    @Override
12
-    public Modal create(ViewController viewController, ModalListener onDismissListener) {
13
-        return spy(new Modal(viewController, onDismissListener));
14
-    }
15
-}

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

@@ -1,128 +0,0 @@
1
-package com.reactnativenavigation.viewcontrollers;
2
-
3
-import com.reactnativenavigation.BaseTest;
4
-import com.reactnativenavigation.mocks.ModalCreatorMock;
5
-import com.reactnativenavigation.mocks.SimpleViewController;
6
-import com.reactnativenavigation.parse.Options;
7
-import com.reactnativenavigation.utils.CommandListenerAdapter;
8
-import com.reactnativenavigation.viewcontrollers.modal.Modal;
9
-import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
10
-
11
-import org.junit.Test;
12
-
13
-import static org.assertj.core.api.Java6Assertions.assertThat;
14
-import static org.mockito.ArgumentMatchers.any;
15
-import static org.mockito.Mockito.spy;
16
-import static org.mockito.Mockito.times;
17
-import static org.mockito.Mockito.verify;
18
-
19
-public class ModalStackTest extends BaseTest {
20
-    private static final String CONTROLLER_ID = "simpleController";
21
-    private ModalStack uut;
22
-    private SimpleViewController viewController;
23
-    private ModalListener modalListener;
24
-
25
-    @Override
26
-    public void beforeEach() {
27
-        createDismissListener();
28
-        uut = spy(new ModalStack(new ModalCreatorMock(), modalListener));
29
-        viewController = new SimpleViewController(newActivity(), CONTROLLER_ID, new Options());
30
-    }
31
-
32
-    @SuppressWarnings("Convert2Lambda")
33
-    private void createDismissListener() {
34
-        ModalListener dismissListener = new ModalListener() {
35
-            @Override
36
-            public void onModalDismiss(Modal modal) {
37
-
38
-            }
39
-
40
-            @Override
41
-            public void onModalDisplay(Modal modal) {
42
-
43
-            }
44
-        };
45
-        this.modalListener = spy(dismissListener);
46
-    }
47
-
48
-    @Test
49
-    public void modalRefIsSaved() {
50
-        uut.showModal(viewController, new CommandListenerAdapter());
51
-        assertThat(findModal(CONTROLLER_ID)).isNotNull();
52
-    }
53
-
54
-    @Test
55
-    public void modalIsShown() {
56
-        uut.showModal(viewController, new CommandListenerAdapter() {
57
-            @Override
58
-            public void onSuccess(String childId) {
59
-                verify(findModal(CONTROLLER_ID), times(1)).show();
60
-                verify(modalListener, times(1)).onModalDisplay(any());
61
-            }
62
-        });
63
-    }
64
-
65
-    @Test
66
-    public void modalIsDismissed() {
67
-        uut.showModal(viewController, new CommandListenerAdapter());
68
-        final Modal modal = findModal(CONTROLLER_ID);
69
-        assertThat(modal).isNotNull();
70
-        uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
71
-            @Override
72
-            public void onSuccess(String childId) {
73
-                assertThat(findModal(CONTROLLER_ID)).isNull();
74
-                verify(uut, times(1)).onModalDismiss(modal);
75
-            }
76
-        });
77
-    }
78
-
79
-    @Test
80
-    public void dismissAllModals() {
81
-        uut.showModal(new SimpleViewController(newActivity(), "1", new Options()), new CommandListenerAdapter());
82
-        uut.showModal(new SimpleViewController(newActivity(), "2", new Options()), new CommandListenerAdapter());
83
-        uut.dismissAll(new CommandListenerAdapter() {
84
-            @Override
85
-            public void onSuccess(String childId) {
86
-                assertThat(uut.isEmpty()).isTrue();
87
-            }
88
-        });
89
-    }
90
-
91
-    @Test
92
-    public void isEmpty() {
93
-        assertThat(uut.isEmpty()).isTrue();
94
-        uut.showModal(viewController, new CommandListenerAdapter());
95
-        assertThat(uut.isEmpty()).isFalse();
96
-        uut.dismissAll(new CommandListenerAdapter());
97
-        assertThat(uut.isEmpty()).isTrue();
98
-    }
99
-
100
-    @Test
101
-    public void onDismiss() {
102
-        uut.showModal(viewController, new CommandListenerAdapter());
103
-        uut.showModal(new SimpleViewController(newActivity(), "otherComponent", new Options()), new CommandListenerAdapter());
104
-        uut.dismissAll(new CommandListenerAdapter() {
105
-            @Override
106
-            public void onSuccess(String childId) {
107
-                verify(uut, times(2)).onModalDismiss(any());
108
-            }
109
-        });
110
-    }
111
-
112
-    @Test
113
-    public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
114
-        SimpleViewController viewController = spy(new SimpleViewController(newActivity(), "otherComponent", new Options()));
115
-        uut.showModal(viewController, new CommandListenerAdapter());
116
-        uut.showModal(this.viewController, new CommandListenerAdapter());
117
-        uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
118
-            @Override
119
-            public void onSuccess(String childId) {
120
-                verify(viewController, times(1)).onViewAppeared();
121
-            }
122
-        });
123
-    }
124
-
125
-    private Modal findModal(String id) {
126
-        return uut.findModalByComponentId(id);
127
-    }
128
-}

+ 4
- 0
playground/src/screens/StaticLifecycleOverlay.js View File

@@ -20,6 +20,10 @@ class StaticLifecycleOverlay extends Component {
20 20
         events: [...this.state.events, { event: 'componentDidDisappear', componentId, componentName }]
21 21
       });
22 22
     });
23
+    Navigation.events().onNavigationCommand((name, params) => {
24
+      // console.log('RNN', `name: ${JSON.stringify(name)}`);
25
+      // console.log('RNN', `params: ${JSON.stringify(params)}`);
26
+    });
23 27
   }
24 28
 
25 29
   render() {

+ 1
- 1
scripts/test-e2e.js View File

@@ -17,5 +17,5 @@ function run() {
17 17
   if (!skipBuild) {
18 18
     exec.execSync(`detox build --configuration ${configuration}`);
19 19
   }
20
-  exec.execSync(`detox test --configuration ${configuration} --platform ${platform} ${cleanup}`);
20
+  exec.execSync(`detox test --configuration ${configuration} --platform ${platform} ${cleanup} --loglevel verbose`);
21 21
 }