Browse Source

Start app (#2927)

* WIP

* Apply default options when screen options are null

* modal animations

* fix tests

* refactor

* refactor

* refactor

* refactor

* test fix

* topBar anim

* child disappear bug

* Update app.js

* Update WelcomeScreen.js

* fix tests

* bottom tabs

* stack id

* fix test

* refactoring

* merge fix

* Update app.js

* merge

* comment to fix test

* merge options

* start app anim

* anim
Roman Kozlov 6 years ago
parent
commit
16415b2213

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/anim/BaseAnimator.java View File

@@ -15,7 +15,7 @@ import com.reactnativenavigation.utils.UiUtils;
15 15
 
16 16
 class BaseAnimator {
17 17
 
18
-    AnimationsOptions options = new AnimationsOptions();
18
+    protected AnimationsOptions options = new AnimationsOptions();
19 19
 
20 20
     private static final int DURATION = 300;
21 21
     private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();

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

@@ -16,6 +16,11 @@ public class NavigationAnimator extends BaseAnimator {
16 16
         super(context);
17 17
     }
18 18
 
19
+    public NavigationAnimator(Context context, AnimationsOptions options) {
20
+        super(context);
21
+        this.options = options;
22
+    }
23
+
19 24
     public void animatePush(final View view, @Nullable final AnimationListener animationListener) {
20 25
         view.setVisibility(View.INVISIBLE);
21 26
         AnimatorSet set;
@@ -58,6 +63,23 @@ public class NavigationAnimator extends BaseAnimator {
58 63
         set.start();
59 64
     }
60 65
 
66
+    public void animateStartApp(View view, @Nullable final AnimationListener animationListener) {
67
+        view.setVisibility(View.INVISIBLE);
68
+        AnimatorSet set = options.startApp.getAnimation(view);
69
+        set.addListener(new AnimatorListenerAdapter() {
70
+            @Override
71
+            public void onAnimationStart(Animator animation) {
72
+                view.setVisibility(View.VISIBLE);
73
+            }
74
+
75
+            @Override
76
+            public void onAnimationEnd(Animator animation) {
77
+                if (animationListener != null) animationListener.onAnimationEnd();
78
+            }
79
+        });
80
+        set.start();
81
+    }
82
+
61 83
     public void setOptions(AnimationsOptions options) {
62 84
         this.options = options;
63 85
     }

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

@@ -3,10 +3,13 @@ package com.reactnativenavigation.viewcontrollers;
3 3
 import android.app.Activity;
4 4
 import android.support.annotation.NonNull;
5 5
 import android.support.annotation.Nullable;
6
+import android.view.View;
6 7
 import android.view.ViewGroup;
7 8
 import android.widget.FrameLayout;
8 9
 
9 10
 import com.facebook.react.bridge.Promise;
11
+import com.reactnativenavigation.anim.NavigationAnimator;
12
+import com.reactnativenavigation.parse.AnimationsOptions;
10 13
 import com.reactnativenavigation.parse.Options;
11 14
 import com.reactnativenavigation.presentation.NavigationOptionsListener;
12 15
 import com.reactnativenavigation.presentation.OverlayManager;
@@ -66,8 +69,17 @@ public class Navigator extends ParentController implements ModalListener {
66 69
         }
67 70
 
68 71
         root = viewController;
69
-        getView().addView(viewController.getView());
70
-        promise.resolve(viewController.getId());
72
+        View view = viewController.getView();
73
+
74
+        AnimationsOptions animationsOptions = viewController.options.animationsOptions;
75
+        if (animationsOptions.startApp.hasValue()) {
76
+            getView().addView(view);
77
+            new NavigationAnimator(viewController.getActivity(), animationsOptions)
78
+                    .animateStartApp(view, () -> promise.resolve(viewController.getId()));
79
+        } else {
80
+            getView().addView(view);
81
+            promise.resolve(viewController.getId());
82
+        }
71 83
     }
72 84
 
73 85
     public void setDefaultOptions(Options defaultOptions) {

+ 0
- 1
playground/android/gradle.properties View File

@@ -21,4 +21,3 @@ android.useDeprecatedNdk=false
21 21
 # Disable incremental resource processing as it broke relase build
22 22
 # https://github.com/react-community/react-navigation/issues/1976
23 23
 # https://developer.android.com/studio/build/gradle-plugin-3-0-0.html
24
-android.enableAapt2=false

+ 14
- 0
playground/src/app.js View File

@@ -25,6 +25,20 @@ function start() {
25 25
   Navigation.events().onAppLaunched(() => {
26 26
     Navigation.setDefaultOptions({
27 27
       _animations: {
28
+        startApp: {
29
+          y: {
30
+            from: 1000,
31
+            to: 0,
32
+            duration: 500,
33
+            interpolation: 'accelerate',
34
+          },
35
+          alpha: {
36
+            from: 0,
37
+            to: 1,
38
+            duration: 500,
39
+            interpolation: 'accelerate'
40
+          }
41
+        },
28 42
         push: {
29 43
           topBar: {
30 44
             id: 'TEST',