Browse Source

Handle fling in collapsing header with image view (#1293)

fixes #1284 #1248
Guy Carmeli 7 years ago
parent
commit
5308c25ea9

+ 9
- 2
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBar.java View File

@@ -3,6 +3,7 @@ package com.reactnativenavigation.views.collapsingToolbar;
3 3
 import android.content.Context;
4 4
 import android.content.res.TypedArray;
5 5
 import android.os.Bundle;
6
+import android.support.annotation.Nullable;
6 7
 import android.view.View;
7 8
 import android.view.ViewGroup;
8 9
 import android.widget.ScrollView;
@@ -20,7 +21,7 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
20 21
 
21 22
 public class CollapsingTopBar extends TopBar implements CollapsingView {
22 23
     private CollapsingTopBarBackground collapsingTopBarBackground;
23
-    private CollapsingTopBarReactHeader header;
24
+    private @Nullable CollapsingTopBarReactHeader header;
24 25
     private ScrollListener scrollListener;
25 26
     private float finalCollapsedTranslation;
26 27
     private final StyleParams styleParams;
@@ -31,6 +32,7 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
31 32
     @Override
32 33
     public void destroy() {
33 34
         if (params.hasReactView()) {
35
+            assert header != null;
34 36
             header.unmountReactView();
35 37
         }
36 38
     }
@@ -83,6 +85,7 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
83 85
                         @Override
84 86
                         public void onDisplay() {
85 87
                             calculateFinalCollapsedTranslation();
88
+                            assert header != null;
86 89
                             header.setOnDisplayListener(null);
87 90
                         }
88 91
                     });
@@ -141,7 +144,11 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
141 144
     @Override
142 145
     public void fling(CollapseAmount amount) {
143 146
         if (titleBar instanceof CollapsingTitleBar) {
144
-            viewCollapser.fling(amount, (CollapsingTitleBar) titleBar, header);
147
+            if (header != null) {
148
+                viewCollapser.fling(amount, (CollapsingTitleBar) titleBar, header);
149
+            } else {
150
+                viewCollapser.fling(amount, (CollapsingTitleBar) titleBar);
151
+            }
145 152
         } else {
146 153
             viewCollapser.collapse(amount);
147 154
         }

+ 10
- 1
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/ViewCollapser.java View File

@@ -68,7 +68,7 @@ public class ViewCollapser {
68 68
         animator.start();
69 69
     }
70 70
 
71
-    void fling(final CollapseAmount amount, final CollapsingTitleBar titleBar, final CollapsingTopBarReactHeader header) {
71
+    void fling(final CollapseAmount amount, final CollapsingTitleBar titleBar, @NonNull final CollapsingTopBarReactHeader header) {
72 72
         fling(amount, new ValueAnimator.AnimatorUpdateListener() {
73 73
             @Override
74 74
             public void onAnimationUpdate(ValueAnimator animation) {
@@ -78,6 +78,15 @@ public class ViewCollapser {
78 78
         });
79 79
     }
80 80
 
81
+    void fling(final CollapseAmount amount, final CollapsingTitleBar titleBar) {
82
+        fling(amount, new ValueAnimator.AnimatorUpdateListener() {
83
+            @Override
84
+            public void onAnimationUpdate(ValueAnimator animation) {
85
+                titleBar.collapse(new CollapseAmount((Float) animation.getAnimatedValue()));
86
+            }
87
+        });
88
+    }
89
+
81 90
     public void fling(CollapseAmount amount) {
82 91
         fling(amount, LISTENER);
83 92
     }