6.3.0 • Published 2 years ago

react-navigation-collapsible v6.3.0

Weekly downloads
2,740
License
MIT
Repository
github
Last release
2 years ago

react-navigation-collapsible

npm npm Greenkeeper badge

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 to 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}}
        scrollIndicatorInsets={{top: 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: Component, collapsibleParams?: {iOSCollapsedColor?: string, extraHeader?: Component, extraHeaderStyle?: Object})
  • collapsibleOptionsForTab (props: Object, userOptions: Object)
  • collapsibleTabConfig (userConfig: Object)
  • setExpoStatusBarHeight (height: number)

react-navigation-collapsible set your this.props.navigation params with {headerHeight: number, translateY: Animated, translateOpacity: Animated, translateProgress: Animated}. You can create your desired screen with this params. For more infomation, see example/src/AdvancedScreen.js.

Limitation

Transition between non-collapsible and collapsible (iOS)

Because react-navigation-collapsible converts your screen's navigationOptions to {headerTransparent: true}, there is a layout issue on a transition with other screens not using {headerTransparent: true}.

If you want to make the transition between screens natural on iOS, you have two options. (See example/src/App.js)

1. Set headerTransparent: true in navigatorConfig and set paddingTop on every screen in the same StackNavigator.

or

2. Set headerMode: 'screen' in navigatorConfig.

With State persistence #40

react-navigation provides State persistence as experimental feature. Unfortunately, collapsible header stops collapsible when you use it.

With SectionList #37

Tasks

  • Regular Header
  • Image Header
  • Nested Stack+Tab
  • Extra Header
  • HOC
  • Split code
  • iOS 11 Style Header
  • Big Header <-> Regular Header

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.

Dependencies Version of Example

  • react-native: 0.57.4, latest: npm
  • react-navigation: 2.18.2, latest: npm

I've ensured this module is compatible with react-native >=0.56 and react-navigation >=2.11.2. But it does not mean it's not compatible with older versions.

6.3.0

2 years ago

6.3.0-rc0

2 years ago

6.3.0-rc3

2 years ago

6.3.0-rc2

2 years ago

6.3.0-rc1

2 years ago

6.2.0-beta1

3 years ago

6.2.0-beta2

3 years ago

6.2.0

3 years ago

6.2.0-beta0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

5.10.2

3 years ago

5.10.1

3 years ago

5.10.0

3 years ago

5.9.1

3 years ago

5.8.1

4 years ago

5.8.0

4 years ago

5.7.5

4 years ago

5.7.4

4 years ago

5.7.3

4 years ago

5.7.2

4 years ago

5.7.1

4 years ago

5.7.0

4 years ago

5.6.4

4 years ago

5.6.3

4 years ago

5.6.2

4 years ago

3.0.4

4 years ago

5.6.1

4 years ago

5.6.0

4 years ago

5.5.0

4 years ago

5.4.0

4 years ago

5.3.0

4 years ago

5.2.0

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

5.0.0-alpha4

4 years ago

5.0.0-alpha3

4 years ago

5.0.0-alpha2

4 years ago

5.0.0-alpha0

4 years ago

5.0.0-alpha1

4 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-beta2

5 years ago

3.0.0-beta1

5 years ago

3.0.0-bera1

5 years ago

2.0.0

5 years ago

3.0.0-alpha1

5 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.18

6 years ago

0.2.17

6 years ago

0.2.16

6 years ago

0.2.15

6 years ago

0.2.14

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago