react-navigation-collapsible

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

  • 所有者: benevbright/react-navigation-collapsible
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

react-navigation-collapsible

npm npm code style: prettier ci: github runs with expo

An extension of react-navigation that makes your header collapsible.

Try out on Expo Snack

Compatibility ?, react-navigation, react-navigation-collapsible, Documentation, ------------------, ------------------------------, ------------------------------------------------------------------------------------, ^5.0.0 (next), ^5.0.0 (latest), current, ^4.0.0 (latest), ^3.0.0, v3-4 branch, ^2.0.0, ^2.0.0, v2 branch, ? The Callapsible Tab-navigator is no longer supported due to the Android bug from react-native.

Usage

1. Default Header

import { createCollapsibleStack } from 'react-navigation-collapsible';

function App() {
  return (
    <NavigationNativeContainer>
      <Stack.Navigator>
        /* Wrap your Stack.Screen */
        {createCollapsibleStack(
          <Stack.Screen
            name="HomeScreen"
            component={MyScreen}
            options={{
              headerStyle: { backgroundColor: 'green' },
              title: 'Home',
            }}
          />,
          {
            collapsedColor: 'red' /* Optional */,
          }
        )}
      </Stack.Navigator>
    </NavigationNativeContainer>
  );
}
import { Animated } from 'react-native';
import { useCollapsibleStack } from 'react-navigation-collapsible';

const MyScreen = ({ navigation, route }) => {
  const {
    onScroll /* Event handler */,
    containerPaddingTop /* number */,
    scrollIndicatorInsetTop /* number */,
    /* Animated.AnimatedInterpolation by scrolling */
    translateY /* 0.0 ~ -headerHeight */,
    progress /* 0.0 ~ 1.0 */,
    opacity /* 1.0 ~ 0.0 */,
  } = useCollapsibleStack();

  return (
    <Animated.FlatList
      onScroll={onScroll}
      contentContainerStyle={{ paddingTop: containerPaddingTop }}
      scrollIndicatorInsets={{ top: scrollIndicatorInsetTop }}
      /* rest of your stuff */
    />
  );
};

See /example/App.tsx and /example/src/DefaultHeaderScreen.tsx

import { createCollapsibleStackSub } from 'react-navigation-collapsible';
/* use 'createCollapsibleStackSub' instead of 'createCollapsibleStack' */

/* The rest are the same with the default header. */
import { Animated } from 'react-native';
import {
  useCollapsibleStack,
  CollapsibleStackSub,
} from 'react-navigation-collapsible';

const MySearchBar = () => (
  <View style={{ padding: 15, width: '100%', height: 60 }}>
    <TextInput placeholder="search here" />
  </View>
);

const MyScreen = ({ navigation, route }) => {
  const {
    onScroll /* Event handler */,
    containerPaddingTop /* number */,
    scrollIndicatorInsetTop /* number */,
  } = useCollapsibleStack();

  return (
    <>
      <Animated.FlatList
        onScroll={onScroll}
        contentContainerStyle={{ paddingTop: containerPaddingTop }}
        scrollIndicatorInsets={{ top: scrollIndicatorInsetTop }}
        /* rest of your stuff */
      />
      /* Wrap your component with `CollapsibleStackSub` */
      <CollapsibleStackSub>
        <MySearchBar />
      </CollapsibleStackSub>
    </>
  );
};

See /example/App.tsx and /example/src/SubHeaderScreen.tsx

Install

# install module
yarn add react-navigation-collapsible

Contribution

PR is welcome!

Testing your library code with the example

/example imports the library directly from the root folder, configured with babel-plugin-module-resolver.
So, just turn the watch option on at the root folder while you're making changes on the library, and check them on the example.

yarn tsc -w

主要指标

概览
名称与所有者benevbright/react-navigation-collapsible
主编程语言TypeScript
编程语言Java (语言数: 8)
平台
许可证MIT License
所有者活动
创建于2018-08-02 21:51:28
推送于2021-11-07 09:09:32
最后一次提交
发布数42
最新版本名称v6.3.0 (发布于 2021-11-07 09:09:30)
第一版名称2.0.0 (发布于 2018-11-20 00:53:56)
用户参与
星数1.2k
关注者数12
派生数94
提交数268
已启用问题?
问题数109
打开的问题数13
拉请求数52
打开的拉请求数3
关闭的拉请求数42
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?