How to increase svg width based on text
See original GitHub issueI’m using this component in my app in many places. recently i found some difficulty with the usage. if i have long text the width of the svg must be adjustable based on the text and the text must be in the center of the box. For suppose
My code is something like below
<View style={{marginTop: 50,width:'100%', height: 50, justifyContent: 'center', alignItems: 'center', flexDirection:'row'}}> <Svg width={200} height={50} style={{backgroundColor:'yellow'}}> <SvgLinearGradient id="Gradient" x1="0%" x2="100%" y1="0%" y2="0%"> <Stop stopColor="#C2515D" offset="0%"/> <Stop stopColor="#853C5E" offset="100%"/> </SvgLinearGradient> <Text fill="url(#Gradient)" x="50" y="20" fontSize="18" fontWeight="700" textAnchor="start" > hi hello hi hih hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi hi i hi </Text> </Svg> </View>
here based on the text the width of the svg must be increased how?
Issue Analytics
- State:
- Created 5 years ago
- Comments:19
Top GitHub Comments
Slightly more involved version:
I tried to write this example with hooks and TS. But I’m getting this error in the tag
<Text>
and<Svg>
I need to change the font size to adjust it to the size of the container.