1.1.0 • Published 7 years ago

react-native-scroll-to-top v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

react-native-scroll-to-top

A React Native component to scroll back to top

preview

Installation

  • npm install react-native-scroll-to-top --save
  • import ScrollToTop from 'react-native-scroll-to-top' or var ScrollToTop = require('react-native-scroll-to-top')

    Available Props

    PropertyTypeDefaultDescription
    rootViewobjectThis prop is required. You must pass a ref of the root view. This will be used to scroll to the top.
    ListViewboolfalsetrue if your List is a ListView, false if your List is a FlatList.
    backgroundColorstringnullBackground color of the view
    borderRadiusnumber30Border radius for the view
    colorstring#ffffffColor of the view
    fontSizenumber12Font size of Text element
    iconelementnullIcon button
    isRadiusbooltrueIf the view is a round view
    leftnumberDimensions.get('window').width - 80Number of logical pixels to offset the left edge of this component.
    textstringScroll to TopIf icon is null. This props will be displayed.
    topnumberDimensions.get('window').width - 170Number of logical pixels to offset the top edge of this component.
    widthnumber60Width of the view

Example

import React, { Component } from 'react';
import { AppRegistry, ListView, StyleSheet, Text, View, TouchableOpacity  } from 'react-native';
import ScrollToTop from 'react-native-scroll-to-top'

class ScrollToTop extends Component {
  constructor() {
    super();
    const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
    this.state = {
      dataSource: ds.cloneWithRows(['row 1', 'row 2', 'row 1', 'row 2', 'row 1', 'row 2', 'row 1', 'row 2', 'row 1', 'row 2', 
      'row 1', 'row 2','row 1', 'row 2','row 1', 'row 2','row 1', 'row 2','row 1', 'row 2','row 1', 'row 2','row 1', 'row 2'
      ]),
    };
  }

  render() {
    return (
      <View>
      <ListView
        ref={(listview) => {
            this.listview = listview;
          }}
        dataSource={this.state.dataSource}
        renderRow={(rowData) => <Text style={styles.text}>{rowData}</Text>}
      />
      <ScrollToTop
          ListView
          rootView={this.listview}
      />
      </View>
    );
  }
}
const styles = StyleSheet.create({
  container: {
      padding: 10,
      marginTop: 3,
      backgroundColor: '#d9f9b1',
      alignItems: 'center',
   },
   text: {
     paddingVertical: 15,
     alignSelf: 'center',
     color: '#4f603c'
   }
})

export default ScrollToTop;