iyegoroff / react-native-text-gradient

Text gradient for React-Native (ON HIATUS)
MIT License
97 stars 32 forks source link

Showing error 'Text strings must be rendered within a <Text> component' #23

Closed saikiranoptisol closed 5 years ago

saikiranoptisol commented 5 years ago

After creating .apk file and install in my android device i got this error 'Text strings must be rendered with in a text component'. I have used the patch that is in the document before creating offline bundle. Still the issue is happening and the app continuosuly crashes in IOS. Any work around for this issue.

yasirdev commented 5 years ago

+1

Balasnest commented 5 years ago

Facing this exact issue in react native 0.57. @iyegoroff any workaround for this? Please help. Got stuck badly on this.

rkdavidson commented 5 years ago

+1, using "react-native": "0.57.7" and seeing this error even when using exact usage instructions:

Using:

<LinearTextGradient
  style={{ fontWeight: 'bold', fontSize: 72 }}
  locations={[0, 1]}
  colors={['red', 'blue']}
  start={{ x: 0, y: 0 }}
  end={{ x: 1, y: 0 }}
>
  THIS IS TEXT GRADIENT
</LinearTextGradient>

Produces:

Invariant Violation: Text strings must be rendered within a <Text> component.

This error is located at:
    in RNLinearTextGradient (at create-text-gradient-class.js:140)
    in TouchableTextGradient (at create-text-gradient-class.js:265)
    in RCTView (at View.js:45)
    in RCTView (at View.js:45)
    in RCTView (at View.js:45)
    in RCTView (at View.js:45)
    in CoreActionCard (at core-action-card.stories.js:44)
...
rkdavidson commented 5 years ago

Update to my comment above

Hey @Balasnest @yasirdev @saikiranoptisol , follow the instructions in the readme for applying the patch: https://github.com/iyegoroff/react-native-text-gradient#usage-with-rn--0560

I got it to work, albeit with the temporary patch workaround. I bumped @iyegoroff 's PR #13211 against react codebase to hopefully get this truly fixed soon.

Couple things to double check:

  1. Make sure you've run react-native link react-native-text-gradient (or followed the manual instructions)
  2. Run the temporary patch: node node_modules/react-native-text-gradient/patch-rn.js
Balasnest commented 5 years ago

@yasirdev @saikiranoptisol @rkdavidson And the better way is to add it in the package.json file rather than executing manually after npm install. We might forget to do this later whenever we remove node_modules.

postinstall:"node node_modules/react-native-text-gradient/patch-rn.js"

saikiranoptisol commented 5 years ago

During development it works fine for me. But my problem is when i create offline bundle for Andorid and IOS it is coming for me that error. After creating offiline bundle i cant do npm install or patch also

rkdavidson commented 5 years ago

@Balasnest Good tip 👍

@saikiranoptisol You could fork the repo and manually apply the patch in an npm scoped way, i.e. @saikiranoptisol/react-native-text-gradient, until facebook's PR is merged.

Balasnest commented 5 years ago

@saikiranoptisol Exactly. Not working on release build. Did you do any workaround for this?

During development it works fine for me. But my problem is when i create offline bundle for Andorid and IOS it is coming for me that error. After creating offiline bundle i cant do npm install or patch also

Balasnest commented 5 years ago

@rkdavidson How to do this? Any idea? My release is got stuck due to this 😞

@iyegoroff could you help us, please! How can we make it work in a release build?

rkdavidson commented 5 years ago

@Balasnest Haven't tried release build yet or verified on Android — this is part of an experimental side branch on my project, so has been a bit isolated from user-facing stuff. I'll report back though as this is coming up again.

To anyone reading this thread, the onus is on the react maintainers to merge this PR: https://github.com/facebook/react/pull/13211

So maybe it will help to bump that thread?

elyngved commented 5 years ago

Hi! Trying to use this in my app as well. Is there a possible workaround to pass the text via a prop instead?

iyegoroff commented 5 years ago

@elyngved I'm not sure if this will work and don't think that changing API in this way is a good idea, because rntg is meant to be a "drop-in replacement for standard Text component". Probably the right way to resolve this issue is to investigate why the patch script doesn't work for you as intended.

jchenx2 commented 5 years ago

@saikiranoptisol Exactly. Not working on release build. Did you do any workaround for this?

During development it works fine for me. But my problem is when i create offline bundle for Andorid and IOS it is coming for me that error. After creating offiline bundle i cant do npm install or patch also

is there any idea for release build

iyegoroff commented 5 years ago

I just updated react-native to 0.58.6 version in example app and generated release apk with Docker. The patch script worked as intended and I didn't get any errors while running the app. Until https://github.com/facebook/react/pull/13211/ is merged there is no other way to avoid this error except patching react-native. If the script doesn't work for your environment for some reason - you have to fix it or patch your react-native sources manually.

bony06aug commented 5 years ago

still, issue exists Simulator Screen Shot - iPhone X - 2019-08-09 at 15 20 15 of Invariant Violation: Text strings must be rendered within a component.

rkdavidson commented 5 years ago

@jchenx2 @bony06aug If you add this line to your package.json, patching becomes an automatic part of builds:

postinstall:"node node_modules/react-native-text-gradient/patch-rn.js"

(Or modify your existing postinstall script)

kevinpiske commented 4 years ago

Still happens, the patch doesn't work anymore

kevinpiske commented 4 years ago

Using the Text component around the string works on Android. On iOS the gradient wasn't rendered, I'm not sure if it was due to this change.

<LinearTextGradient
  style={{ fontWeight: 'bold', fontSize: 72 }}
  locations={[0, 1]}
  colors={['red', 'blue']}
  start={{ x: 0, y: 0 }}
  end={{ x: 1, y: 0 }}
>
  <Text>THIS IS TEXT GRADIENT</Text>
</LinearTextGradient>
tomhagen commented 4 years ago

Using the Text component around the string works on Android. On iOS the gradient wasn't rendered, I'm not sure if it was due to this change.

<LinearTextGradient
  style={{ fontWeight: 'bold', fontSize: 72 }}
  locations={[0, 1]}
  colors={['red', 'blue']}
  start={{ x: 0, y: 0 }}
  end={{ x: 1, y: 0 }}
>
  <Text>THIS IS TEXT GRADIENT</Text>
</LinearTextGradient>

DO YOU HAVE ANY UPDATE ON THIS ? I still face this problem exactly as you said

kevinpiske commented 4 years ago

@tomhagen,

I abandoned the gradient texts, but you can try other approaches. You can use the react-native-svg or react-native-masked-view libraries. You can also directly use an image with the gradient text.

https://github.com/react-native-community/react-native-svg https://github.com/react-native-community/react-native-masked-view