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

React native 0.60.5 version error #31

Open
ewu-tarun opened this issue Aug 14, 2019 · 18 comments
Open

React native 0.60.5 version error #31

ewu-tarun opened this issue Aug 14, 2019 · 18 comments

Comments

@ewu-tarun
Copy link

ewu-tarun commented Aug 14, 2019

@iyegoroff, When I used the react-native-text-gradient library. it shows this error "Text strings must be rendered within a component". it was working fine in the previous react-native version library. when I update the react-native version it shows this error. note I run the patch-rn.js command.

@ewu-tarun ewu-tarun changed the title React native 0.60.5 error React native 0.60.5 version error Aug 14, 2019
@iyegoroff
Copy link
Owner

When I used rntg last time - my rn version was 0.59.10. So there is a chance that patch-rn.js script will fail to patch latest versions of react native sources.

@imimoises
Copy link

not working for me either, It says "Text strings must be rendered within a component"

yet If I don't include a text string as children in the component, it says "No component found for view with name "RNLinearTextGradient""

@ewu-tarun
Copy link
Author

@iyegoroff is there any possibility to update this library?

@iyegoroff
Copy link
Owner

@TarunDas005, sure! If you have fixed this issue for yourself - you can submit a PR to this repo.

@karengharibyan
Copy link

create js file , put this inside

#!/usr/bin/env node

const { writeFile, readFile, readdir } = require('fs');
const { promisify } = require('util');
const path = require('path');

const folder = 'node_modules/react-native/Libraries/Renderer/oss/';

const pattern = new RegExp(
'throw ReactError'+
'\('+'[\s\S]{0,20}' +
'"Text strings must be rendered within a component\."[\s\S]{0,20}' +
'\)[;,]'
);

const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern,'');
await promisify(writeFile)(file, patched);
};

const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};

patchAll();

and run

@pragneshpj
Copy link

same error in 60.5.
this package is working properly before.
@iyegoroff can you please update package with rn 60.5

@ChrisCodeCole
Copy link

ChrisCodeCole commented Sep 20, 2019

create js file , put this inside

#!/usr/bin/env node

const { writeFile, readFile, readdir } = require('fs');
const { promisify } = require('util');
const path = require('path');

const folder = 'node_modules/react-native/Libraries/Renderer/oss/';

const pattern = new RegExp(
'throw ReactError'+
'('+'[\s\S]{0,20}' +
'"Text strings must be rendered within a component."[\s\S]{0,20}' +
')[;,]'
);

const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern,'');
await promisify(writeFile)(file, patched);
};

const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};

patchAll();

and run

It does look like the patch needs to be updated with rn 60.0+ since all the files in this directory did get updated (node_modules/react-native/Libraries/Renderer/oss/)

This patch posted here didn't work for me, the regex doesn't match. The regex string should include at least a "<Text>" in it. I tried looking at it for awhile and couldn't get the regex to match so that I can update these files. I also haven't used NodeJS so I'm wondering if there is a better way.

Pattern I was using that doesn't work below:
const pattern = new RegExp(
'throw ReactError'+
'([\s\S]{0,20}' +
'"Text strings must be rendered within a <Text> component."[\s\S]{0,20}' +
')[;,]'
);

Example of string I'm trying to match below:
throw ReactError(
"Text strings must be rendered within a <Text> component."
);

Edit: I see now that you have to escape the < with a "\" in GitHub for the text to be visible, so <Text> was probably included in the patch mentioned above at some point. Maybe there were other escaped characters missing in that post?

@L-x-C
Copy link

L-x-C commented Sep 27, 2019

create js file , put this inside

#!/usr/bin/env node

const { writeFile, readFile, readdir } = require('fs');
const { promisify } = require('util');
const path = require('path');

const folder = 'node_modules/react-native/Libraries/Renderer/oss/';

const pattern = new RegExp(
'throw ReactError'+
'('+'[\s\S]{0,20}' +
'"Text strings must be rendered within a component."[\s\S]{0,20}' +
')[;,]'
);

const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern,'');
await promisify(writeFile)(file, patched);
};

const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};

patchAll();

and run

there is no oss/ in RN 0.61.1
image

@ChrisCodeCole
Copy link

ChrisCodeCole commented Sep 27, 2019

create js file , put this inside
#!/usr/bin/env node
const { writeFile, readFile, readdir } = require('fs');
const { promisify } = require('util');
const path = require('path');
const folder = 'node_modules/react-native/Libraries/Renderer/oss/';
const pattern = new RegExp(
'throw ReactError'+
'('+'[\s\S]{0,20}' +
'"Text strings must be rendered within a component."[\s\S]{0,20}' +
')[;,]'
);
const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern,'');
await promisify(writeFile)(file, patched);
};
const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};
patchAll();
and run

there is no oss/ in RN 0.61.1
image

You're correct. The files that are being used to throw the text string error are within "node_modules\react-native\Libraries\Renderer\implementations" now in 0.61. I'm still not able to find the error with the regex.

@L-x-C
Copy link

L-x-C commented Sep 29, 2019

create js file , put this inside
#!/usr/bin/env node
const { writeFile, readFile, readdir } = require('fs');
const { promisify } = require('util');
const path = require('path');
const folder = 'node_modules/react-native/Libraries/Renderer/oss/';
const pattern = new RegExp(
'throw ReactError'+
'('+'[\s\S]{0,20}' +
'"Text strings must be rendered within a component."[\s\S]{0,20}' +
')[;,]'
);
const patchFile = async (file) => {
const content = (await promisify(readFile)(file)).toString();
const patched = content.replace(pattern,'');
await promisify(writeFile)(file, patched);
};
const patchAll = async () => {
const files = await promisify(readdir)(folder);
await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};
patchAll();
and run

there is no oss/ in RN 0.61.1
image

You're correct. The files that are being used to throw the text string error are within "node_modules\react-native\Libraries\Renderer\implementations" now in 0.61. I'm still not able to find the error with the regex.

const pattern = new RegExp(
  'throw ReactError[\\s\\S]{0,80}Text strings must be rendered within a <Text> component[\\s\\S]{0,80}[^()]\\)[;,]'
, 'gm');

this will work!

@ChrisCodeCole
Copy link

thanks, that did it for me :D. hopefully they add in the fix some day to the actual react native project..

@ChrisCodeCole
Copy link

ChrisCodeCole commented Oct 8, 2019

@L-x-C had to change the replace function a bit, since it worked in development but not release..
going to put this here in case someone else comes across this issue:

const patched = content.replace(pattern,() => {
        //dev files just need an empty string
        //every other file (production & profiling) needs {} to scope IF statements in order to work
        const fileRegEx = new RegExp('dev');
        
        if(fileRegEx.test(file))
            return ''
        else
            return '{}';
    });

@anagar23
Copy link

@L-x-C , @ChrisCodeCole I tried the solution but it doesn't work.

@Suraj-Tiwari
Copy link

solutions are divided in multiple comments, so here is a complete solution thanks to @ChrisCodeCole and @L-x-C

i'm on react-native v0.61.2 that's why my directory path is :
node_modules/react-native/Libraries/Renderer/implementations/
for older versions it's :
node_modules/react-native/Libraries/Renderer/oss/

#!/usr/bin/env node

const {writeFile, readFile, readdir} = require('fs');
const {promisify} = require('util');
const path = require('path');

const folder = 'node_modules/react-native/Libraries/Renderer/implementations/';

const pattern = new RegExp(
    'throw ReactError[\\s\\S]{0,80}Text strings must be rendered within a <Text> component[\\s\\S]{0,80}[^()]\\)[;,]'
    , 'gm');

const patchFile = async (file) => {
    const content = (await promisify(readFile)(file)).toString();
    const patched = content.replace(pattern, () => {
        const fileRegEx = new RegExp('dev');
        if (fileRegEx.test(file))
            return '';
        else
            return '{}';
    });
    await promisify(writeFile)(file, patched);
};

const patchAll = async () => {
    const files = await promisify(readdir)(folder);

    await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};

patchAll();

@rewdt
Copy link

rewdt commented Dec 30, 2019

solutions are divided in multiple comments, so here is a complete solution thanks to @ChrisCodeCole and @L-x-C

i'm on react-native v0.61.2 that's why my directory path is :
node_modules/react-native/Libraries/Renderer/implementations/
for older versions it's :
node_modules/react-native/Libraries/Renderer/oss/

#!/usr/bin/env node

const {writeFile, readFile, readdir} = require('fs');
const {promisify} = require('util');
const path = require('path');

const folder = 'node_modules/react-native/Libraries/Renderer/implementations/';

const pattern = new RegExp(
    'throw ReactError[\\s\\S]{0,80}Text strings must be rendered within a <Text> component[\\s\\S]{0,80}[^()]\\)[;,]'
    , 'gm');

const patchFile = async (file) => {
    const content = (await promisify(readFile)(file)).toString();
    const patched = content.replace(pattern, () => {
        const fileRegEx = new RegExp('dev');
        if (fileRegEx.test(file))
            return '';
        else
            return '{}';
    });
    await promisify(writeFile)(file, patched);
};

const patchAll = async () => {
    const files = await promisify(readdir)(folder);

    await Promise.all(files.map(file => path.join(folder, file)).map(patchFile));
};

patchAll();

This is not working for rn-0.61.4. I am now getting an error saying "No component found for view with name RNLinearTextGradient after applying the patch. Has anybody solved this ?

@vonbarnekowa
Copy link

Any updates?

@fukemy
Copy link

fukemy commented May 27, 2022

still got this problem with newest react native, decided to removed this lib

@KrishEnacton
Copy link

Simply you can use this

// GradientText.js
import React from 'react';
import {Text} from 'react-native';
import MaskedView from '@react-native-community/masked-view';
import LinearGradient from 'react-native-linear-gradient';

const GradientText = ({colors, ...rest}) => {
  return (
    <MaskedView maskElement={<Text {...rest} />}>
      <LinearGradient colors={colors} start={{x: 0, y: 0}} end={{x: 1, y: 0}}>
        <Text {...rest} style={[rest.style, {opacity: 0}]} />
      </LinearGradient>
    </MaskedView>
  );
};

export default GradientText;

// App.js
import React from 'react';
import {SafeAreaView, StyleSheet} from 'react-native';
import GradientText from './GradientText';

const App = () => {
  return (
    <SafeAreaView style={styles.container}>
      <GradientText colors={['#cc2b5e', '#753a88']} style={styles.text}>
        GRADIENT TEXT
      </GradientText>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    fontSize: 35,
    fontFamily: 'Gill Sans',
    fontWeight: 'bold',
  },
});

export default App;

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