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

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

68
         animator.start();
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
         fling(amount, new ValueAnimator.AnimatorUpdateListener() {
72
         fling(amount, new ValueAnimator.AnimatorUpdateListener() {
73
             @Override
73
             @Override
74
             public void onAnimationUpdate(ValueAnimator animation) {
74
             public void onAnimationUpdate(ValueAnimator animation) {
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
     public void fling(CollapseAmount amount) {
90
     public void fling(CollapseAmount amount) {
82
         fling(amount, LISTENER);
91
         fling(amount, LISTENER);
83
     }
92
     }