hamjeth Misree
hamjeth Misree

Reputation: 123

React Native: TypeError with SvgText component on Android but not on iOS

Problem

I'm working on a React Native project using TypeScript and react-native-svg to create an AttendanceCard component that includes a circular progress chart and percentage text. The component works perfectly on iOS, but I'm encountering a type error when running the app on Android

Error Message

Type '{ children: (string | number)[]; x: string; y: string; fontSize: string; textAnchor: "middle"; fill: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<TextProps, any, any>> & Readonly<TextProps>'.
Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<TextProps, any, any>> & Readonly<TextProps>'.
import React from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import Svg, { Circle, Text as SvgText } from 'react-native-svg';
import { styles } from './styles';

const AttendanceCard = () => {
  const percentage = 75;

  return (
    <View style={styles.cardContainer}>
      <View style={styles.row}>
        <Svg height="100" width="100" viewBox="0 0 100 100">
          <Circle
            cx="50"
            cy="50"
            r="40"
            stroke="#9756AA"
            strokeWidth="10"
            fill="none"
            strokeDasharray={`${percentage * 2.5} ${100 * 2.5}`}
            rotation="-90"
            origin="50, 50"
          />
          <Circle
            cx="50"
            cy="50"
            r="40"
            stroke="gold"
            strokeWidth="10"
            fill="none"
            strokeDasharray={`${(100 - percentage) * 2.5} ${100 * 2.5}`}
            rotation={`${percentage * 7.2}`}
            origin="50, 50"
          />
          <SvgText x="45" y="55" fontSize="20" textAnchor="middle" fill="purple">
            {percentage}%
          </SvgText>
        </Svg>
        <View style={styles.column}>
          <Text style={styles.date}>May 23, 2024</Text>
          <View style={styles.row1}>
            <View style={styles.textContainer}>
              <Text style={styles.title}>Attendance</Text>
              <TouchableOpacity style={styles.button}>
                <Text style={styles.buttonText}>View full</Text>
              </TouchableOpacity>
            </View>
          </View>
          <View style={styles.row2}>
            <View style={styles.legend}>
              <View style={[styles.legendColor, { backgroundColor: 'purple' }]} />
              <Text>Day Present</Text>
            </View>
            <View style={styles.legend}>
              <View style={[styles.legendColor, { backgroundColor: 'gold' }]} />
              <Text>Day Absent</Text>
            </View>
          </View>
        </View>
      </View>
    </View>
  );
};

export default AttendanceCard;



What I've Tried:

**Expected Outcome: **

I expected the SvgText component to render the percentage text inside the circular progress chart correctly on both iOS and Android. While it works perfectly on iOS, it fails on Android with the mentioned type error.

Actual Outcome:

The component works fine on iOS, rendering the text as expected. However, on Android, it throws a type error stating that the children prop cannot be assigned to the TextProps type.

Upvotes: 0

Views: 45

Answers (0)

Related Questions