Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG's from react-native-svg don't appear in skia snapshots (makeImageFromView) only Android #2555

Open
dani-benet opened this issue Jul 30, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@dani-benet
Copy link

Description

I'm creating a popper-like component that snapshots a component and puts the image in top of a dark overlay ->

it.works.on.iOS.mp4

But I'm facing an issue on Android where the SVG's created using react native reanimated are not shown in the snapshots.
See on the next video the cursor on the top-left disappears.

on.Android.no.mp4

Version

1.3.9 and also tried it on 1.2.3

Steps to reproduce

Make a snapshot of any svg in Android and it doesn't work.

Snack, code example, screenshot, or link to a repository

I've managed to reproduce the issue with this sample code

import {
  Canvas,
  Image,
  makeImageFromView,
  SkImage,
} from "@shopify/react-native-skia"
import { useRef, useState } from "react"
import { Button, View } from "react-native"
import Close from "~assets/icons/close.svg"

const Home = () => {
  const ref = useRef<View>(null)
  const [snapshot, setSnapshot] = useState<SkImage | null>(null)

  const handleImageCreation = async () => {
    const _snapshot = await makeImageFromView(ref)
    setSnapshot(_snapshot)
  }

  return (
    <View style={{ alignItems: "center", justifyContent: "center", flex: 1 }}>
      <View ref={ref} collapsable={false}>
        <Close style={{ height: 40, width: 40 }} />
      </View>
      {snapshot && (
        <Canvas style={{ height: 40, width: 40 }}>
          <Image image={snapshot} x={0} y={0} width={40} height={40} />
        </Canvas>
      )}
      <Button onPress={handleImageCreation} title="Create Image" />
    </View>
  )
}

on iOS it's visible but not on Android

iOS Android
image android card not working

To render the svg I use the react-native-svg library

  declare module "*.svg" {
    import React from "react"
    import { SvgProps } from "react-native-svg"
    const content: React.FC<SvgProps>
    export default content
  }
@dani-benet dani-benet added the bug Something isn't working label Jul 30, 2024
@wcandillon
Copy link
Contributor

@WoLewicki it looks like RN SVG is using a type of view that we are not handling there: https://github.com/Shopify/react-native-skia/blob/main/package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java#L123

We handle SurfaceView and TextureView, but maybe RN SVG is using something else?

@wcandillon
Copy link
Contributor

Thanks this is very helpful. If gre/react-native-view-shot handles it well, we will be able to do it as well: https://github.com/gre/react-native-view-shot/blob/master/android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

@WoLewicki
Copy link
Contributor

I'd guess react-native-svg views propably go here:

and then here:
Class[] cArg = new Class[1];
cArg[0] = Canvas.class;
Method method = ReactViewGroup.class.getDeclaredMethod("dispatchOverflowDraw", cArg);
method.setAccessible(true);
method.invoke(group, canvas);
and I think it is not the proper way.

@ersincakmak
Copy link

I am facing same issue, any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants