1.3.0 • Published 9 years ago

rn-header v1.3.0

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

RN-Header

Can Use the header as a stand alone header, or a scroll away header.

You must have react-native-vector-icons installed and linked for this to display icons on the header. Can also display text on the sides of header

Uses Font Awesome icons as the icon source

npm install react-native-vector-icons --save
react-native link react-native-vector-icons
npm install rn-header --save
  • To use as a scroll away header takes a little work to set up.
  • import Animated from react-native
  • Add an Animated.Value to the constructor. Need a scrollY so the Header can respond properly
  • Can use with Listview or ScrollView.
  • SET UP THE ONSCROLL PROP TO MATCH THIS EXAMPLE
  • If you don't use scrollEventThrottle you're gonna have a bad time...mmmm-kay??
  • just copy/paste this example and you'll get the hang of it 🤓
  • When using as a scroll away header, wrap whatever content you want to stay within the <Header> </Header> tags. When using as a stand alone Header, just use as <Header/>

If you do not want the header to scroll away, do not supply the header with the scrollY

gif

'use strict'

import React, { Component } from 'react';
import {
View,
Text,
ScrollView,
Animated
} from 'react-native';

import Header from 'rn-header';


export default class Example extends Component {
 constructor(){
   super();
   this.scrollY = new Animated.Value(0)
 };


 render(){
   let things = ['Watch','The','Header','Scroll','Away','As','I','Move'].map((opt,i) => {
     return(
       <View
         key={i}
         style={{
           marginTop:60,
           backgroundColor:'deeppink',
           paddingLeft:20
         }}>
         <Text style={{fontSize:33}}>{opt}</Text>
       </View>
     )
   });
   return(
     <View style={{
       flex:1,
       backgroundColor:'yellow'
     }}>
       <Header
         scrollY={this.scrollY}
         backgroundColor={'blue'}
         height={60}
         centerText={'Scroll Away'}
         rightIconProps={{
           name:'cogs',
           size:25,
           color:'white'
         }}
         onRightPress={
           () => console.log('Stuff')
          }
         centerTextProps={{
           fontSize:20,
           color:'white',
           fontWeight:'500'
         }}>

         <View style={{
           height:200,
           backgroundColor:'red',
           alignItems:'center',
           justifyContent:'center'
         }}>
           <Text style={{
             color:'white',
             fontSize:23,
             textAlign: 'center'
           }}>Watch me stay after the header goes away!</Text>
         </View>
       </Header>

       <ScrollView
         scrollEventThrottle={16}
         onScroll={
           // this maps the onScroll event to the scrollY variable declared in the constructor.  Now the header has a reference to the scrolling and can respond properly
           Animated.event(
           [{nativeEvent: {contentOffset: {y:  this.scrollY }}}]
           )
         }

         {things}
       </ScrollView>
     </View>
   )
 };

};

All props

PropTypeDescriptionRequired
backgroundColorstringbackgroundColor of the HeaderYES
heightnumberheight of the HeaderYES
centerTextstringText to display in the centerno
centerTextPropsText Propsany valid Text propsno
onCenterPressfunctionwhat to do on center press....like scroll to top or show a pop-upno
onRightPressfunctionwhat to do on right pressno
onLeftPressfunctionwhat to do on right pressno
leftTextPropsText Propsany valid Text Propsno
leftIconPropsIcon Propsany valid Icon Propsno
rightTextPropsText Propsany valid Text Propsno
rightIconPropsIcon Propsany valid Icon propsno
1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.7

9 years ago

1.1.6

9 years ago

1.1.5

9 years ago

1.1.4

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago