question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Removed child count (0) was not what we expected (1)

See original GitHub issue

I’m getting the following error on iOS only (specifically an iPhone SE running iOS 12) while rendering an area chart with a line and a gradient in React Native. I’ve been able to isolate the issue down to the <Line /> component which renders a <Path />, but I’m not sure how to stop the error from popping up each time I render the chart.

I also tested on Android, and there are no errors there.

img_1768

These are the versions I’m using:

“react-native”: “0.57.1”, “react-native-svg”: “^8.0.8”, “react-native-svg-charts”: “^5.2.0”,

And here is my code:

import React from "react";
import { View } from "react-native";
import {
  Defs,
  LinearGradient,
  Path,
  Stop
} from "react-native-svg";
import { AreaChart, XAxis, YAxis } from "react-native-svg-charts";
import * as scale from "d3-scale";
import * as shape from "d3-shape";
import moment from "moment";

const SpeciesChart = ( { data } ) => {
  const formatXAxis = ( index ) => {
    const allMonths = moment.monthsShort();
    if ( index === 0 || index % 2 === 0 ) {
      return "      " + allMonths[index];
    }
  };

  const Line = ( { line } ) => (
    <Path
      key="line"
      d={line}
      stroke="rgb(255, 255, 255)"
      strokeWidth="3"
      fill="none"
    />
  );

  const Gradient = ( { index } ) => (
    <Defs key={index}>
      <LinearGradient id="gradient" x1="0%" y="0%" x2="0%" y2="100%">
        <Stop offset="0%" stopColor="rgb(255, 255, 255)" stopOpacity={0.8} />
        <Stop offset="100%" stopColor="rgb(255, 255, 255)" stopOpacity={0.2} />
      </LinearGradient>
    </Defs>
  );

  return (
    <View>
      <YAxis
        data={data}
        yAccessor={ ( { item } ) => item.count }
        contentInset={styles.contentInset}
        svg={{ fontSize: 10, fill: "white" }}
        min={0}
        numberOfTicks={8}
      />
      <View style={styles.chartRow}>
        <AreaChart
          data={data}
          yAccessor={ ( { item } ) => item.count }
          xAccessor={( { item } ) => item.month }
          xScale={scale.scaleTime}
          yScale={scale.scaleLinear}
          contentInset={styles.contentInset}
          curve={shape.curveNatural}
          svg={{ fill: "url(#gradient)" }}
        >
          <Line />
          <Gradient />
        </AreaChart>
        <XAxis
          data={data}
          xAccessor={( { item } ) => item.month }
          formatLabel={ value => formatXAxis( value - 1 ) }
          svg={{
            fontSize: 10,
            fill: "white"
          }}
        />
      </View>
    </View>
  );
};

export default SpeciesChart;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:18

github_iconTop GitHub Comments

5reactions
bhavik13commented, Feb 5, 2019

const Gradient = ({ index }) => ( <G> <Defs key={index}> <LinearGradient id="gradient" x1="0%" y="0%" x2="0%" y2="100%"> <Stop offset="0%" stopColor="rgb(255, 255, 255)" stopOpacity={0.8} /> <Stop offset="100%" stopColor="rgb(255, 255, 255)" stopOpacity={0.2} /> </LinearGradient> </Defs> </G> );

Add <G> tag

1reaction
springroll12commented, Feb 25, 2019

Tested this on android today and all seems well. I think it’s safe to say this is fixed!

Thanks @msand !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Removed child count (0) was not what we expected (1) #848
Using react-native-chart-kit and react-native-svg to render some linecharts. When I try to update data, this error occurs.
Read more >
Trying to remove a view index above child count error
I set this to true after deletion. The post hid with layout animation correctly, and when the page refreshed it no longer rendered...
Read more >
"Purge All" space trash fails with "org.hibernate ... - Jira Atlassian
1 (1409026) -- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.
Read more >
Trying to remove a view index above child count error-React ...
Coding example for the question Trying to remove a view index above child count error-React Native.
Read more >
Everything you need to know about the children prop in React
It verifies that children has only one child and returns it. If there is more than one child, then it will throw an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found