Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native: Fade ScrollView bottom

I'm trying to implement a ScrollView list that fades out the bottom items in the list. This is achievable by monitoring the scroll position, determining the layout of each item and then adding opacity to each item ~ Even then, it won't achieve a smooth fade as each item will have a fixed opacity.

I'm wondering if there is a more graceful and cleaner way to achieve this?

like image 962
Anshul Koka Avatar asked Aug 24 '17 14:08

Anshul Koka


People also ask

How to fix ScrollView is not scrolling to the bottom in React Native?

to set contentContainerStyle to { paddingBottom: 60 } to add 60px of bottom padding on the ScrollView. To fix ScrollView is not scrolling to the bottom sometimes issue with React Native, we can set the contentContainerStyle to add some bottom padding.

What is React Native fade out opacity on Android?

Home Online Android Emulator Online iOS Emulator CONTRIBUTE YOUR CODE Suggest Us Tutorial React Native Fade In Fade Out Opacity Animation Android iOS Example adminSeptember 29, 2019September 29, 2019React Native Opacity style is used to control visibility of a particular component in react native.

How to render a smooth Fadeout in ScrollView?

Use LinearGradient from expo to render a smooth fadeout. If ScrollView has touchable item, add prop 'pointerEvents= {'none'}' to LinearGradient.

What are fading edges in Scroll View?

Fades out the edges of the the scroll content. If the value is greater than 0, the fading edges will be set accordingly to the current scroll direction and position, indicating if there is more content to show. When true, the scroll view's children are arranged horizontally in a row instead of vertically in a column.


2 Answers

  1. Use LinearGradient from expo to render a smooth fadeout.
  2. If ScrollView has touchable item, add prop 'pointerEvents={'none'}' to LinearGradient. It can bypass touch events to ScrollView.

    import {LinearGradient} from 'expo';
    
    <View style={{width:100, height:100, backgroundColor:'#fff'}}>
      <ScrollView />
      <LinearGradient
        style={{position:'absolute', bottom:0, width:100, height:20}}
        colors={['rgba(255, 255, 255, 0.1)', 'rgba(255, 255, 255, 0.8)']}
        pointerEvents={'none'}
      />
    </View>
    

edit:

  1. If it is dynamic images, maybe you can try the backgroundColor of image's parent. The following example is black, so use black LinearGradient.

    <View style={{flex:1, backgroundColor:'#000'}}>
      <ImageBackground
        style={{flex:1}}
        source={{uri:'https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?cs=srgb&dl=beauty-bloom-blue-67636.jpg&fm=jpg'}}
      >
        <LinearGradient
          style={{flex:1}}
          locations={[0.7, 0.9, 1]}
          colors={['rgba(0, 0, 0, 0)', 'rgba(0, 0, 0, 0.1)', 'rgba(0, 0, 0, 0.5)']}
          pointerEvents={'none'}
        />
      </ImageBackground>
    </View>
    
like image 76
Dwyane Lin Avatar answered Oct 11 '22 05:10

Dwyane Lin


There is package for achieving fade effects in ScrollView.

rn-faded-scrollview does work good.

 <RNFadedScrollView
    allowStartFade={true}
    allowEndFade={true}
    bounces={false}
    horizontal={true}
     >
 </RNFadedScrollView>

Hope this helps.

like image 1
Abdul Kawee Avatar answered Oct 11 '22 07:10

Abdul Kawee