Skip to content

Commit

Permalink
fix overflow hidden
Browse files Browse the repository at this point in the history
Reviewed By: shergin

Differential Revision: D5917111

fbshipit-source-id: e3d97f26b6aada199f700ec6659ace0d7dffd4c5
  • Loading branch information
aaronechiu authored and facebook-github-bot committed Sep 30, 2017
1 parent e7af72b commit 30044fd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@

package com.facebook.react.views.view;

import javax.annotation.Nullable;

import java.util.Arrays;
import java.util.Locale;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
Expand All @@ -26,11 +21,13 @@
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;

import com.facebook.yoga.YogaConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
import com.facebook.react.uimanager.FloatUtil;
import com.facebook.react.uimanager.Spacing;
import com.facebook.yoga.YogaConstants;
import java.util.Arrays;
import java.util.Locale;
import javax.annotation.Nullable;

/**
* A subclass of {@link Drawable} used for background of {@link ReactViewGroup}. It supports
Expand Down Expand Up @@ -231,6 +228,10 @@ public void setRadius(float radius, int position) {
}
}

public float getRadius() {
return mBorderRadius;
}

public void setColor(int color) {
mColor = color;
invalidateSelf();
Expand Down Expand Up @@ -334,10 +335,8 @@ private void updatePathEffect() {
mPaint.setPathEffect(mPathEffectForBorderStyle);
}

/**
* For rounded borders we use default "borderWidth" property.
*/
private float getFullBorderWidth() {
/** For rounded borders we use default "borderWidth" property. */
public float getFullBorderWidth() {
return (mBorderWidth != null && !YogaConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) ?
mBorderWidth.getRaw(Spacing.ALL) : 0f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
package com.facebook.react.views.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
Expand All @@ -31,6 +34,7 @@
import com.facebook.react.uimanager.ReactPointerEventsView;
import com.facebook.react.uimanager.ReactZIndexedViewGroup;
import com.facebook.react.uimanager.ViewGroupDrawingOrderHelper;
import com.facebook.yoga.YogaConstants;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -93,12 +97,14 @@ public void onLayoutChange(
private int mAllChildrenCount;
private @Nullable Rect mClippingRect;
private @Nullable Rect mHitSlopRect;
private @Nullable String mOverflow;
private PointerEvents mPointerEvents = PointerEvents.AUTO;
private @Nullable ChildrenLayoutChangeListener mChildrenLayoutChangeListener;
private @Nullable ReactViewBackgroundDrawable mReactBackgroundDrawable;
private @Nullable OnInterceptTouchEventListener mOnInterceptTouchEventListener;
private boolean mNeedsOffscreenAlphaCompositing = false;
private final ViewGroupDrawingOrderHelper mDrawingOrderHelper;
private @Nullable Path mPath;

public ReactViewGroup(Context context) {
super(context);
Expand Down Expand Up @@ -584,6 +590,11 @@ public void setHitSlopRect(@Nullable Rect rect) {
mHitSlopRect = rect;
}

public void setOverflow(String overflow) {
mOverflow = overflow;
invalidate();
}

/**
* Set the background for the view or remove the background. It calls {@link
* #setBackground(Drawable)} or {@link #setBackgroundDrawable(Drawable)} based on the sdk version.
Expand All @@ -599,4 +610,45 @@ private void updateBackgroundDrawable(Drawable drawable) {
}
}

@Override
protected void dispatchDraw(Canvas canvas) {
if (mOverflow != null) {
switch (mOverflow) {
case "visible":
if (mPath != null) {
mPath.rewind();
}
break;
case "hidden":
if (mReactBackgroundDrawable != null) {
float left = 0f;
float top = 0f;
float right = getWidth();
float bottom = getHeight();
if (mReactBackgroundDrawable.getFullBorderWidth() != 0f) {
float borderWidth = mReactBackgroundDrawable.getFullBorderWidth();
left += borderWidth;
top += borderWidth;
right -= borderWidth;
bottom -= borderWidth;
}
float radius = mReactBackgroundDrawable.getRadius();

if (radius != YogaConstants.UNDEFINED) {
if (mPath == null) {
mPath = new Path();
}
mPath.rewind();
mPath.addRoundRect(
new RectF(left, top, right, bottom), radius, radius, Path.Direction.CW);
canvas.clipPath(mPath);
}
}
break;
default:
break;
}
}
super.dispatchDraw(canvas);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public void setCollapsable(ReactViewGroup view, boolean collapsable) {
// handled in NativeViewHierarchyOptimizer
}

@ReactProp(name = ViewProps.OVERFLOW)
public void setOverflow(ReactViewGroup view, String overflow) {
view.setOverflow(overflow);
}

@Override
public String getName() {
return REACT_CLASS;
Expand Down

11 comments on commit 30044fd

@atticoos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@Doko-Demo-Doa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Images still can't be drawn with overflow: visible behavior like iOS.

@Noitidart
Copy link

@Noitidart Noitidart commented on 30044fd Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the github issue tracking this? Is it this one: #6802?

@designorant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Doko-Demo-Doa There's a workaround: https://snack.expo.io/@designorant/overflow-visible-android-workaround although it doesn't work with some complex cases.

@Doko-Demo-Doa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I knew how to do it. But it's something good anyway.

@slorber
Copy link
Contributor

@slorber slorber commented on 30044fd Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't this commit break the ability of Android view to overflow their parent?

#17074

@brunolemos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not working well with transforms: #18266

@marcorm
Copy link

@marcorm marcorm commented on 30044fd Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not been released with 0.56... I'm i right?

@yeomann
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still not working in android? 😞

@mike623
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt merge?

@thinklinux
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this commit still relevant?

Please sign in to comment.