Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Text> does not work in <G> #568

Closed
ghost opened this issue Jan 5, 2018 · 19 comments
Closed

<Text> does not work in <G> #568

ghost opened this issue Jan 5, 2018 · 19 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2018

I just run this test, the first (Line) and the second(Rect) can work well, but the thrid(Text) don't show !

<G
    rotate="50"
    origin="100, 50"
>
    <Line
        x1="60"
        y1="10"
        x2="140"
        y2="10"
        stroke="#060"
    />

    <Rect
        x="60"
        y="20"
        height="50"
        width="80"
        stroke="#060"
        fill="#060"
    />

    <Text
        x="100"
        y="75"
        stroke="#600"
        fill="#600"
        textAnchor="middle"
    >
        Text grouped with shapes</Text>
</G>
@MosesGit
Copy link

MosesGit commented Jan 16, 2018

Are you importing Text from react-native and react-native-svg perhaps?

import { Text } from 'react-native';
import Svg, { Text } from 'react-native-svg';

Normal React Text does not show up in Svg, only Svg.Text

@msand
Copy link
Collaborator

msand commented Feb 13, 2018

This is probably just using the Text component from react-native instead of react-native-svg, and isn't supported for now. I'll go ahead and close this.

@msand msand closed this as completed Feb 13, 2018
@Neha3011
Copy link

Neha3011 commented Apr 9, 2018

Hi, i am facing the same issue.
Text doesn't show, the simulator just closes. If i remove the SVGText, the app works just fine
my code is

import React from 'react';
import { Circle, Line, G, Text as SVGText } from 'react-native-svg'
<G key={index}>
              <Circle
                  cx={x(index)}
                  cy={y(value)}
                  r={4}
                  strokeWidth={2}
                  stroke={'#20AAC3'}
                  fill="white"
              />
              <Line
                  x1={x(index)}
                  y1={"250"}
                  x2={x(index)}
                  stroke="#BFE5EC"
                  strokeWidth="0.3"
              />
              <SVGText
                fontSize="20"
                fontWeight="bold"
                x={x(index)}
                y={"250"}
                textAnchor="middle"
              >Test</SVGText>
            </G>

@Neha3011
Copy link

Neha3011 commented Apr 9, 2018

Adding the stack trace

