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
     private final Animator animator;
17
     private final Animator animator;
18
 
18
 
19
     public PeekingAnimator(View view, Position position, final boolean show) {
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
         this.animator = show ?
22
         this.animator = show ?
23
                 createSlideInAnimator(view, offsetPixels) :
23
                 createSlideInAnimator(view, offsetPixels) :

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

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
 import com.reactnativenavigation.screens.Screen;
11
 import com.reactnativenavigation.screens.Screen;
12
 import com.reactnativenavigation.utils.ViewUtils;
12
 import com.reactnativenavigation.utils.ViewUtils;
13
 import com.reactnativenavigation.views.ContentView;
13
 import com.reactnativenavigation.views.ContentView;
14
+import com.reactnativenavigation.views.utils.ViewMeasurer;
14
 
15
 
15
 public class SlidingOverlay {
16
 public class SlidingOverlay {
16
 
17
 
47
         view = createSlidingOverlayView(params);
48
         view = createSlidingOverlayView(params);
48
         parent.addView(view);
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
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
51
         view.setOnDisplayListener(new Screen.OnDisplayListener() {
63
             @Override
52
             @Override
64
             public void onDisplay() {
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
                 view.setVisibility(View.VISIBLE);
67
                 view.setVisibility(View.VISIBLE);
66
                 visibilityState = VisibilityState.AnimateShow;
68
                 visibilityState = VisibilityState.AnimateShow;
67
                 animator.animate();
69
                 animator.animate();
106
     }
108
     }
107
 
109
 
108
     protected ContentView createSlidingOverlayView(SlidingOverlayParams params) {
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
         lp.addRule(params.position == Position.Top ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.ALIGN_PARENT_BOTTOM);
112
         lp.addRule(params.position == Position.Top ? RelativeLayout.ALIGN_PARENT_TOP : RelativeLayout.ALIGN_PARENT_BOTTOM);
113
 
113
 
114
         final ContentView view = new ContentView(parent.getContext(), params.screenInstanceId, params.navigationParams);
114
         final ContentView view = new ContentView(parent.getContext(), params.screenInstanceId, params.navigationParams);
115
+        view.setViewMeasurer(new OverlayViewMeasurer(view));
115
         view.setLayoutParams(lp);
116
         view.setLayoutParams(lp);
116
         view.setVisibility(View.INVISIBLE);
117
         view.setVisibility(View.INVISIBLE);
117
         return view;
118
         return view;

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

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