mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-04 23:54:53 +00:00
feat(android): support using other native views in e.g. masks
This commit is contained in:
@@ -23,6 +23,7 @@ import android.view.View;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
import com.facebook.react.uimanager.annotations.ReactProp;
|
||||
import com.facebook.react.views.view.ReactViewGroup;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -123,6 +124,10 @@ class GroupView extends RenderableView {
|
||||
if (svgView.isResponsible()) {
|
||||
svg.enableTouchEvents();
|
||||
}
|
||||
} else if (child instanceof ReactViewGroup) {
|
||||
// Enable rendering other native ancestor views in e.g. masks
|
||||
ReactViewGroup vg = (ReactViewGroup) child;
|
||||
vg.draw(canvas);
|
||||
}
|
||||
}
|
||||
this.setClientRect(groupRect);
|
||||
|
||||
@@ -21,6 +21,8 @@ import android.util.Base64;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.uimanager.DisplayMetricsHolder;
|
||||
@@ -94,6 +96,25 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
||||
mBitmap = null;
|
||||
}
|
||||
|
||||
// Enable rendering other native ancestor views in e.g. masks, but don't render them another time
|
||||
Bitmap fakeBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
|
||||
Canvas fake = new Canvas(fakeBitmap);
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(fake);
|
||||
}
|
||||
|
||||
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
||||
return super.drawChild(fake, child, drawingTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDescendantInvalidated(@NonNull View child, @NonNull View target) {
|
||||
super.onDescendantInvalidated(child, target);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
if (getParent() instanceof VirtualView) {
|
||||
|
||||
@@ -559,13 +559,17 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
return;
|
||||
}
|
||||
mClientRect = rect;
|
||||
if (mClientRect == null || (!mResponsible && !mOnLayout)) {
|
||||
if (mClientRect == null) {
|
||||
return;
|
||||
}
|
||||
int width = (int) Math.ceil(mClientRect.width());
|
||||
int height = (int) Math.ceil(mClientRect.height());
|
||||
setMeasuredDimension(width, height);
|
||||
if ((!mResponsible && !mOnLayout)) {
|
||||
return;
|
||||
}
|
||||
int left = (int) Math.floor(mClientRect.left);
|
||||
int top = (int) Math.floor(mClientRect.top);
|
||||
int width = (int) Math.ceil(mClientRect.width());
|
||||
int height = (int) Math.ceil(mClientRect.height());
|
||||
if (mResponsible) {
|
||||
int right = (int) Math.ceil(mClientRect.right);
|
||||
int bottom = (int) Math.ceil(mClientRect.bottom);
|
||||
@@ -576,7 +580,6 @@ abstract public class VirtualView extends ReactViewGroup {
|
||||
setRight(right);
|
||||
setBottom(bottom);
|
||||
}
|
||||
setMeasuredDimension(width, height);
|
||||
}
|
||||
if (mOnLayout) {
|
||||
EventDispatcher eventDispatcher = mContext
|
||||
|
||||
Reference in New Issue
Block a user