Exponent[1228]: -[__NSArrayM floatValue]: unrecognized selector sent to instance 0x60000104e640
Exponent[1228]: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM floatValue]: unrecognized selector sent to instance 0x60000104e640'
	*** First throw call stack:
	(
		0   CoreFoundation                      0x000000010fca8b0b __exceptionPreprocess + 171
		1   libobjc.A.dylib                     0x000000010f071141 objc_exception_throw + 48
		2   CoreFoundation                      0x000000010fd18134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
		3   CoreFoundation                      0x000000010fc2f840 ___forwarding___ + 1024
		4   CoreFoundation                      0x000000010fc2f3b8 _CF_forwarding_prep_0 + 120
		5   Exponent                            0x000000010526dd81 +[ABI25_0_0RNSVGPercentageConverter stringToFloat:relative:offset:] + 130
		6   Exponent                            0x0000000105265b61 -[ABI25_0_0RNSVGGlyphContext pushContext:deltaX:deltaY:positionX:positionY:] + 150
		7   Exponent                            0x0000000105272ff6 -[ABI25_0_0RNSVGText pushGlyphContext] + 234
		8   Exponent                            0x0000000105272a92 -[ABI25_0_0RNSVGText getGroupPath:] + 36
		9   Exponent                            0x0000000105272906 -[ABI25_0_0RNSVGText renderLayerTo:] + 80
		10  Exponent                            0x000000010526f687 -[ABI25_0_0RNSVGRenderable renderTo:] + 166
		11  Exponent                            0x0000000105266b62 __37-[ABI25_0_0RNSVGGroup renderGroupTo:]_block_invoke + 178

 systemsoundserver-simd[1231]: [aqme] 254: AQDefaultDevice (173): skipping input stream 0 0 0x0
Exponent[1228]: -[__NSArrayM floatValue]: unrecognized selector sent to instance 0x60000104e640
Exponent[1228]: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM floatValue]: unrecognized selector sent to instance 0x60000104e640'
	*** First throw call stack:
	(
		0   CoreFoundation                      0x000000010fca8b0b __exceptionPreprocess + 171
		1   libobjc.A.dylib                     0x000000010f071141 objc_exception_throw + 48
		2   CoreFoundation                      0x000000010fd18134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
		3   CoreFoundation                      0x000000010fc2f840 ___forwarding___ + 1024
		4   CoreFoundation                      0x000000010fc2f3b8 _CF_forwarding_prep_0 + 120
		5   Exponent                            0x000000010526dd81 +[ABI25_0_0RNSVGPercentageConverter stringToFloat:relative:offset:] + 130
		6   Exponent                            0x0000000105265b61 -[ABI25_0_0RNSVGGlyphContext pushContext:deltaX:deltaY:positionX:positionY:] + 150
		7   Exponent                            0x0000000105272ff6 -[ABI25_0_0RNSVGText pushGlyphContext] + 234
		8   Exponent                            0x0000000105272a92 -[ABI25_0_0RNSVGText getGroupPath:] + 36
		9   Exponent                            0x0000000105272906 -[ABI25_0_0RNSVGText renderLayerTo:] + 80
		10  Exponent                            0x000000010526f687 -[ABI25_0_0RNSVGRenderable renderTo:] + 166
		11  Exponent                            0x0000000105266b62 __37-[ABI25_0_0RNSVGGroup renderGroupTo:]_block_invoke + 178
		12  Exponent                            0x0000000105269968 -[ABI25_0_0RNSVGNode traverseSubviews:] + 285
		13  Exponent                            0x0000000105266a86 -[ABI25_0_0RNSVGGroup renderGroupTo:] + 147
		14  Exponent                            0x000000010526f687 -[ABI25_0_0RNSVGRenderable renderTo:] + 166
		15  Exponent                            0x000000010527144b -[ABI25_0_0RNSVGSvgView drawRect:] + 1371
		16  UIKit                               0x000000010ccd4d45 -[UIView(CALayerDelegate) drawLayer:inContext:] + 489
		17  QuartzCore                          0x000000010c748500 -[CALayer drawInContext:] + 257
		18  QuartzCore                          0x000000010c65eae5 CABackingStoreUpdate_ + 2505
		19  QuartzCore                          0x000000010c7480fa ___ZN2CA5Layer8display_Ev_block_invoke + 61
		20  QuartzCore                          0x000000010c747df3 _ZN2CA5Layer8display_Ev + 1633
		21  QuartzCore                          0x000000010c73c31d _ZN2CA5Layer17display_if_neededEPNS_11TransactionE + 315
		22  QuartzCore                          0x000000010c73c3ab _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 35
		23  QuartzCore                          0x000000010c6cbe92 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
		24  QuartzCore                          0x000000010c6f8130 _ZN2CA11Transaction6commitEv + 468
		25  QuartzCore                          0x000000010c6f8b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
		26  CoreFoundation                      0x000000010fc4e717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
		27  CoreFoundation                      0x000000010fc4e687 __CFRunLoopDoObservers + 391
		28  CoreFoundation                      0x000000010fc33720 __CFRunLoopRun + 1200
		29  CoreFoundation                      0x000000010fc33016 CFRunLoopRunSpecific + 406
		30  GraphicsServices                    0x00000001118eda24 GSEventRunModal + 62
		31  UIKit                               0x000000010cc12134 UIApplicationMain + 159
		32  Exponent                            0x0000000104796381 main + 80
		33  libdyld.dylib                       0x00000001108b465d start + 1
		34  ???                                 0x0000000000000001 0x0 + 1
	)

@ammichael
Copy link

ammichael commented May 4, 2018

I'm also having this issue. I can't render text inside Circle. And, yes, I'm importing from react-native-svg, not react-native.

@Neha3011 did you find a solution?

@msand Why is it closed?

@ap050492
Copy link

Same issue. Any Update ? @Neha3011 @msand @ammichael

