ソースを参照

Default screen animation (#2120)

* Support showing modals with the default screen push/pop animation

* Set navigation bar color before modal is displayed

* Implement screenAnimationType property

controls animation type of all screens including modals.
Guy Carmeli 7 年 前
コミット
20f6944157
No account linked to committer's email address

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/Modal.java ファイルの表示

@@ -24,6 +24,7 @@ import com.reactnativenavigation.params.TitleBarButtonParams;
24 24
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
25 25
 import com.reactnativenavigation.params.parsers.ModalAnimationFactory;
26 26
 import com.reactnativenavigation.screens.NavigationType;
27
+import com.reactnativenavigation.utils.NavigationBar;
27 28
 import com.reactnativenavigation.utils.StatusBar;
28 29
 
29 30
 import java.util.List;
@@ -115,6 +116,7 @@ class Modal extends Dialog implements DialogInterface.OnDismissListener, ScreenS
115 116
         createContent();
116 117
         setAnimation(screenParams);
117 118
         setStatusBarStyle(screenParams.styleParams);
119
+        setNavigationBarStyle(screenParams.styleParams);
118 120
     }
119 121
 
120 122
     private void setStatusBarStyle(StyleParams styleParams) {
@@ -124,6 +126,10 @@ class Modal extends Dialog implements DialogInterface.OnDismissListener, ScreenS
124 126
         StatusBar.setTextColorScheme(window.getDecorView(), styleParams.statusBarTextColorScheme);
125 127
     }
126 128
 
129
+    private void setNavigationBarStyle(StyleParams styleParams) {
130
+        NavigationBar.setColor(getWindow(), styleParams.navigationBarColor);
131
+    }
132
+
127 133
     public AppCompatActivity getActivity() {
128 134
         return activity;
129 135
     }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java ファイルの表示

@@ -80,6 +80,7 @@ public class StyleParams {
80 80
     }
81 81
 
82 82
     public Orientation orientation;
83
+    public String screenAnimationType;
83 84
     public StatusBarTextColorScheme statusBarTextColorScheme;
84 85
     public Color statusBarColor;
85 86
     public boolean statusBarHidden;

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/ModalAnimationFactory.java ファイルの表示

@@ -11,6 +11,8 @@ public class ModalAnimationFactory {
11 11
                 return R.style.ModalFadeAnimation;
12 12
             case "slide-horizontal":
13 13
                 return R.style.ModalSlideHorizontal;
14
+            case "screen":
15
+                return R.style.ModalScreenAnimations;
14 16
             default:
15 17
                 return R.style.ModalDefaultAnimations;
16 18
         }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java ファイルの表示

@@ -3,6 +3,7 @@ package com.reactnativenavigation.params.parsers;
3 3
 import android.graphics.drawable.Drawable;
4 4
 import android.os.Bundle;
5 5
 
6
+import com.reactnativenavigation.params.AppStyle;
6 7
 import com.reactnativenavigation.params.NavigationParams;
7 8
 import com.reactnativenavigation.params.PageParams;
8 9
 import com.reactnativenavigation.params.ScreenParams;
@@ -55,7 +56,7 @@ public class ScreenParamsParser extends Parser {
55 56
         result.animateScreenTransitions = new AnimationParser(params).parse();
56 57
         result.sharedElementsTransitions = getSharedElementsTransitions(params);
57 58
 
58
-        result.animationType = params.getString(ANIMATION_TYPE, "slide-up");
59
+        result.animationType = params.getString(ANIMATION_TYPE, AppStyle.appStyle.screenAnimationType);
59 60
 
60 61
         return result;
61 62
     }

+ 7
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java ファイルの表示

