Pārlūkot izejas kodu

Add showInAppNotification position param support for Android (#693)

Royce Townsend 7 gadus atpakaļ
vecāks
revīzija
d71795b938

+ 11
- 8
android/app/src/main/java/com/reactnativenavigation/animation/PeekingAnimator.java Parādīt failu

@@ -5,6 +5,8 @@ import android.animation.ObjectAnimator;
5 5
 import android.view.View;
6 6
 import android.view.animation.OvershootInterpolator;
7 7
 
8
+import com.reactnativenavigation.params.SlidingOverlayParams.Position;
9
+
8 10
 import static android.view.View.TRANSLATION_Y;
9 11
 
10 12
 public class PeekingAnimator {
@@ -14,12 +16,12 @@ public class PeekingAnimator {
14 16
 
15 17
     private final Animator animator;
16 18
 
17
-    public PeekingAnimator(View view, final boolean show) {
18
-        final int heightPixels = view.getLayoutParams().height;
19
+    public PeekingAnimator(View view, Position position, final boolean show) {
20
+        final int offsetPixels = view.getLayoutParams().height * (position == Position.Top ? -1 : 1);
19 21
 
20 22
         this.animator = show ?
21
-                createSlideInAnimator(view, heightPixels) :
22
-                createSlideOutAnimator(view, heightPixels);
23
+                createSlideInAnimator(view, offsetPixels) :
24
+                createSlideOutAnimator(view, offsetPixels);
23 25
     }
24 26
 
25 27
     public void addListener(Animator.AnimatorListener listener) {
@@ -30,8 +32,9 @@ public class PeekingAnimator {
30 32
         animator.start();
31 33
     }
32 34
 
33
-    private ObjectAnimator createSlideInAnimator(View view, int heightPixels) {
34
-        view.setTranslationY(-heightPixels);
35
+    private ObjectAnimator createSlideInAnimator(View view, int offset) {
36
+
37
+        view.setTranslationY(offset);
35 38
 
36 39
         ObjectAnimator slideIn = ObjectAnimator.ofFloat(view, TRANSLATION_Y, 0);
37 40
         slideIn.setDuration(SLIDE_IN_DURATION);
@@ -39,8 +42,8 @@ public class PeekingAnimator {
39 42
         return slideIn;
40 43
     }
41 44
 
42
-    private ObjectAnimator createSlideOutAnimator(View view, int heightPixels) {
43
-        ObjectAnimator slideOut = ObjectAnimator.ofFloat(view, TRANSLATION_Y, -heightPixels);
45
+    private ObjectAnimator createSlideOutAnimator(View view, int offset) {
46
+        ObjectAnimator slideOut = ObjectAnimator.ofFloat(view, TRANSLATION_Y, offset);
44 47
         slideOut.setDuration(SLIDE_OUT_DURATION);
45 48
         return slideOut;
46 49
     }

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/params/SlidingOverlayParams.java Parādīt failu

@@ -1,6 +1,21 @@
1 1
 package com.reactnativenavigation.params;
2 2
 
3 3
 public class SlidingOverlayParams {
4
+    public enum Position {
5
+        Top, Bottom;
6
+
7
+        public static Position fromString(String string) {
8
+            switch(string) {
9
+                case "bottom":
10
+                    return Position.Bottom;
11
+                case "top":
12
+                default:
13
+                    return Position.Top;
14
+            }
15
+        }
16
+    }
17
+
4 18
     public String screenInstanceId;
5 19
     public NavigationParams navigationParams;
20
+    public Position position;
6 21
 }

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/SlidingOverlayParamsParser.java Parādīt failu

@@ -11,6 +11,7 @@ public class SlidingOverlayParamsParser extends Parser {
11 11
         final SlidingOverlayParams result = new SlidingOverlayParams();
12 12
         result.screenInstanceId = bundle.getString("screen");
13 13
         result.navigationParams = new NavigationParams(bundle.getBundle("navigationParams"));
14
+        result.position = SlidingOverlayParams.Position.fromString(bundle.getString("position", "top"));
14 15
         return result;
15 16
     }
16 17
 }

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/views/slidingOverlay/SlidingOverlay.java Parādīt failu

@@ -7,6 +7,7 @@ import android.widget.RelativeLayout;
7 7
 
8 8
 import com.reactnativenavigation.animation.PeekingAnimator;
9 9
 import com.reactnativenavigation.params.SlidingOverlayParams;
10
+import com.reactnativenavigation.params.SlidingOverlayParams.Position;
10 11
 import com.reactnativenavigation.screens.Screen;
11 12
 import com.reactnativenavigation.utils.ViewUtils;
12 13
 import com.reactnativenavigation.views.ContentView;
@@ -42,7 +43,7 @@ public class SlidingOverlay {
42 43
     public void show() {
43 44
         parent.addView(view);
44 45
 
45
-        final PeekingAnimator animator = new PeekingAnimator(view, true);
46
+        final PeekingAnimator animator = new PeekingAnimator(view, params.position, true);
46 47
         animator.addListener(new AnimatorListenerAdapter() {
47 48
             @Override
48 49
             public void onAnimationCancel(Animator animator) {
@@ -65,7 +66,7 @@ public class SlidingOverlay {
65 66
     }
66 67
 
67 68
     public void hide() {
68
-        final PeekingAnimator animator = new PeekingAnimator(view, false);
69
+        final PeekingAnimator animator = new PeekingAnimator(view, params.position, false);
69 70
         animator.addListener(new AnimatorListenerAdapter() {
70 71
             @Override
71 72
             public void onAnimationCancel(Animator animator) {
@@ -98,7 +99,7 @@ public class SlidingOverlay {
98 99
         final float heightPixels = ViewUtils.convertDpToPixel(100);
99 100
 
100 101
         final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) heightPixels);
101
-        lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
102
+        lp.addRule(params.position == Position.Top ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.ALIGN_PARENT_BOTTOM);
102 103
 
103 104
         final ContentView view = new ContentView(parent.getContext(), params.screenInstanceId, params.navigationParams);
104 105
         view.setLayoutParams(lp);

+ 2
- 1
example/src/screens/SideMenu.js Parādīt failu

@@ -53,7 +53,8 @@ export default class SideMenu extends Component {
53 53
   onShowInAppNotification() {
54 54
     this._toggleDrawer();
55 55
     this.props.navigator.showInAppNotification({
56
-      screen: "example.InAppNotification"
56
+      screen: "example.InAppNotification",
57
+      //position: "bottom",
57 58
     });
58 59
   }
59 60