Giter VIP home page Giter VIP logo

react-navigation-collapsible's Introduction

react-navigation-collapsible

npm npm

React Navigation Extension for Collapsible Header. Make your header of react-navigation collapsible.

Try Expo Snack

Try Example.

$ cd example
$ npm install
$ react-native run-ios
$ react-native run-android

Usage

Expo

If you use Expo, add this lines in your App.js. (It only affects Android)

/* Support Expo */
import { setExpoStatusBarHeight } from 'react-navigation-collapsible';
import { Constants } from 'expo';
setExpoStatusBarHeight(Constants.statusBarHeight);

StackNavigator

(MyScreen.js)

import { withCollapsible } from 'react-navigation-collapsible';
const AnimatedFlatList = Animated.createAnimatedComponent(FlatList);

class MyScreen extends Component{
  static navigationOptions = {
    title: 'Awesome Screen'
  };

  render(){
    const { paddingHeight, scrollY, onScroll } = this.props.collapsible;

    return (
      <AnimatedFlatList 
        ...
        contentContainerStyle={{paddingTop: paddingHeight}}
        _mustAddThis={scrollY}
        onScroll={onScroll} 
        
        // if you want to use 'onScroll' callback.
        // onScroll={Animated.event(
        //   [{nativeEvent: {contentOffset: {y: scrollY}}}],
        //   {useNativeDriver:true, listener:this.onScroll})} 
        />
    )
  }
}

export default withCollapsible(MyScreen, {iOSCollapsedColor: '#031'});

StackNavigator + MaterialTopTabNavigator

(MyScreen.js)

...
export default withCollapsible(MyScreen, {iOSCollapsedColor: '#031'});

(Your Navigator.js)

import { collapsibleOptionsForTab, collapsibleTabConfig } from 'react-navigation-collapsible';

const TopTabNavigator = createMaterialTopTabNavigator(
  {
    Screen1: { screen: MyScreen },
    Screen2: { screen: OtherScreen },
  },
  collapsibleTabConfig({
    navigationOptions:{
      tabBarOptions: {
        indicatorStyle: { backgroundColor: 'white' },
        style: { backgroundColor: 'green' },
      }
    }
  })
);

const routeConfig = {
  MainScreen: { screen: MainScreen },
  TopTabScreen: { screen: TopTabNavigator, navigationOptions: props => collapsibleOptionsForTab(props, {title: 'Material Tab'}) },
};

const StackNavigator = createStackNavigator(routeConfig);

Custom or Image Header with StackNavigator

See Example/src/ImageScreen.js

Extra Header(eg. SearchBar) with StackNavigator

See Example/src/ExtraHeaderScreen.js

API

  • HOC withCollapsible (wrappedUserScreen, ?collapsibleParams: {?iOSCollapsedColor, ?extraHeader, ?extraHeaderStyle})
  • collapsibleOptionsForTab (props, userOptions)
  • collapsibleTabConfig (userConfig)
  • setExpoStatusBarHeight (height)

Limitation

Because react-navigation-capable combines your screen's navigationOptions with {headerTransparent: true}, there is some layout issue on a transition to other screens which is using {headerTransparent: false}.

Tasks

  • Regular Header
  • Image Header
  • Nested Stack+Tab
  • Extra Header
  • HOC
  • Flow
  • Split code

Contribution

This module is just published. Please help and let's make it better so that this module can capable more use cases.

  • create issue or PR with a sample react-navigation code or Expo Snack that are not working with this module.
  • If you improved module, please set /example's react-navigation-collapsible package url to be linked to your forked repo and PR.

Compatible Versions with Example

  • react-native 0.56
  • react-navigation 2.11.2

react-navigation-collapsible's People

Contributors

benevbright avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.