Browse Source

Bottom anim (#2906)

* 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
Roman Kozlov 6 years ago
parent
commit
c1a6a4c315

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

@@ -0,0 +1,49 @@
1
+package com.reactnativenavigation.anim;
2
+
3
+
4
+import android.animation.Animator;
5
+import android.animation.AnimatorListenerAdapter;
6
+import android.animation.AnimatorSet;
7
+
8
+import com.reactnativenavigation.parse.AnimationsOptions;
9
+import com.reactnativenavigation.views.BottomTabs;
10
+
11
+public class BottomTabsAnimator {
12
+
13
+    private BottomTabs bottomTabs;
14
+
15
+    public BottomTabsAnimator(BottomTabs bottomTabs) {
16
+        this.bottomTabs = bottomTabs;
17
+    }
18
+
19
+    public void hide(AnimationsOptions animationsOptions) {
20
+        if (animationsOptions.pop.bottomTabs.hasValue()) {
21
+            AnimatorSet set = animationsOptions.pop.bottomTabs.getAnimation(bottomTabs);
22
+            set.addListener(new AnimatorListenerAdapter() {
23
+                @Override
24
+                public void onAnimationEnd(Animator animation) {
25
+                    bottomTabs.hideBottomNavigation(false);
26
+                }
27
+            });
28
+            set.start();
29
+        } else {
30
+            bottomTabs.hideBottomNavigation();
31
+        }
32
+    }
33
+
34
+    public void show(AnimationsOptions animationsOptions) {
35
+        if (animationsOptions.push.bottomTabs.hasValue()) {
36
+            AnimatorSet set = animationsOptions.push.bottomTabs.getAnimation(bottomTabs);
37
+            set.addListener(new AnimatorListenerAdapter() {
38
+                @Override
39
+                public void onAnimationEnd(Animator animation) {
40
+                    bottomTabs.restoreBottomNavigation(false);
41
+                }
42
+            });
43
+            set.start();
44
+        } else {
45
+            bottomTabs.restoreBottomNavigation();
46
+        }
47
+    }
48
+
49
+}

+ 17
- 4
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabsOptionsPresenter.java View File

@@ -1,5 +1,7 @@
1 1
 package com.reactnativenavigation.presentation;
2 2
 
3
+import com.reactnativenavigation.anim.BottomTabsAnimator;
4
+import com.reactnativenavigation.parse.AnimationsOptions;
3 5
 import com.reactnativenavigation.parse.BottomTabOptions;
4 6
 import com.reactnativenavigation.parse.BottomTabsOptions;
5 7
 import com.reactnativenavigation.parse.Options;
@@ -9,14 +11,16 @@ import com.reactnativenavigation.views.BottomTabs;
9 11
 public class BottomTabsOptionsPresenter {
10 12
     private BottomTabs bottomTabs;
11 13
     private BottomTabFinder bottomTabFinder;
14
+    private BottomTabsAnimator animator;
12 15
 
13 16
     public BottomTabsOptionsPresenter(BottomTabs bottomTabs, BottomTabFinder bottomTabFinder) {
14 17
         this.bottomTabs = bottomTabs;
15 18
         this.bottomTabFinder = bottomTabFinder;
19
+        animator = new BottomTabsAnimator(bottomTabs);
16 20
     }
17 21
 
18 22
     public void present(Options options) {
19
-        applyBottomTabsOptions(options.bottomTabsOptions);
23
+        applyBottomTabsOptions(options.bottomTabsOptions, options.animationsOptions);
20 24
     }
21 25
 
22 26
     public void present(Options options, int tabIndex) {
@@ -29,7 +33,7 @@ public class BottomTabsOptionsPresenter {
29 33
         }
30 34
     }
31 35
 
32
-    private void applyBottomTabsOptions(BottomTabsOptions options) {
36
+    private void applyBottomTabsOptions(BottomTabsOptions options, AnimationsOptions animationsOptions) {
33 37
         if (options.backgroundColor.hasValue()) {
34 38
             bottomTabs.setBackgroundColor(options.backgroundColor.get());
35 39
         }
@@ -50,10 +54,19 @@ public class BottomTabsOptionsPresenter {
50 54
             if (tabIndex >= 0) bottomTabs.setCurrentItem(tabIndex);
51 55
         }
52 56
         if (options.visible.isTrueOrUndefined()) {
53
-            bottomTabs.restoreBottomNavigation(options.animate.isTrueOrUndefined());
57
+            if (options.animate.isTrueOrUndefined()) {
58
+                animator.show(animationsOptions);
59
+            } else {
60
+                bottomTabs.restoreBottomNavigation(false);
61
+            }
54 62
         }
55 63
         if (options.visible.isFalse()) {
56
-            bottomTabs.hideBottomNavigation(options.animate.isTrueOrUndefined());
64
+            if (options.animate.isTrueOrUndefined()) {
65
+                animator.hide(animationsOptions);
66
+            } else {
67
+                bottomTabs.hideBottomNavigation(false);
68
+            }
57 69
         }
58 70
     }
71
+
59 72
 }

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

@@ -40,6 +40,20 @@ function start() {
40 40
               interpolation: 'accelerate'
41 41
             }
42 42
           },
43
+          bottomTabs: {
44
+            y: {
45
+              from: 1000,
46
+              to: 0,
47
+              duration: 500,
48
+              interpolation: 'decelerate',
49
+            },
50
+            alpha: {
51
+              from: 0,
52
+              to: 1,
53
+              duration: 500,
54
+              interpolation: 'decelerate'
55
+            }
56
+          },
43 57
           content: {
44 58
             y: {
45 59
               from: 1000,
@@ -57,6 +71,20 @@ function start() {
57 71
         },
58 72
         pop: {
59 73
           topBar: {
74
+            y: {
75
+              from: 0,
76
+              to: 100,
77
+              duration: 500,
78
+              interpolation: 'accelerate',
79
+            },
80
+            alpha: {
81
+              from: 1,
82
+              to: 0,
83
+              duration: 500,
84
+              interpolation: 'accelerate'
85
+            }
86
+          },
87
+          bottomTabs: {
60 88
             y: {
61 89
               from: 0,
62 90
               to: 100,

+ 2
- 1
playground/src/screens/TextScreen.js View File

@@ -88,7 +88,8 @@ class TextScreen extends Component {
88 88
   hideTabBar(visible) {
89 89
     Navigation.setOptions(this.props.componentId, {
90 90
       bottomTabs: {
91
-        visible
91
+        visible,
92
+        animate: true
92 93
       }
93 94
     });
94 95
   }