I want to have some words of Text in linear gradient color. check desired output
To achieve gradient text I am doing -
import React from 'react';
import {Text} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import MaskedView from '@react-native-masked-view/masked-view';
const GradientText = props => {
return (
<MaskedView maskElement={<Text {...props} />}>
<LinearGradient
colors={['red', 'green', 'blue']}
start={{x: 0, y: 0}}
end={{x: 1, y: 0}}>
<Text {...props} style={[props.style, {opacity: 0}]} />
</LinearGradient>
</MaskedView>
);
};
export default GradientText;
When wrapping inside is not giving the required result -
<Text style={{color: 'white'}}>
hello
<GradientText>Gradient Text here</GradientText>
</Text>
Flex is not helpful as multi-line sentence is not achievable using that.
Attached image of the desired output. Please help
Modify the
GradientTextcomponent to accept children and apply the gradient to each character individually.Here is working example: