0.3.45 • Published 1 year ago

react-native-tab-view-reanimated-3 v0.3.45

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-tab-view-reanimated-3

A package create tab view in react native, using react-native-pager-view on Android & iOS and reanimated 3 for animation, support collapse tab view header, basic using below.

Installation

npm install react-native-tab-view-reanimated-3 react-native-pager-view

or

yarn add react-native-tab-view-reanimated-3 react-native-pager-view

Then sure Reanimated is installed by follow the official installation guide.

Quick start

import { TabView, SceneMap, RTabView, IRoute } from "react-native-tab-view-reanimated-3";

type TRouteData = number

const Tab1 = ({route} : {route:IRoute<TRouteData>}) => <View style={{ flex: 1, backgroundColor: 'gray' }}></View>
const Tab2 = ({route} : {route:IRoute<TRouteData>}) => <View style={{ flex: 1, backgroundColor: 'purple' }}></View>

const scenes = SceneMap({
  "1": Tab1,
  "2": Tab2,
})

// ...

export const Test = () => {
  const refTabView = useRef<RTabView>(null)
  const [routes] = useState<IRoute<TRouteData>[]>([
    { key: "1", title: "Tab 1", data: 0 },
    { key: "2", title: "Tab 2", data: 1 },
  ])

  return (
    <View style={{flex: 1}}>
      <TabView ref={refTabView} routes={routes} renderScene={scenes} lazy />
    </View>
  )
}

Quick start with collapse header

import { TabView, SceneMap, RTabView, IRoute, TCollapseHeaderOptions, ScrollViewWithCollapse, FlatListWithCollapse } from "react-native-tab-view-reanimated-3";

type TRouteData = number

// NOTE: you must pass route to tab and use route key for ScrollViewWithCollapse to sync scroll
// NOTE: handleScroll is function on UI should you have 'worklet' in first function
const Tab1 = ({route} : {route:IRoute<TRouteData>}) => <ScrollViewWithCollapse id={route.key} handleScroll={(e:NativeScrollEvent) => {"worklet"}} style={{ flex: 1, backgroundColor: 'gray' }}></ScrollViewWithCollapse>
const Tab2 = ({route} : {route:IRoute<TRouteData>}) => <FlatListWithCollapse id={route.key} handleScroll={(e:NativeScrollEvent) => {"worklet"}} style={{ flex: 1, backgroundColor: 'purple' }}></FlatListWithCollapse>

const scenes = SceneMap({
  "1": Tab1,
  "2": Tab2,
})

// ...

export const Test = () => {
  const refTabView = useRef<RTabView>(null)
  const [routes] = useState<IRoute<TRouteData>[]>([
    { key: "1", title: "Tab 1", data: 0 },
    { key: "2", title: "Tab 2", data: 1 },
  ])

  // Declare and use props will trigger header collapse
  const renderHeader = () => {
    return <View style={{height: 200}} />
  }

  return (
    <View style={{flex: 1}}>
      <TabView
        idTabView='test'
        ref={refTabView}
        routes={routes}
        renderScene={scenes}
        renderHeader={renderHeader}
        isSnap={true}
        revealHeaderOnScroll={true}
        minHeightHeader={100}
        lazy
        />
    </View>
  )
}

API Reference

nametypedefaultdescription
routesIRoute<T>[]Data route to render tab bar and view (is required)
defaultIndexTabnumber0Default tab index when init
scrollEnabledbooleantrueEnable swipe between tab views
lazybooleanfalseLazy render tab view outside screen
onChangeTab(currentIndexTab: number) => voidfalseEvent to catch tab current when change
renderScene({ route }:{ route: IRoute<T> }) => ReactElementundefinedFunction to render scenes view (is required)
renderTabBar(props: TTabBar<T>) => ReactElement(props: TTabBar<T>) => <TabBar {...props} />Function to custom render tab bar
renderHeader({ offsetActiveScrollView }:{ offsetActiveScrollView: SharedValue<number> }) => ReactElementundefinedIf set props auto header is rendered, custom header function
isSnapbooleanfalseCan auto snap collapse header or no
revealHeaderOnScrollbooleanfalseReveal header when scrolling down. Implements diffClamp
minHeightHeadernumber0Header minimum height when collapsed
styleHeaderContainerStyleProp<ViewStyle>undefinedStyle container header
refRTabViewundefinedRef tav view

IRoute

propstype
keystring
titlestring
dataT

TTabBar

propstype
routesIRoute<T>[]
positionSharedValue<number>
currentIndexSharedValue<number>
pageScrollStateSharedValue<'idle' \| 'dragging' \| 'settling'>
hiddenIndicatorboolean
styleContainerListStyleProp<ViewStyle>
styleTabBarItemStyleProp<ViewStyle>
renderTabBarItem(props: TTabBarItem) => ReactElement
renderIndicator() => ReactElement

TTabBarItem

propstype
titlestring
positionSharedValue<number>
indexnumber

RTabView

methodtype
setIndexTab(indexTab: number) => void
setIsSwipe(isSwipe: boolean) => void

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

0.3.45

1 year ago

0.3.44

1 year ago

0.3.43

1 year ago

0.3.42

1 year ago

0.3.41

1 year ago

0.3.40

1 year ago

0.3.39

1 year ago

0.3.38

1 year ago

0.3.37

1 year ago

0.3.36

1 year ago

0.3.35

1 year ago

0.3.34

1 year ago

0.3.33

1 year ago

0.3.32

1 year ago

0.3.31

1 year ago

0.3.30

1 year ago

0.3.29

1 year ago

0.3.28

1 year ago

0.3.27

1 year ago

0.3.26

1 year ago

0.3.25

1 year ago

0.3.24

1 year ago

0.3.23

1 year ago

0.3.22

1 year ago

0.3.21

1 year ago

0.3.20

1 year ago

0.3.19

1 year ago

0.3.18

1 year ago

0.3.17

1 year ago

0.3.16

1 year ago

0.3.15

1 year ago

0.3.14

1 year ago

0.3.13

1 year ago

0.3.12

1 year ago

0.3.11

1 year ago

0.3.10

1 year ago

0.3.9

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago