GithubHelp home page GithubHelp logo

ybeetle8 / react-native-tab-view-header Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deflexable/react-native-tab-view-header

0.0 0.0 0.0 803 KB

A tabview component with collapsible header. adapted with refreshable, scrollable and touchable header

JavaScript 100.00%

react-native-tab-view-header's Introduction

react-native-tab-view-header

A tabview component with collapsible header. adapted with refreshable, scrollable and touchable header

npm version

Getting Started

Install

react-native-tab-view-header is built upon react-native-tab-view

npm install react-native-tab-view-header react-native-tab-view --save

or using yarn

yarn add react-native-tab-view-header react-native-tab-view

Demo

Example

import React, { useState } from "react";
import { Alert, Animated, TouchableOpacity, View, Text, FlatList, Dimensions } from "react-native";
import { getStatusBarHeight } from "react-native-iphone-x-helper";
import CollapsibleTabViewHeader from "react-native-tab-view-header";


const WINDOW_HEIGHT = Dimensions.get('window').height;

const App = () => {
    const [currentSlideIndex, setCurrentSlideIndex] = useState(0);

    const slideData = [{
        key: 'first',
        title: 'First',
        Wrapper: Animated.FlatList,
        WrapperProps: {
            data: Array(20).fill(1),
            renderItem: ({ item, index }) => (
                <View style={{ backgroundColor: index % 2 ? 'lightgray' : 'gray', height: WINDOW_HEIGHT / 2, justifyContent: 'center', alignItems: 'center' }}>
                    <Text>
                        {`Index: ${index}`}
                    </Text>
                </View>
            ),
            keyExtractor: (_item, index) => index
        }
    }, {
        key: 'second',
        title: 'Second',
        Wrapper: Animated.FlatList,
        WrapperProps: {
            data: Array(40).fill(1),
            renderItem: ({ item, index }) => (
                <View style={{ backgroundColor: index % 2 ? 'orange' : 'pink', height: WINDOW_HEIGHT / 2, justifyContent: 'center', alignItems: 'center' }}>
                    <Text>
                        {`Index: ${index}`}
                    </Text>
                </View>
            ),
            keyExtractor: (_item, index) => index
        }
    }]

    const renderHeaderScroll = () => (
        <FlatList
            style={{ width: '100%', height: 50 }}
            data={Array(40).fill(1)}
            renderItem={({ item, index }) =>
                <Text style={{ backgroundColor: 'orange', width: 50, height: 50, textAlign: 'center' }}>
                    {index + ''}
                </Text>
            }
            keyExtractor={(_, i) => i}
            horizontal
        />
    )

    return (
        <View style={{ flex: 1 }}>
            <CollapsibleTabViewHeader
                tabSlides={slideData}
                tabIndex={currentSlideIndex} // if you want to control the current tab index
                onIndexChange={i => {
                    console.log('onIndexChange: ', i);
                    setCurrentSlideIndex(i);
                }}
                renderTabBar={undefined} // only provide this if you want to render your custom tab bar
                renderHeader={() =>
                    <View style={{ height: 350, backgroundColor: 'red' }}>
                        <TouchableOpacity
                            style={{ height: 270, justifyContent: 'center', alignItems: 'center' }}
                            onPress={() => {
                                Alert.alert('Header Clicked');
                            }}>
                            <Text>
                                {'Click Header'}
                            </Text>
                        </TouchableOpacity>
                        {renderHeaderScroll()}
                    </View>
                }
                enableRefresh={false} // enable refresh control
                tabBarStickyPosition={getStatusBarHeight()} // position to stop the header and tab-bar
                onTabBarStickyChange={sticky => null} // callback that triggers whenever the tab-bar stick/unstick
            />
        </View>
    )
}

export default App;

PropTypes

Property Type Description
tabSlides Array Array containing data pertaining to each tab slide
onIndexChange Function Called whenever the current tab index changes
renderTabBar Function Function that renders your custom tab-bar component
renderHeader Function Function that renders your custom header component
tabIndex number The default visible slide index of the tab view
headerHeight number The height of the header (Optional but speedup tabview render when provide together with tabBarHeight)
onScrollY Function Listens to the scroll offset of the tabview
tabBarStickyPosition number The position in which the tab-bar should stop
onTabBarStickyChange Function Called whenever the tab-bar stick/unstick to it position
onHeaderHeightChanged Function Called whenever the header height changes
renderLabel Function Function that renders the tab-bar label instead of the entire tab-bar

TODOS

  • Add refresh control feature
  • Add support for <View /> and <ScrollView /> (Currently only support FlatList, SectionList)
  • Add Header Collapse snap effect

Reference

Contribution

Pull requests and contributions are welcome

react-native-tab-view-header's People

Contributors

deflexable 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.