Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fade the edge of a View in react native?

Example 1

Example 2

How to fade the edge of a View like the above images in react native?

like image 959
longsangstan Avatar asked Feb 06 '18 19:02

longsangstan


People also ask

How do you make a gradient in react native?

... <LinearGradient colors={['red', 'yellow', 'green' ]} style={styles. linearGradient} start={{ x: 0, y: 0.5 }} end={{ x: 1, y: 0.5 }} locations={[0, 0.7, 0.9]} > <Text>H. Location Gradient</Text> </LinearGradient> <LinearGradient colors={['red', 'yellow', 'green' ]} style={styles.

How do you add a linear gradient in react native?

Right click on Libraries and click Add Files to "Your Project Name" . Look under node_modules/react-native-linear-gradient/ios and add BVLinearGradient.


2 Answers

I know this post is old but for anyone looking at this now, you can set a fadingEdgeLength on your ScrollView like this to achieve that effect. Note that it only works for Android though. For example:

<ScrollView fadingEdgeLength={100}>
  ... scroll view content ...
</ScrollView>
like image 152
Ryker Avatar answered Sep 21 '22 00:09

Ryker


On iOS, you can use the MaskedViewIOS component to create an transparent alpha mask for the fading effect.

For the fading gradient itself, you can either use something like react-native-linear-gradient (which is also built into Expo) or a semi-transparent image (black pixels will show content through, transparent pixels will block masked content).

<MaskedViewIOS 
  maskElement={
    <LinearGradient colors={['black', 'transparent']} />
  }
>
  <YourContent />
</MaskedViewIOS>

Here is an example on Snack.

Unfortunately, MaskedView is not yet implemented on Android. I'm not aware of a simple way of implementing this, but would be happy to be proven wrong.

like image 45
jevakallio Avatar answered Sep 22 '22 00:09

jevakallio