mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-05 07:59:28 +00:00
[android] fix hit testing of nested svg and invalidation on changes.
This commit is contained in:
@@ -117,6 +117,9 @@ class GroupView extends RenderableView {
|
||||
} else if (child instanceof SvgView) {
|
||||
SvgView svgView = (SvgView)child;
|
||||
svgView.drawChildren(canvas);
|
||||
if (svgView.isResponsible()) {
|
||||
svg.enableTouchEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setClientRect(groupRect);
|
||||
@@ -230,18 +233,24 @@ class GroupView extends RenderableView {
|
||||
|
||||
for (int i = getChildCount() - 1; i >= 0; i--) {
|
||||
View child = getChildAt(i);
|
||||
if (!(child instanceof VirtualView)) {
|
||||
continue;
|
||||
}
|
||||
if (child instanceof MaskView) {
|
||||
continue;
|
||||
}
|
||||
if (child instanceof VirtualView) {
|
||||
if (child instanceof MaskView) {
|
||||
continue;
|
||||
}
|
||||
|
||||
VirtualView node = (VirtualView) child;
|
||||
VirtualView node = (VirtualView) child;
|
||||
|
||||
int hitChild = node.hitTest(dst);
|
||||
if (hitChild != -1) {
|
||||
return (node.isResponsible() || hitChild != child.getId()) ? hitChild : getId();
|
||||
int hitChild = node.hitTest(dst);
|
||||
if (hitChild != -1) {
|
||||
return (node.isResponsible() || hitChild != child.getId()) ? hitChild : getId();
|
||||
}
|
||||
} else if (child instanceof SvgView) {
|
||||
SvgView node = (SvgView) child;
|
||||
|
||||
int hitChild = node.reactTagForTouch(dst[0], dst[1]);
|
||||
if (hitChild != child.getId()) {
|
||||
return hitChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,15 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
ViewParent parent = getParent();
|
||||
if (parent instanceof VirtualView) {
|
||||
if (!mRendered) {
|
||||
return;
|
||||
}
|
||||
mRendered = false;
|
||||
((VirtualView) parent).getSvgView().invalidate();
|
||||
return;
|
||||
}
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
}
|
||||
@@ -242,6 +251,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
}
|
||||
|
||||
void drawChildren(final Canvas canvas) {
|
||||
mRendered = true;
|
||||
mCanvas = canvas;
|
||||
if (mAlign != null) {
|
||||
RectF vbRect = getViewBox();
|
||||
@@ -314,6 +324,10 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
}
|
||||
}
|
||||
|
||||
boolean isResponsible() {
|
||||
return mResponsible;
|
||||
}
|
||||
|
||||
private int hitTest(float touchX, float touchY) {
|
||||
if (!mResponsible || !mInvertible) {
|
||||
return getId();
|
||||
@@ -326,11 +340,11 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
int viewTag = -1;
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
View child = getChildAt(i);
|
||||
if (!(child instanceof VirtualView)) {
|
||||
continue;
|
||||
if (child instanceof VirtualView) {
|
||||
viewTag = ((VirtualView) child).hitTest(transformed);
|
||||
} else if (child instanceof SvgView) {
|
||||
viewTag = ((SvgView) child).hitTest(touchX, touchY);
|
||||
}
|
||||
|
||||
viewTag = ((VirtualView) child).hitTest(transformed);
|
||||
if (viewTag != -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user