Browse Source

Detect height of notification. (#710)

Royce Townsend 7 years ago
parent
commit
f0ee6cfa8e

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/animation/PeekingAnimator.java View File

@@ -17,7 +17,7 @@ public class PeekingAnimator {
17 17
     private final Animator animator;
18 18
 
19 19
     public PeekingAnimator(View view, Position position, final boolean show) {
20
-        final int offsetPixels = view.getLayoutParams().height * (position == Position.Top ? -1 : 1);
20
+        final int offsetPixels = view.getHeight() * (position == Position.Top ? -1 : 1);
21 21
 
22 22
         this.animator = show ?
23 23
                 createSlideInAnimator(view, offsetPixels) :

+ 24
- 0
android/app/src/main/java/com/reactnativenavigation/views/slidingOverlay/OverlayViewMeasurer.java View File

@@ -0,0 +1,24 @@
1
+package com.reactnativenavigation.views.slidingOverlay;
2
+
3
+import android.view.View;
4
+
5
+import com.reactnativenavigation.views.ContentView;
6
+import com.reactnativenavigation.views.utils.ViewMeasurer;
7
+
8
+public class OverlayViewMeasurer extends ViewMeasurer {
9
+    private final ContentView view;
10
+
11
+    public OverlayViewMeasurer(ContentView view) {
12
+        this.view = view;
13
+    }
14
+
15
+    @Override
16
+    public int getMeasuredHeight(int heightMeasureSpec) {
17
+        View view = this.view.getChildAt(0);
18
+        if (view != null) {
19
+            return view.getMeasuredHeight();
20
+        }
21
+
22
+        return super.getMeasuredHeight(heightMeasureSpec);
23
+    }
24
+}

+ 16
- 15
android/app/src/main/java/com/reactnativenavigation/views/slidingOverlay/SlidingOverlay.java View File

@@ -11,6 +11,7 @@ import com.reactnativenavigation.params.SlidingOverlayParams.Position;
11 11
 import com.reactnativenavigation.screens.Screen;
12 12
 import com.reactnativenavigation.utils.ViewUtils;
13 13
 import com.reactnativenavigation.views.ContentView;
14
+import com.reactnativenavigation.views.utils.ViewMeasurer;
14 15
 
15 16
 public class SlidingOverlay {
16 17
 
@@ -47,21 +48,22 @@ public class SlidingOverlay {
47 48
         view = createSlidingOverlayView(params);
48 49
         parent.addView(view);
49 50
 
50
-        final PeekingAnimator animator = new PeekingAnimator(view, params.position, true);
51
-        animator.addListener(new AnimatorListenerAdapter() {
52
-            @Override
53
-            public void onAnimationCancel(Animator animator) {
54
-                onSlidingOverlayShown(view);
55
-            }
56
-
57
-            @Override
58
-            public void onAnimationEnd(Animator animator) {
59
-                onSlidingOverlayShown(view);
60
-            }
61
-        });
62 51
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
63 52
             @Override
64 53
             public void onDisplay() {
54
+                final PeekingAnimator animator = new PeekingAnimator(view, params.position, true);
55
+                animator.addListener(new AnimatorListenerAdapter() {
56
+                    @Override
57
+                    public void onAnimationCancel(Animator animator) {
58
+                        onSlidingOverlayShown(view);
59
+                    }
60
+
61
+                    @Override
62
+                    public void onAnimationEnd(Animator animator) {
63
+                        onSlidingOverlayShown(view);
64
+                    }
65
+                });
66
+
65 67
                 view.setVisibility(View.VISIBLE);
66 68
                 visibilityState = VisibilityState.AnimateShow;
67 69
                 animator.animate();
@@ -106,12 +108,11 @@ public class SlidingOverlay {
106 108
     }
107 109
 
108 110
     protected ContentView createSlidingOverlayView(SlidingOverlayParams params) {
109
-        final float heightPixels = ViewUtils.convertDpToPixel(100);
110
-
111
-        final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, (int) heightPixels);
111
+        final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
112 112
         lp.addRule(params.position == Position.Top ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.ALIGN_PARENT_BOTTOM);
113 113
 
114 114
         final ContentView view = new ContentView(parent.getContext(), params.screenInstanceId, params.navigationParams);
115
+        view.setViewMeasurer(new OverlayViewMeasurer(view));
115 116
         view.setLayoutParams(lp);
116 117
         view.setVisibility(View.INVISIBLE);
117 118
         return view;

+ 1
- 5
example/src/screens/InAppNotification.js View File

@@ -9,14 +9,10 @@ import {
9 9
 
10 10
 const styleSheet = StyleSheet.create({
11 11
   container: {
12
-    flex: 1,
12
+    height: 120,
13 13
     backgroundColor: 'white',
14 14
     alignItems: 'center',
15 15
     justifyContent: 'center',
16
-    marginLeft: 10,
17
-    marginRight: 10,
18
-    marginTop: 18,
19
-    marginBottom: 18
20 16
   }
21 17
 });
22 18