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.

Removing child elements causes crash (Android, 7.0.3)

See original GitHub issue

I’m running into issues when I try to remove a child from an <Svg> element.

Platform: Android react-native: 0.57.0 react-native-svg: 7.0.3

Here’s a picture of the error:

It appears that React is trying to manage the removal of one of the native SVG components, but you’ve already removed it, but I’m not too familiar with React Native development.

Here’s the reproduction code. Click the button at the top to add the line, then click again to cause the crash.

import React from 'react';
import { Button, Dimensions, StyleSheet, View, } from 'react-native';
import Svg, { Polyline } from 'react-native-svg';

const { width, height } = Dimensions.get('window');

export default class SVGFail extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showLine: false
    };
  }

  toggleLine = () => {
    this.setState({ showLine: !this.state.showLine });
  }

  render() {
    const { showLine } = this.state;
    return (
      <View
        style={styles.container}
      >
        <Button
          title="Toggle Line"
          onPress={this.toggleLine}
        />
        <Svg
          width={width}
          height={height}
        >
          {showLine ? (
            <Polyline
              points={'10,10 100,100 150,100 100,150'}
              fill="none"
              stroke="red"
              strokeWidth="1"
            />
          ) : (
            null
          )}
        </Svg>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    backgroundColor: 'beige',
  },
});

UPDATE: After some debugging, the error occurs in NativeViewHierarchyManager.java when React tries to remove the child from the SvgView, but there isn’t a child in SvgView to remove. Well, SvgView overrides the addView method and only adds children if they are not instances of RenderableView, which means that somehow SvgView never ends up with children, despite displaying the content. I’m not familiar enough with the code base to be able to help more.

UPDATE 2: Everything works when I wrap my polylines with a <G> tag, which is great, but this is still a valid bug.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
ManAnRuckcommented, Sep 28, 2018

@IjzerenHein u can use the G Tag from react-native-svg

bildschirmfoto 2018-09-28 um 12 28 36 bildschirmfoto 2018-09-28 um 12 28 48
0reactions
msandcommented, Feb 9, 2019

I’ve published a proper fix for iOS in v9.2.4 If anyone has any issues in either iOS or Android with the latest version, please comment and / or provide a reproduction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Removing child elements causes crash (Android, 7.0.3) #789
I'm running into issues when I try to remove a child from an element. Platform: Android react-native: 0.57.0 react-native-svg: 7.0.3.
Read more >
App crash after removing firebase child - Stack Overflow
My app shows in a RecyclerView some various firebase children and its Values. I made a method on the app, which can delete...
Read more >
Android Studio 2021.1.1 Closed Issues
Android Gradle Plugin 7.0.2 crashes app on Android 4 and 5 devices with Verifier rejected class due to bad method ...
Read more >
Xamarin Forms App Crash on Android - Esri Community
I just upgraded some of the Android components on my PC, ... to my device from some other means the app crashes with...
Read more >
IndexOutOfBoundsException in RecyclerView ... - Issue Tracker
This crash happens because the RecyclerView tries to calculate a layout and at the same time you are changing adapter contents. De-couple your ......
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