1.0.0 • Published 3 years ago

native-x-paginated-view v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

native-x-paginated-view

semantic-release

This component will help you to implement a tab with a horizontal scroll to toggle between content.

Install

Yarn

yarn add native-x-paginated-view

NPM

npm install native-x-paginated-view

Usage

import { Screen } from 'native-x-screen'
import React, { useEffect, useRef, useState } from 'react'
import { PaginatedView, PaginatedViewRef } from 'native-x-paginated-view'
import { DiscoverScreen, HomeScreen, UserProfileScreen } from '../screens'

export enum HomeScreenTab {
  HOME,
  DISCOVER,
  PROFILE,
}

export function MainScreen() {
  const [tab, setTab] = useState<HomeScreenTab>(HomeScreenTab.HOME)
  const paginatedViewRef = useRef<PaginatedViewRef>()

  useEffect(() => {
    paginatedViewRef?.current?.goto(tab)
  }, [tab])

  return (
    <Screen scrollable>
      <PaginatedView ref={paginatedViewRef} onIndexChange={setTab}>
        <HomeScreen />
        <DiscoverScreen />
        <UserProfileScreen />
      </PaginatedView>
      <TabHeader tab={tab} onChange={setTab} />
    </Screen>
  )
}

API

PropertyDefault ValueUsage
children: ReactNode[]Content of the paginated view
style?: ViewStyleContainer style
scrollEnabled?: booleantrueSet to true to enable scroll
animated?: booleantrueAnimate transition between views
showsHorizontalScrollIndicator?: booleanfalseSet to true to show indicator
onIndexChange?: (index: number) => voidCallback for index change
keepAlreadyRendered?: booleantrueIf set to true, all paged once rendered will be cached
cachePageCount?: number3Number of pages to cache at any time (works only if keepAlreadyRendered is false)
containerWidth?: numberScreen SizeWidth of the container. By default this is set to screen size
dynamicWidth?: booleanfalseSet this to true for the component to calculate width of the content as it changes

Automatic Release

Here is an example of the release type that will be done based on a commit messages:

Commit messageRelease type
fix: commentPatch Release
feat: commentMinor Feature Release
perf: commentMajor Feature Release
doc: commentNo Release
refactor: commentNo Release
chore: commentNo Release