Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

translate on Y using SectionList and header view creating empty space on scroll - react native

i'm new in react native and Animated API, so what i'm trying to do a simple parallax header and Animated SectionList like this

empty space on bottom while scrolling

my code is

export default class Edit extends Component {

constructor(props) {
    super(props)

    this.state = {
        fullName: '',
        scrollEnabled: true,
        scrollY: new Animated.Value(0),
    }
}

_renderSectionHeader(section){
    return <View style={[styles.SectionHeaderViewStyle]}><Text style={styles.SectionHeaderStyle}> {section.title} </Text></View>;
}

_renderItem(item){
    return  <View><TextFieldValidate /></View>;
}
_onScroll(event) {
    // console.log(event.nativeEvent.contentOffset.y);
}

render() {

    const backgroundScrollY = this.state.scrollY.interpolate({
        inputRange: [0, 224],
        outputRange: [0, -170],
        extrapolate: 'clamp',
    });

    const listScrollY = this.state.scrollY.interpolate({
        inputRange: [0, 224],
        outputRange: [0, -170],
        extrapolate: 'clamp',
    });

    const infoOpacity = this.state.scrollY.interpolate({
        inputRange: [0, 0.5, 150],
        outputRange: [1, 1, 0],
        extrapolate: 'clamp',
    });


    const AnimatedSectionList = Animated.createAnimatedComponent(SectionList)

    return (

        <View style={{flex: 1}}>
            <View style={{position: 'relative', height: 224, justifyContent: 'center', alignItems: 'center'}}>
                <Animated.Image source={Images.profileEdit} style={[styles.background, {transform: [{translateY: backgroundScrollY}]}]} blurRadius={1.5}/>
                <Text style={styles.fullNameHeader}>Steve Smith</Text>
                <Animated.View style={{opacity: infoOpacity, position: 'relative', justifyContent: 'center', alignItems: 'center'}}>
                    <AnimatedCircularProgress size={76} width={4} fill={50} rotation={0} tintColor={Colors.cyan} backgroundColor={Colors.white}>
                        {
                            (fill) => (
                                <Image source={require('./img/details_icon.png')}/>
                            )
                        }
                    </AnimatedCircularProgress>
                    <Text style={styles.communityNameHeader}>Jumeirah Village Circle</Text>
                    <Text style={styles.profileCompletionHeader}>50% Profile Completion</Text>
                </Animated.View>
            </View>


            <AnimatedSectionList
                bounces={false}
                scrollEnabled={this.state.scrollEnabled}
                style={[{position: 'relative'}, {transform: [{translateY: listScrollY}]}]}
                onScroll={
                    Animated.event(
                        [{nativeEvent: {contentOffset: {y: (this.state.scrollY)}}}],
                        {useNativeDriver: true, listener: this._onScroll.bind(this)}
                    )
                }
                sections={[
                    {title: 'MY DETAILS', data: myDetailsFields},
                    {title: 'MY COMMUNITY', data: myCommunity},
                    {title: 'MY FAMILY', data: myFamily},
                ]}

                renderSectionHeader={({section}) => this._renderSectionHeader(section)}

                renderItem={({item}) => this._renderItem(item)}

                keyExtractor={(item, index) => index}

                stickySectionHeadersEnabled={true}

            />

        </View>

    );
  }
}

please any help to remove the bottom white space when scrolling i tried paddingBottom:950 in the "AnimatedSectionList" style but it missed up the keyboard viewing and scrolling

style={[{position: 'relative'}, {paddingBottom:950}, {transform: [{translateY: listScrollY}]}]}

AFTER ADDING marginBottom

enter image description here

like image 613
Fadi Avatar asked Mar 28 '18 18:03

Fadi


1 Answers

if any one interested in the Answer i just added "marginBottom:-170" to the AnimatedSectionList instead of "paddingBottom:950"

style={[{position: 'relative'}, {marginBottom:-170}, {backgroundColor:'blue'}, {transform: [{translateY: listScrollY}]}]}
like image 116
Fadi Avatar answered Nov 09 '22 20:11

Fadi