Skip to content

Commit

Permalink
fix(android): elements not touchable if below opacity limit
Browse files Browse the repository at this point in the history
fixes #1200:
  <Rect>, <Ellipse> are not rendered if opacity set to 0 on Android
  • Loading branch information
msand committed Jan 4, 2020
1 parent a2ef51f commit ebc7220
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 50 deletions.
6 changes: 2 additions & 4 deletions android/src/main/java/com/horcrux/svg/GroupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ void popGlyphContext() {

void draw(final Canvas canvas, final Paint paint, final float opacity) {
setupGlyphContext(canvas);
if (opacity > MIN_OPACITY_FOR_DRAW) {
clip(canvas, paint);
drawGroup(canvas, paint, opacity);
}
clip(canvas, paint);
drawGroup(canvas, paint, opacity);
}

void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
Expand Down
70 changes: 34 additions & 36 deletions android/src/main/java/com/horcrux/svg/RenderableView.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,49 +336,47 @@ void render(Canvas canvas, Paint paint, float opacity) {
void draw(Canvas canvas, Paint paint, float opacity) {
opacity *= mOpacity;

if (opacity > MIN_OPACITY_FOR_DRAW) {
boolean computePaths = mPath == null;
if (computePaths) {
mPath = getPath(canvas, paint);
mPath.setFillType(fillRule);
}
boolean nonScalingStroke = vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE;
Path path = mPath;
if (nonScalingStroke) {
Path scaled = new Path();
//noinspection deprecation
mPath.transform(mCTM, scaled);
canvas.setMatrix(null);
path = scaled;
}
boolean computePaths = mPath == null;
if (computePaths) {
mPath = getPath(canvas, paint);
mPath.setFillType(fillRule);
}
boolean nonScalingStroke = vectorEffect == VECTOR_EFFECT_NON_SCALING_STROKE;
Path path = mPath;
if (nonScalingStroke) {
Path scaled = new Path();
//noinspection deprecation
mPath.transform(mCTM, scaled);
canvas.setMatrix(null);
path = scaled;
}

if (computePaths || path != mPath) {
mBox = new RectF();
path.computeBounds(mBox, true);
}
if (computePaths || path != mPath) {
mBox = new RectF();
path.computeBounds(mBox, true);
}

RectF clientRect = new RectF(mBox);
mCTM.mapRect(clientRect);
this.setClientRect(clientRect);
RectF clientRect = new RectF(mBox);
mCTM.mapRect(clientRect);
this.setClientRect(clientRect);

clip(canvas, paint);
clip(canvas, paint);

if (setupFillPaint(paint, opacity * fillOpacity)) {
if (computePaths) {
mFillPath = new Path();
paint.getFillPath(path, mFillPath);
}
canvas.drawPath(path, paint);
if (setupFillPaint(paint, opacity * fillOpacity)) {
if (computePaths) {
mFillPath = new Path();
paint.getFillPath(path, mFillPath);
}
if (setupStrokePaint(paint, opacity * strokeOpacity)) {
if (computePaths) {
mStrokePath = new Path();
paint.getFillPath(path, mStrokePath);
}
canvas.drawPath(path, paint);
canvas.drawPath(path, paint);
}
if (setupStrokePaint(paint, opacity * strokeOpacity)) {
if (computePaths) {
mStrokePath = new Path();
paint.getFillPath(path, mStrokePath);
}
renderMarkers(canvas, paint, opacity);
canvas.drawPath(path, paint);
}
renderMarkers(canvas, paint, opacity);
}

void renderMarkers(Canvas canvas, Paint paint, float opacity) {
Expand Down
14 changes: 6 additions & 8 deletions android/src/main/java/com/horcrux/svg/TextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,12 @@ public void setPositionY(Dynamic positionY) {

@Override
void draw(Canvas canvas, Paint paint, float opacity) {
if (opacity > MIN_OPACITY_FOR_DRAW) {
setupGlyphContext(canvas);
clip(canvas, paint);
getGroupPath(canvas, paint);
pushGlyphContext();
drawGroup(canvas, paint, opacity);
popGlyphContext();
}
setupGlyphContext(canvas);
clip(canvas, paint);
getGroupPath(canvas, paint);
pushGlyphContext();
drawGroup(canvas, paint, opacity);
popGlyphContext();
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions android/src/main/java/com/horcrux/svg/VirtualView.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ abstract public class VirtualView extends ReactViewGroup {
*/
private static final double M_SQRT1_2l = 0.707106781186547524400844362104849039;

static final float MIN_OPACITY_FOR_DRAW = 0.01f;

private static final float[] sRawMatrix = new float[]{
1, 0, 0,
0, 1, 0,
Expand Down

0 comments on commit ebc7220

Please sign in to comment.