Ver código fonte

Fix misaligned text in CollapsingTextView (#1418)

Guy Carmeli 7 anos atrás
pai
commit
66bc1ef7a0

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java Ver arquivo

@@ -173,7 +173,7 @@ public class ViewUtils {
173 173
         return new Point(xy[0], xy[1]);
174 174
     }
175 175
 
176
-    private static int getStatusBarHeight() {
176
+    public static int getStatusBarHeight() {
177 177
         if (statusBarHeight > 0) {
178 178
             return statusBarHeight;
179 179
         }

+ 6
- 4
android/app/src/main/java/com/reactnativenavigation/views/collapsingToolbar/CollapsingTextView.java Ver arquivo

@@ -11,6 +11,7 @@ import android.support.v4.widget.TextViewCompat;
11 11
 import android.support.v7.widget.TintTypedArray;
12 12
 import android.text.TextPaint;
13 13
 import android.text.TextUtils;
14
+import android.util.Log;
14 15
 import android.view.animation.DecelerateInterpolator;
15 16
 import android.view.animation.Interpolator;
16 17
 import android.widget.FrameLayout;
@@ -20,6 +21,9 @@ import android.widget.TextView;
20 21
 import com.reactnativenavigation.R;
21 22
 import com.reactnativenavigation.params.StyleParams;
22 23
 import com.reactnativenavigation.utils.ViewUtils;
24
+import com.reactnativenavigation.views.utils.Point;
25
+
26
+import static android.R.attr.y;
23 27
 
24 28
 public class CollapsingTextView extends FrameLayout {
25 29
     private static final float TEXT_SCALE_FACTOR = 1.75f;
@@ -123,11 +127,9 @@ public class CollapsingTextView extends FrameLayout {
123 127
     }
124 128
 
125 129
     private void calculateTextPosition(Canvas canvas) {
126
-        final int[] positionOnScreen = new int[2];
127
-        getLocationInWindow(positionOnScreen);
128
-        currentY = initialY = positionOnScreen[1] + canvas.getHeight() - dummy.getMeasuredHeight();
130
+        currentY = initialY = ViewUtils.getStatusBarHeight() + canvas.getHeight() - dummy.getMeasuredHeight();
129 131
         float bottomMargin = ViewUtils.convertDpToPixel(10);
130
-        collapseY = positionOnScreen[1] + bottomMargin;
132
+        collapseY = ViewUtils.getStatusBarHeight() + bottomMargin;
131 133
     }
132 134
 
133 135
     private float linearInterpolation(float from, float to, float fraction) {