Skip to content

Fix react-native-svg elements not appearing in SKIA snapshotsย #3611

@XChikuX

Description

@XChikuX

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch @shopify/[email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java b/node_modules/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java
index 127f91f..c6d0fb9 100644
--- a/node_modules/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java
+++ b/node_modules/@shopify/react-native-skia/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java
@@ -67,6 +67,16 @@ public class ViewScreenshotService {
         return paint;
     }
 
+    private static boolean isSvgView(View view) {
+    try {
+        String className = view.getClass().getName();
+        return className != null && className.startsWith("com.horcrux.svg");
+    } catch (Throwable t) {
+        Log.e("SvgCheck", "Error checking class name", t);
+        return false;
+    }
+    }
+
     private static void renderViewToCanvas(Canvas canvas, View view, Paint paint, float parentOpacity) {
         float combinedOpacity = parentOpacity * view.getAlpha();
         canvas.save();
@@ -83,7 +93,7 @@ public class ViewScreenshotService {
             canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
         }
 
-        if (view instanceof ViewGroup) {
+        if (view instanceof ViewGroup && !isSvgView(view)) {
             ViewGroup group = (ViewGroup) view;
             drawBackgroundIfPresent(canvas, view, combinedOpacity);
             drawChildren(canvas, group, paint, combinedOpacity);

Based on patch example from #2555

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions