How do I install React Native Skia so that I can use it with an Expo project and see it working in Expo Go?

huangapple go评论108阅读模式
英文:

How do I install React Native Skia so that I can use it with an Expo project and see it working in Expo Go?

问题

我一直在尝试启动一个项目,该项目将使用React Native Skia来绘制类似HTML Canvas的图形。我已经设置了一个Expo项目,并运行了以下命令 - npx expo install @shopify/react-native-skia。

当我尝试在Expo GO中打开项目时,我收到以下消息:

Uncaught Error
无法读取未定义的属性'displayName'

我认为这是从withDevTools.js中调用的,我认为它是Expo捆绑软件的一部分。

只有当我尝试在项目中使用Skia时才会发生这种情况,否则不会发生?

我尝试运行基本的Skia示例,如下所示:

import { Canvas, Circle, Group } from "@shopify/react-native-skia";

export const HelloWorld = () => {
  const size = 256;
  const r = size * 0.33;
  return (
    <Canvas style={{ flex: 1 }}>
      <Group blendMode="multiply">
        <Circle cx={r} cy={r} r={r} color="cyan" />
        <Circle cx={size - r} cy={r} r={r} color="magenta" />
        <Circle
          cx={size / 2}
          cy={size - r}
          r={r}
          color="yellow"
        />
      </Group>
    </Canvas>
  );
};

在下面链接的Skia安装指南中,它说要在ios目录上运行pod install。我还没有执行这一步,因为Expo尚未创建我可以找到的ios目录。任何帮助将不胜感激。

https://shopify.github.io/react-native-skia/docs/getting-started/installation

英文:

I've been trying to start a project which will use React Native Skia to draw HTML Canvas like graphics. I've set up an Expo project and ran the following command - npx expo install @shopify/react-native-skia.

When I try to open the project in Expo GO I get the following message:

Uncaught Error
Cannot read property 'displayName' of undefined

This is being called from withDevTools.js which I assume is part of the Expo bundling software.

This only happens if I try to use Skia in the project but not otherwise?

I tried to run the basic Skia example as follows:

import {Canvas, Circle, Group} from &quot;@shopify/react-native-skia&quot;;
 
export const HelloWorld = () =&gt; {
  const size = 256;
  const r = size * 0.33;
  return (
    &lt;Canvas style={{ flex: 1 }}&gt;
      &lt;Group blendMode=&quot;multiply&quot;&gt;
        &lt;Circle cx={r} cy={r} r={r} color=&quot;cyan&quot; /&gt;
        &lt;Circle cx={size - r} cy={r} r={r} color=&quot;magenta&quot; /&gt;
        &lt;Circle
          cx={size/2}
          cy={size - r}
          r={r}
          color=&quot;yellow&quot;
        /&gt;
      &lt;/Group&gt;
    &lt;/Canvas&gt;
  );
};

Within the Skia Installation guide linked below it says run pod install on the ios directory. I have not do this step as Expo has not created an ios directory that I can find? Any help would be appreciated.

https://shopify.github.io/react-native-skia/docs/getting-started/installation

答案1

得分: 1

我也遇到了这个问题。原来你需要在你的 App.js 文件中设置默认导出。

也就是说,你需要这样写 export default HelloWorld = () =&gt; { ...

英文:

I had this issue as well. Turns out that you need a default export in your App.js.

i.e. you need export default HelloWorld = () =&gt; { ... instead.

huangapple
  • 本文由 发表于 2023年8月10日 21:43:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876316.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定