wuba / wuba/react-native-echarts

0.81.4开启新架构React Native CLI方式依赖后使用报错

Open
#267 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
967
Forks
35
PR merge metrics
No merged PRs in 30d

Description

#报错如下:

Image

#调用代码:

import { useEffect, useRef } from 'react';
import { Dimensions } from 'react-native';
import {
  SVGRenderer,
  SkiaRenderer,
  SkiaChart,
} from '@wuba/react-native-echarts';
import * as echarts from 'echarts/core';
import type { EChartsOption } from 'echarts';
import type { ChartElement } from '@wuba/react-native-echarts';
import { BarChart, LineChart } from 'echarts/charts';
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
} from 'echarts/components';
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  SVGRenderer,
  SkiaRenderer,
  BarChart,
  LineChart,
]);

const E_HEIGHT = 250;
const E_WIDTH = Dimensions.get('screen').width;

function SkiaComponent({ option }: { option: EChartsOption }) {
  const skiaRef = useRef<(ChartElement & any) | null>(null);

  useEffect(() => {
    let chart: echarts.EChartsType | undefined;
    if (skiaRef.current) {
      chart = echarts.init(skiaRef.current, 'light', {
        // @ts-ignore
        renderer: 'skia',
        width: E_WIDTH,
        height: E_HEIGHT,
      });
      chart.setOption(option);
    }
    return () => chart?.dispose();
  }, [option]);

  return <SkiaChart ref={skiaRef} />;
}
export default SkiaComponent;
//使用:
import { Platform, StyleSheet, View } from 'react-native';
import React from 'react';
import { EChartsOption } from 'echarts';
import SkiaComponent from '../components/SkiaComponent.tsx';
const fontFamily = Platform.select({
  ios: 'PingFang SC',
  android: 'sans-serif',
});
const option = {
  xAxis: {
    type: 'category' as const,
    data: ['周一', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  },
  yAxis: {
    type: 'value' as const,
  },
  tooltip: {
    trigger: 'axis' as const,
  },
  series: [
    {
      data: [120, 200, 150, 80, 70, 110, 130],
      type: 'bar' as const,
    },
    {
      data: [220, 100, 180, 160, 150, 120, 110],
      type: 'line' as const,
    },
  ],
  textStyle: {
    fontFamily,
  },
} as EChartsOption;
function GameScreen() {
  return <View style={styles.container}>
    <SkiaComponent option={option}/>
  </View>;
}
export default GameScreen
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    paddingBottom: 24,
  }
});
App.tsx:

  <Tab.Screen
        name={ROUTES.GAMES}
        component={GameScreen}
        options={{ title: 'Game' }}
      />

#新增的依赖如下:
package.json:

   "@wuba/react-native-echarts": "3.0.1",
    "@shopify/react-native-skia": "2.2.12",
    "echarts": "^6.0.0",
    "react-native-reanimated": "~4.1.0",
    "react-native-worklets": "^0.5.1",
    "zrender": "^6.0.0"`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported error with the dependencies in package.json and the new-architecture setup. Inspect App.tsx and the SkiaComponent code, especially the SkiaChart ref and echarts.init call, then compare the installed package versions. Done means identifying the compatibility or usage problem and confirming that the chart renders without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.