Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - render shadow on view border not on content

Tags:

react-native

I am having problem. I want to add shadows to the border of a view, like here: https://github.com/styled-components/styled-components/issues/709

I have tried with styled-components and with normal style prop.

I currently have:

const shadow = {
  shadowOffset:{  width: 10,  height: 10,  },
  shadowColor: 'black',
  shadowOpacity: 1.0,
  shadowRadius: 8,
};

...

<View style={shadow}>
  <TotalText>SALDO</TotalText>
  <MoneyText>R$ 1.000,00</MoneyText>
  <NextAllowanceText>PRÓXIMA MESADA</NextAllowanceText>
</View>

This is the output: https://ibb.co/b6xOYp

I want the shadow to be applied to the border and not the content inside, what am I missing?

like image 522
jgfidelis Avatar asked Oct 09 '18 03:10

jgfidelis


People also ask

How do you add shadow to a view in React Native?

For adding box shadows in Android, we can use the elevation prop, which uses the Android Elevation API. Next, import the StyleSheet again to style the card: // remember to import StyleSheet from react-native const styles = StyleSheet.

How do you give bottom shadow to view in React Native?

To set elevation shadow only on the bottom on React Native, we wrap out View with another View and set its overflow to 'hidden' . to set overflow to 'hidden' on the outer View . And then we add the shadow styles in the inner view to add the shadow. elevation is needed for Android to show the shadow.

How do you add shadow to text in React Native?

To add text shadow in React Native, we can set some text shadow styles. to set the textShadowColor to the text shadow color. We set textShadowOffset to add depth to the shadow. And we set textShadowRadius to set the shadow radius.

How to set elevation shadow only on the bottom on React Native?

To set elevation shadow only on the bottom on React Native, we wrap out View with another View and set its overflow to 'hidden'. to set overflow to 'hidden' on the outer View. And then we add the shadow styles in the inner view to add the shadow. elevation is needed for Android to show the shadow.

How to set border around view component in React Native?

To set border around view component in react native we have to use borderWidth and borderColor style prop. Using the borderWidth prop we would define the border width in pixels.

What is a renderer in React Native?

At a high level, React Native renderer creates a corresponding Host View for each React Shadow Node and mounts it on screen. In the example above, the renderer creates an instance of android.view.ViewGroup for the <View> and android.widget.TextView for <Text> and populates it with “Hello World”.

What is the React-Native-drop-shadow package in React Native?

The react-native-drop-shadow package is a View component that takes its nested component, creates a bitmap representation, then blurs and colors it to the style’s shadow values, similar to applying shadows in iOS with the shadow props. To get started, install the react-native-drop-shadow package using one of the following commands:


Video Answer


1 Answers

Try setting the background colour of the view to white - backgroundColor: 'white'

like image 102
Barry Gough Avatar answered Oct 21 '22 09:10

Barry Gough