@@ -28,6 +28,7 @@ public class StyleParamsParser {
28 28
 
29 29
         StyleParams result = new StyleParams(params);
30 30
         result.orientation = Orientation.fromString(params.getString("orientation", getDefaultOrientation()));
31
+        result.screenAnimationType = params.getString("screenAnimationType", getDefaultScreenAnimationType());
31 32
         result.statusBarColor = getColor("statusBarColor", getDefaultStatusBarColor());
32 33
         result.statusBarHidden = getBoolean("statusBarHidden", getDefaultStatusHidden());
33 34
         result.statusBarTextColorScheme = StatusBarTextColorScheme.fromString(params.getString("statusBarTextColorScheme"), getDefaultStatusBarTextColorScheme());
@@ -89,8 +90,7 @@ public class StyleParamsParser {
89 90
         result.bottomTabsHiddenOnScroll = getBoolean("bottomTabsHiddenOnScroll", getDefaultBottomTabsHiddenOnScroll());
90 91
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
91 92
         result.bottomTabsButtonColor = getColor("bottomTabsButtonColor", getDefaultBottomTabsButtonColor());
92
-        result.selectedBottomTabsButtonColor =
93
-                getColor("bottomTabsSelectedButtonColor", getDefaultSelectedBottomTabsButtonColor());
93
+        result.selectedBottomTabsButtonColor = getColor("bottomTabsSelectedButtonColor", getDefaultSelectedBottomTabsButtonColor());
94 94
         result.bottomTabBadgeTextColor = getColor("bottomTabBadgeTextColor", getBottomTabBadgeTextColor());
95 95
         result.bottomTabBadgeBackgroundColor = getColor("bottomTabBadgeBackgroundColor", getBottomTabBadgeBackgroundColor());
96 96
 
@@ -102,6 +102,10 @@ public class StyleParamsParser {
102 102
         return result;
103 103
     }
104 104
 
105
+    private String getDefaultScreenAnimationType() {
106
+        return AppStyle.appStyle == null ? "slide-up" : AppStyle.appStyle.screenAnimationType;
107
+    }
108
+
105 109
     private StatusBarTextColorScheme getDefaultStatusBarTextColorScheme() {
106 110
         return AppStyle.appStyle == null ? StatusBarTextColorScheme.Undefined : AppStyle.appStyle.statusBarTextColorScheme;
107 111
     }
@@ -121,6 +125,7 @@ public class StyleParamsParser {
121 125
         result.titleBarSubtitleFontFamily = new StyleParams.Font();
122 126
         result.titleBarButtonFontFamily = new StyleParams.Font();
123 127
         result.titleBarHeight = -1;
128
+        result.screenAnimationType = "slide-up";
124 129
         return result;
125 130
     }
126 131
 

+ 2
- 13
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java ファイルの表示

@@ -1,13 +1,9 @@
1 1
 package com.reactnativenavigation.screens;
2 2
 
3 3
 import android.animation.LayoutTransition;
4
-import android.annotation.TargetApi;
5 4
 import android.content.res.Configuration;
6
-import android.graphics.Color;
7
-import android.os.Build;
8 5
 import android.os.Bundle;
9 6
 import android.support.v7.app.AppCompatActivity;
10
-import android.view.Window;
11 7
 import android.widget.RelativeLayout;
12 8
 
13 9
 import com.facebook.react.bridge.Callback;
@@ -28,6 +24,7 @@ import com.reactnativenavigation.params.StyleParams;
28 24
 import com.reactnativenavigation.params.TitleBarButtonParams;
29 25
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
30 26
 import com.reactnativenavigation.params.parsers.StyleParamsParser;
27
+import com.reactnativenavigation.utils.NavigationBar;
31 28
 import com.reactnativenavigation.utils.StatusBar;
32 29
 import com.reactnativenavigation.views.ContentView;
33 30
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
@@ -181,16 +178,8 @@ public abstract class Screen extends RelativeLayout implements Subscriber {
181 178
         StatusBar.setTextColorScheme(this, textColorScheme);
182 179
     }
183 180
 
184
-    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
185 181
     public void setNavigationBarColor(StyleParams.Color navigationBarColor) {
186
-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;
187
-
188
-        final Window window = ((NavigationActivity) activity).getScreenWindow();
189
-        if (navigationBarColor.hasColor()) {
190
-            window.setNavigationBarColor(navigationBarColor.getColor());
191
-        } else {
192
-            window.setNavigationBarColor(Color.BLACK);
193
-        }
182
+        NavigationBar.setColor(((NavigationActivity) activity).getScreenWindow(), navigationBarColor);
194 183
     }
195 184
 
196 185
     public abstract void unmountReactView();

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ScreenAnimator.java ファイルの表示

@@ -8,7 +8,6 @@ import android.view.View;
8 8
 import android.view.animation.AccelerateDecelerateInterpolator;
9 9
 import android.view.animation.AccelerateInterpolator;
10 10
 import android.view.animation.DecelerateInterpolator;
11
-import android.view.animation.LinearInterpolator;
12 11
 
13 12
 import com.reactnativenavigation.NavigationApplication;
14 13
 import com.reactnativenavigation.utils.ViewUtils;
@@ -23,7 +22,6 @@ class ScreenAnimator {
23 22
     private static final int DURATION = 250;
24 23
     private static final int ALPHA_START_DELAY = 100;
25 24
     private static final int ALPHA_SHORT_DURATION = 150;
26
-    private static final LinearInterpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
27 25
     private static final DecelerateInterpolator DECELERATE_INTERPOLATOR = new DecelerateInterpolator();
28 26
     private static final AccelerateDecelerateInterpolator ACCELERATE_DECELERATE_INTERPOLATOR = new AccelerateDecelerateInterpolator();
29 27
     private static final AccelerateInterpolator ACCELERATE_INTERPOLATOR = new AccelerateInterpolator();

+ 22
- 0
android/app/src/main/java/com/reactnativenavigation/utils/NavigationBar.java ファイルの表示

@@ -0,0 +1,22 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.annotation.TargetApi;
4
+import android.graphics.Color;
5
+import android.os.Build;
6
+import android.view.Window;
7
+
8
+import com.reactnativenavigation.params.StyleParams;
9
+
10
+
11
+public class NavigationBar {
12
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
13
+    public static void setColor(Window window, StyleParams.Color navigationBarColor) {
14
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP || window == null) return;
15
+//        final Window window = ((NavigationActivity) activity).getScreenWindow();
16
+        if (navigationBarColor.hasColor()) {
17
+            window.setNavigationBarColor(navigationBarColor.getColor());
18
+        } else {
19
+            window.setNavigationBarColor(Color.BLACK);
20
+        }
21
+    }
22
+}

+ 14
- 0
android/app/src/main/res/anim/pop.xml ファイルの表示

@@ -0,0 +1,14 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<set xmlns:android="http://schemas.android.com/apk/res/android"
3
+     android:interpolator="@android:anim/accelerate_interpolator"
4
+     android:shareInterpolator="true">
5
+    <translate
6
+        android:duration="250"
7
+        android:fromYDelta="0%"
8
+        android:toYDelta="8%"/>
9
+    <alpha
10
+        android:startOffset="100"
11
+        android:duration="150"
12
+        android:fromAlpha="1"
13
+        android:toAlpha="0"/>
14
+</set>

+ 4
- 0
android/app/src/main/res/values/styles.xml ファイルの表示

@@ -26,4 +26,8 @@
26 26
     <style name="ModalSlideHorizontal">
27 27
         <item name="android:windowExitAnimation">@anim/slide_out_right</item>
28 28
     </style>
29
+
30
+    <style name="ModalScreenAnimations">
31
+        <item name="android:windowExitAnimation">@anim/pop</item>
32
+    </style>
29 33
 </resources>

+ 1
- 0
src/deprecated/platformSpecificDeprecated.android.js ファイルの表示

@@ -138,6 +138,7 @@ function convertStyleParams(originalStyleObject) {
138 138
 
139 139
   let ret = {
140 140
     orientation: originalStyleObject.orientation,
141
+    screenAnimationType: originalStyleObject.screenAnimationType,
141 142
     statusBarColor: processColor(originalStyleObject.statusBarColor),
142 143
     statusBarHidden: originalStyleObject.statusBarHidden,
143 144
     statusBarTextColorScheme: originalStyleObject.statusBarTextColorScheme,