@msand
Copy link
Collaborator

msand commented Sep 10, 2018

Are you using expo? It comes with a pre bundled version of react-native-svg and can't be combined with others.

@ap050492
Copy link

@msand Nop,i am not using expo

@msand
Copy link
Collaborator

msand commented Sep 10, 2018

Can you post a replication? I don't know how to make this issue appear

@ap050492
Copy link

Please check below code

<Svg style={{ width: 360, height: 360,alignItems: 'center', justifyContent: 'center', alignContent: 'center' }}>
<Path onPress={()=>
this.props.navigation.navigate('BuildQuery', { id: 1, title: 'Sales' })}
fill="#64B5F6" d="M180,180 L180,0 A180,180 1 0,1 336.278783, 90.6827 z" transform="rotate(60, 180, 180)">
<Text style={{fontSize:30,color:'pink'}}>
Sales


<Path onPress={()=> this.props.navigation.navigate('BuildQuery', { id: 2, title: 'Margins' })}
fill="#D4E157" d="M180,180 L180,0 A180,180 1 0,1 336.278783, 90.6827 z" transform="rotate(120, 180, 180)">




<Path onPress={() => this.props.navigation.navigate('BuildQuery', { id: 6, title: 'Inventory' })}
fill="#9575CD" d="M180,180 L180,0 A180,180 1 0,1 336.278783, 90.6827 z" transform="rotate(360, 180, 180)">


screenshot_2018-09-11-13-48-18-817_com ceodashboard

@ninofiliu
Copy link

ninofiliu commented Dec 16, 2018

Same, <Text> seems to be having some issues.

<G><Text>some text</Text></G>: works fine

<G><Text textAnchor="center">some text</Text></G>: makes the whole app crash: no logged error, the app simply closes. It can be opened back but as soon as I navigate on the faulty component, it happens again. I have to delete the faulty tag, reinstall the app, and re-run react-native run-android to make it work again. I expected some kind of 'center' is not a valid value for textAnchor, maybe you meant 'middle' error, but it's still weird that it makes the whole app crash this hard.

Weird and painful! Good luck on resolving the bug


Computer OS: Windows
Device OS: Android
Reproducible demo: Can't reproduce the fault on small bits of code

@mikeyyyzhao
Copy link

As updates on this? I'm running into this issue as well. My whole app crashes when I insert the code into my svg

<Text fontFamily="Raleway-Bold, Raleway" fontSize={12} fontWeight="bold" letterSpacing={1} fill="#FF1E4F" transform="translate(2240 -14246)" > <TSpan x={10} y={20}> {15} </TSpan> </Text>

@msand
Copy link
Collaborator

msand commented Apr 22, 2019

Are you importing Text from react-native or from react-native-svg? Please provide a full replication.

@mikeyyyzhao
Copy link

mikeyyyzhao commented Apr 22, 2019

I'm importing it from react-native-svg. If I remove the Text part, the rest of the code runs no problem so I assume it's the Text component that causing the error.

import React from "react";

import Svg, { G, Path, Text, TSpan } from "react-native-svg";

const SvgSketchSelectedSvg = props => (

  <Svg width={30} height={32} {...props}>

    <G fill="none" fillRule="evenodd">

      <Path
        d="M2243-14277.5c0 7.456 6.044 13.5 13.5 13.5s13.5-6.044 13.5-13.5c0-3.216-1.125-6.17-3.002-8.489a13.474 13.474 0 0 0-10.498-5.011h-12.077"
        stroke="#FF1D4F"
        strokeWidth={2}
      />
      <Path stroke="#FF1F50" fill="#FF1D4F" d="M2241-14289.5l5-4.5v9z" />
      <Text
        fontFamily="Raleway-Bold, Raleway"
        fontSize={12}
        fontWeight="bold"
        letterSpacing={1}
        fill="#FF1E4F"
        transform="translate(2240 -14295)"
      >
        <TSpan x={10} y={20}>
          {`15`}
        </TSpan>
      </Text>
    </G>
  </Svg>
);

export default SvgSketchSelectedSvg;

Computer OS: Mac
Device OS: iOS
RN version: 0.57.1

