You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo 36.0.0中react-native-pie报ARTShape未找到错误求助

Fixing "ARTShape was not found in the UIManager" with react-native-pie in Expo 36.0.0

Hey there! Let's get that pie chart working for you. That error pops up because react-native-pie relies on React Native's native ART library, which isn't set up the same way in Expo—Expo wraps ART into the expo-art package instead. Here's how to fix it, step by step:

Option 1: Patch react-native-pie to work with Expo

1. Install expo-art first

Run this in your project root to add the Expo-compatible ART package:

expo install expo-art

2. Update the ART import in react-native-pie

The react-native-pie package looks for ART in react-native by default, but we need to point it to expo-art. Open node_modules/react-native-pie/Pie.js and change:

import { ART } from 'react-native';

to:

import * as ART from 'expo-art';

⚠️ Quick note: This change will get overwritten if you run npm install or yarn install later. For a permanent fix, skip to Option 2.

Option 2: Build a custom pie chart with expo-art (no external dependencies)

If you don't want to mess with node_modules, you can make a simple pie chart component yourself using expo-art directly. Create a new file PieChart.js in your project:

import React from 'react';
import { View } from 'react-native';
import { ART } from 'expo-art';
const { Surface, Shape, Path } = ART;

const PieChart = ({ radius, sections }) => {
  const totalPercentage = sections.reduce((sum, section) => sum + section.percentage, 0);
  let currentAngle = -Math.PI / 2; // Start drawing from the top of the circle

  return (
    <Surface width={radius * 2} height={radius * 2}>
      {sections.map((section, index) => {
        const sliceAngle = (section.percentage / totalPercentage) * 2 * Math.PI;
        const endAngle = currentAngle + sliceAngle;

        // Draw the slice path
        const slicePath = new Path()
          .moveTo(radius, radius)
          .arc(radius, radius, radius, currentAngle, endAngle)
          .close();

        currentAngle = endAngle;

        return <Shape d={slicePath} fill={section.color} key={index} />;
      })}
    </Surface>
  );
};

export default PieChart;

Then update your HomeScreen to use this component instead:

// Replace import Pie from 'react-native-pie'; with:
import PieChart from './PieChart'; // Adjust the path if you saved it elsewhere

// In your render method:
<PieChart radius={80} sections={[
  { percentage:10, color:'red' },
  { percentage:30, color:'green' },
  { percentage:60, color:'orange' }
]} />

Final Step: Restart Expo with cache cleared

Run this command to make sure all changes take effect:

expo start -c

Pro Tip for New React Native/Expo Devs

Since you're just starting out, consider using Expo-compatible chart libraries that don't require native module tweaks:

  • victory-native: Fully supported by Expo, has tons of chart types and customization options
  • react-native-chart-kit: Uses SVG (install with expo install react-native-svg first) and is super easy to set up

内容的提问来源于stack exchange,提问作者M.Kalidass

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 10:47:52