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
 public class CollapsingTopBarParams {
7
 public class CollapsingTopBarParams {
8
     public @Nullable String imageUri;
8
     public @Nullable String imageUri;
9
     public @Nullable String reactViewId;
9
     public @Nullable String reactViewId;
10
-    public int reactViewHeight;
11
     public StyleParams.Color scrimColor;
10
     public StyleParams.Color scrimColor;
12
     public CollapseBehaviour collapseBehaviour;
11
     public CollapseBehaviour collapseBehaviour;
13
     public boolean expendOnTopTabChange;
12
     public boolean expendOnTopTabChange;

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

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

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

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

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

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
                     params,
78
                     params,
79
                     new NavigationParams(Bundle.EMPTY),
79
                     new NavigationParams(Bundle.EMPTY),
80
                     scrollListener);
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
             header.setOnHiddenListener(new CollapsingTopBarReactHeaderAnimator.OnHiddenListener() {
82
             header.setOnHiddenListener(new CollapsingTopBarReactHeaderAnimator.OnHiddenListener() {
84
                 @Override
83
                 @Override
85
                 public void onHidden() {
84
                 public void onHidden() {

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

38
         listener = scrollListener;
38
         listener = scrollListener;
39
         ViewConfiguration vc = ViewConfiguration.get(context);
39
         ViewConfiguration vc = ViewConfiguration.get(context);
40
         mTouchSlop = vc.getScaledTouchSlop();
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
     public void collapse(float amount) {
58
     public void collapse(float amount) {

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

128
     topBarCollapseOnScroll: originalStyleObject.topBarCollapseOnScroll,
128
     topBarCollapseOnScroll: originalStyleObject.topBarCollapseOnScroll,
129
     collapsingToolBarImage: originalStyleObject.collapsingToolBarImage,
129
     collapsingToolBarImage: originalStyleObject.collapsingToolBarImage,
130
     collapsingToolBarComponent: originalStyleObject.collapsingToolBarComponent,
130
     collapsingToolBarComponent: originalStyleObject.collapsingToolBarComponent,
131
-    collapsingToolBarComponentHeight: originalStyleObject.collapsingToolBarComponentHeight,
132
     collapsingToolBarCollapsedColor: processColor(originalStyleObject.collapsingToolBarCollapsedColor),
131
     collapsingToolBarCollapsedColor: processColor(originalStyleObject.collapsingToolBarCollapsedColor),
133
     expendCollapsingToolBarOnTopTabChange: originalStyleObject.expendCollapsingToolBarOnTopTabChange,
132
     expendCollapsingToolBarOnTopTabChange: originalStyleObject.expendCollapsingToolBarOnTopTabChange,
134
     titleBarHidden: originalStyleObject.navBarHidden,
133
     titleBarHidden: originalStyleObject.navBarHidden,