React Native : textShadow not rendering well on sides

1.6k views Asked by At

I have troubles to use textShadow propriety as expected. Here is my code :

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

class Test extends React.Component {
  
  render() {
    return (
      <View style={styles.main_container}>
         <Text style={}>Some textooo</Text>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  main_container: {
    flex: 1,
    justifyContent:'center',
    alignItems:'center',
  },
  text: {
    fontSize: 30, 
    fontWeight: '900', 
    textShadowColor: 'rgba(0, 0, 0, 0.8)', 
    textShadowOffset: { width: 0, height: 0 },
    textShadowRadius: 10,
}

 
})

export default Test

Here is how it renders :

Text with shadow

As you can notice, shadow is cut at the beginning and at the end of the text...

Does anyone knows how to avoid this? (Without adding " " in the string to render)

Thank you very much for your help.

3

There are 3 answers

4
MUHAMMAD ILYAS On

Here is a working example of your code https://snack.expo.io/@jsfit/text-shadow seems good to me

enter image description here

0
Jeff Pai On

Adding empty space at the end seems to fix it for me.

0
Ali Pouris On

give Text component width and height then align the text

textAlign: 'center',
textAlignVertical: 'center'
  text: {
    fontSize: 30, 
    fontWeight: '900', 
    textShadowColor: 'rgba(0, 0, 0, 0.8)', 
    textShadowOffset: { width: 0, height: 0 },
    textShadowRadius: 10,

    //add this styles
    width:100,
    height: 100,
    textAlign: 'center',
    textAlignVertical: 'center'
}