GithubHelp home page GithubHelp logo

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

react-native-tab-flatlist

ReactNative 跨平台实现TabView嵌套ScrollView滚动吸顶效果,采用react-native-tab-view+flatlist实现效果丝滑

安装

使用前需要先安装react-native-tab-view react-native-pager-view


npm install react-native-tab-flatlist --save

Demo

开始

import React from 'react';
import {View,Text,} from 'react-native';
import {ScrollView, TabView, FlatList} from '../components/TabScrollView';

export default class Home extends React.Component<any, any> {
  constructor(props: any) {
    super(props);
    this.state = {
      activeIndex: 0
    };
  }
  renderScene = (props: any) => {
    switch (props.route.key) {
      case '1':
        return (
          <ScrollView isActive={this.state.activeIndex == 0 ? true : false}>
            <View
              style={{
                width: '100%',
                height: 1000,
                backgroundColor: '#5a32ac',
              }}
            />
            <View
              style={{
                width: '100%',
                height: 1000,
                backgroundColor: 'yellow',
              }}
            />
          </ScrollView>
        );
      case '2':
        return (
          <FlatList
            style={{zIndex: 999}}
            isActive={this.state.activeIndex == 1 ? true : false}
            data={[1, 2, 3]}
            renderItem={({item, index}) => {
              return (
                <View
                  style={{
                    width: '100%',
                    height: 600,
                    backgroundColor: index % 2 == 0 ? '#f93776' : '#48a248',
                  }}
                />
              );
            }}
          />
        );
    }
  };

  // 渲染头部
  renderTabHeader = (props: any, position: any) => {
    const {
      navigationState: {index},
    } = props;
    return (
      <View style={{width: '100%', height: 300, backgroundColor: '#2b88f0'}}>
        <View
          style={{
            height: 100,
            width: '100%',
            marginTop: 200,
            flexDirection: 'row',
            alignItems: 'flex-end',
          }}>
          <View
            style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
            <Text style={{fontSize: 18, color: index == 0 ? 'white' : '#000'}}>
              页面1
            </Text>
          </View>
          <View
            style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
            <Text style={{fontSize: 18, color: index == 1 ? 'white' : '#000'}}>
              页面2
            </Text>
          </View>
        </View>
      </View>
    );
  };
  render() {
    return (
      <View style={{flex: 1}}>
        <TabView
          renderHeader={this.renderTabHeader}
          headerHeight={300}
          stopHeight={200}
          navigationState={{
            index: this.state.activeIndex,
            routes: [
              {title: '页面1', key: '1'},
              {title: '页面2', key: '2'},
            ],
          }}
          renderScene={this.renderScene}
          onIndexChange={index => {
            this.setState({
              activeIndex: index,
            });
          }}
        />
      </View>
    );
  }
}

接口参考


headerHeight

头部header高度


stopHeight

头部header可上移距离


renderHeader


  • position FlatList 或 ScrollView 滚动的位置

renderTabBar(此方法与renderHeader二选一实现一个即可)


renderHeader参数一致,此方法用于自定义header滚动动画

renderScene

此方法必须返回的是本组件里的FlatList或ScrollView


其他Api请参考 react-native-tab-view

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

Contributors

jianglingzhi666 avatar

Stargazers

lanjinglingxx avatar Mr_He avatar  avatar Bekir Yetim avatar  avatar Dicky avatar  avatar

Watchers

lanjinglingxx avatar  avatar

react-native-tab-scroll-view's Issues

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.