@msand
Copy link
Collaborator

msand commented Apr 22, 2019

It seems you're missing a viewBox attribute, and apparently there's a bug with handling of letterSpacing as a number, giving it as a string works fine. Also, I would recommend to move the content to the origin, instead of having it offset to x=2240, and y=-14295, something like this:

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';

import Svg, { G, Path, Text, TSpan } from 'react-native-svg';

const SvgSketchSelectedSvg = props => (
  <Svg width={300} height={320} viewBox="0 0 32 32" {...props}>
    <G fill="none" fillRule="evenodd">
      <Path
        d="M3,17.5c0 7.456 6.044 13.5 13.5 13.5s13.5-6.044 13.5-13.5c0-3.216-1.125-6.17-3.002-8.489a13.474 13.474 0 0 0-10.498-5.011h-12.077"
        stroke="#FF1D4F"
        strokeWidth={2}
      />
      <Path stroke="#FF1F50" fill="#FF1D4F" d="M1,5.5l5-4.5v9z" />
      <Text
        fontFamily="Raleway-Bold, Raleway"
        fontSize={12}
        fontWeight="bold"
        letterSpacing="1"
        fill="#FF1E4F"
      >
        <TSpan x={10} y={20}>
          {`15`}
        </TSpan>
      </Text>
    </G>
  </Svg>
);

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <SvgSketchSelectedSvg />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    backgroundColor: '#ecf0f1',
    justifyContent: 'center',
    alignItems: 'center',
    flex: 1,
  },
});

@msand
Copy link
Collaborator

msand commented Apr 22, 2019

@mikeyyyzhao I've fixed the crash with letterSpacing as numbers in c343229, can you test it?

const SvgSketchSelectedSvg = props => (
  <Svg width={300} height={320} viewBox="0 0 32 32" {...props}>
    <G fill="none" fillRule="evenodd">
      <Path
        d="M3,17.5c0 7.456 6.044 13.5 13.5 13.5s13.5-6.044 13.5-13.5c0-3.216-1.125-6.17-3.002-8.489a13.474 13.474 0 0 0-10.498-5.011h-12.077"
        stroke="#FF1D4F"
        strokeWidth={2}
      />
      <Path stroke="#FF1F50" fill="#FF1D4F" d="M1,5.5l5-4.5v9z" />
      <Text
        fontFamily="Raleway-Bold, Raleway"
        fontSize={12}
        fontWeight="bold"
        letterSpacing={1}
        fill="#FF1E4F"
      >
        <TSpan x={10} y={20}>
          {`15`}
        </TSpan>
      </Text>
    </G>
  </Svg>
);

@mikeyyyzhao
Copy link

Hi @msand I tried the code and it still crashed. Here's the exact code that I ran:

`
import React, { Component } from 'react';

import { StyleSheet, View } from 'react-native';

import Svg, { G, Path, Text, TSpan } from 'react-native-svg';

const ForwardButton = props => (

<Svg width={300} height={320} viewBox="0 0 32 32" {...props}>

<G fill="none" fillRule="evenodd">
  <Path
    d="M3,17.5c0 7.456 6.044 13.5 13.5 13.5s13.5-6.044 13.5-13.5c0-3.216-1.125-6.17-3.002-8.489a13.474 13.474 0 0 0-10.498-5.011h-12.077"
    stroke="#FF1D4F"
    strokeWidth={2}
  />
  <Path stroke="#FF1F50" fill="#FF1D4F" d="M1,5.5l5-4.5v9z" />
  <Text
    fontFamily="Raleway-Bold, Raleway"
    fontSize={12}
    fontWeight="bold"
    letterSpacing={1}
    fill="#FF1E4F"
  >
    <TSpan x={10} y={20}>
      {`15`}
    </TSpan>
  </Text>
</G>

);

export default ForwardButton;

`

@msand
Copy link
Collaborator

msand commented Apr 23, 2019

Try changing letterSpacing={1} to letterSpacing="1"

@mikeyyyzhao
Copy link

It worked and didn't crash this time! Thanks for your help @msand!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants