Browse Source

Dynamic height for CollapsingReactHeader (#726)

This commit deprecates collapsingToolBarComponentHeight style property
Guy Carmeli 7 years ago
parent
commit
326f4833f0

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/params/CollapsingTopBarParams.java View File

@@ -7,7 +7,6 @@ import com.reactnativenavigation.views.collapsingToolbar.behaviours.CollapseBeha
7 7
 public class CollapsingTopBarParams {
8 8
     public @Nullable String imageUri;
9 9
     public @Nullable String reactViewId;
10
-    public int reactViewHeight;
11 10
     public StyleParams.Color scrimColor;
12 11
     public CollapseBehaviour collapseBehaviour;
13 12
     public boolean expendOnTopTabChange;

+ 0
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/CollapsingTopBarParamsParser.java View File

@@ -32,7 +32,6 @@ class CollapsingTopBarParamsParser extends Parser {
32 32
         CollapsingTopBarParams result = new CollapsingTopBarParams();
33 33
         result.imageUri = params.getString("collapsingToolBarImage", null);
34 34
         result.reactViewId = params.getString("collapsingToolBarComponent", null);
35
-        result.reactViewHeight = params.getInt("collapsingToolBarComponentHeight");
36 35
         result.expendOnTopTabChange = params.getBoolean("expendCollapsingToolBarOnTopTabChange");
37 36
         result.scrimColor = getColor(params, "collapsingToolBarCollapsedColor", new StyleParams.Color(Color.WHITE));
38 37
         result.showTitleWhenCollapsed = hasReactView;

+ 1
- 2
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java View File

@@ -50,9 +50,8 @@ public class ContentView extends ReactRootView {
50 50
     @Override
51 51
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
52 52
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
53
-        int measuredHeight = viewMeasurer.getMeasuredHeight(heightMeasureSpec);
54 53
         setMeasuredDimension(viewMeasurer.getMeasuredWidth(widthMeasureSpec),
55
-                measuredHeight);
54
+                viewMeasurer.getMeasuredHeight(heightMeasureSpec));
56 55
     }
57 56
 
58 57
     @Override

+ 22
- 0
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingReactHeaderMeasurer.java View File

@@ -0,0 +1,22 @@
1
+package com.reactnativenavigation.views.collapsingToolbar;
2
+
3
+import android.view.ViewGroup;
4
+
5
+import com.reactnativenavigation.views.utils.ViewMeasurer;
6
+
7
+class CollapsingReactHeaderMeasurer extends ViewMeasurer {
8
+    private ViewGroup header;
9
+
10
+    CollapsingReactHeaderMeasurer(ViewGroup header) {
11
+        this.header = header;
12
+    }
13
+
14
+    @Override
15
+    public int getMeasuredHeight(int heightMeasureSpec) {
16
+        return hasChildren() ? header.getChildAt(0).getMeasuredHeight() : super.getMeasuredHeight(heightMeasureSpec);
17
+    }
18
+
19
+    private boolean hasChildren() {
20
+        return header.getChildCount() > 0;
21
+    }
22
+}

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

@@ -78,8 +78,7 @@ public class CollapsingTopBar extends TopBar implements CollapsingView {
78 78
                     params,
79 79
                     new NavigationParams(Bundle.EMPTY),
80 80
                     scrollListener);
81
-            LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, (int) ViewUtils.convertDpToPixel(params.reactViewHeight));
82
-            titleBarAndContextualMenuContainer.addView(header, lp);
81
+            titleBarAndContextualMenuContainer.addView(header, new LayoutParams(MATCH_PARENT, WRAP_CONTENT));
83 82
             header.setOnHiddenListener(new CollapsingTopBarReactHeaderAnimator.OnHiddenListener() {
84 83
                 @Override
85 84
                 public void onHidden() {

+ 13
- 6
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTopBarReactHeader.java View File

@@ -38,14 +38,21 @@ public class CollapsingTopBarReactHeader extends ContentView implements Collapsi
38 38
         listener = scrollListener;
39 39
         ViewConfiguration vc = ViewConfiguration.get(context);
40 40
         mTouchSlop = vc.getScaledTouchSlop();
41
-        createVisibilityAnimator(params.reactViewHeight);
41
+        setViewMeasurer(new CollapsingReactHeaderMeasurer(this));
42
+        createVisibilityAnimator(getHeight());
42 43
     }
43 44
 
44
-    private void createVisibilityAnimator(int reactViewHeight) {
45
-        float height = ViewUtils.convertDpToPixel(reactViewHeight);
46
-        visibilityAnimator = new CollapsingTopBarReactHeaderAnimator(this, height * 0.6f, height * 0.60f);
47
-        visibilityAnimator.setOnHiddenListener(this);
48
-        visibilityAnimator.setOnVisibleListener(this);
45
+    private void createVisibilityAnimator(final int reactViewHeight) {
46
+        ViewUtils.runOnPreDraw(this, new Runnable() {
47
+            @Override
48
+            public void run() {
49
+                final CollapsingTopBarReactHeader header = CollapsingTopBarReactHeader.this;
50
+                float height = ViewUtils.convertDpToPixel(reactViewHeight);
51
+                visibilityAnimator = new CollapsingTopBarReactHeaderAnimator(header, height * 0.6f, height * 0.60f);
52
+                visibilityAnimator.setOnHiddenListener(header);
53
+                visibilityAnimator.setOnVisibleListener(header);
54
+            }
55
+        });
49 56
     }
50 57
 
51 58
     public void collapse(float amount) {

+ 0
- 1
src/deprecated/platformSpecificDeprecated.android.js View File

@@ -128,7 +128,6 @@ function convertStyleParams(originalStyleObject) {
128 128
     topBarCollapseOnScroll: originalStyleObject.topBarCollapseOnScroll,
129 129
     collapsingToolBarImage: originalStyleObject.collapsingToolBarImage,
130 130
     collapsingToolBarComponent: originalStyleObject.collapsingToolBarComponent,
131
-    collapsingToolBarComponentHeight: originalStyleObject.collapsingToolBarComponentHeight,
132 131
     collapsingToolBarCollapsedColor: processColor(originalStyleObject.collapsingToolBarCollapsedColor),
133 132
     expendCollapsingToolBarOnTopTabChange: originalStyleObject.expendCollapsingToolBarOnTopTabChange,
134 133
     titleBarHidden: originalStyleObject.navBarHidden,