1.1.7 • Published 2 years ago

@itenl/react-native-scrollable-tabview v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-scrollable-tabview

NPM Version

English | 简体中文

Based on pure JS scripts, without relying on native, no need for react-native link,Title / Header / Tabs / Sticky / Screen components can be flexibly configured, among which Tabs / Sticky can slide When it reaches the top, it will be topped; what we support is to independently manage its own Sticky / Screen / Badge / tabLabel configuration in the form of a stack, and inject the Screen lifecycle onRefresh / onEndReached They will be triggered when the pull-down refresh and the scroll bar hit the bottom, and finally inject more into Screen / Sticky props

Table of Contents

Features

  • Support to individually set pull-down refresh and up-slide load for each screen (Lifecycle injection or props injection)
  • Flex Tabs and multiple Tabs horizontal scrolling support configuration method
  • Allow to set up each Screen’s own Sticky component
  • Custom badges can be configured for each Tab
  • Support pull down to refresh and slide up to load more pre-functions onBeforeRefresh / onBeforeEndReached
  • Support animation title, can support animation as interpolate.opacity and interpolate.height

Installation

npm i @itenl/react-native-scrollable-tabview

or

yarn add @itenl/react-native-scrollable-tabview

Usage

import React from 'react';
import ScrollableTabView from '@itenl/react-native-scrollable-tabview';

function App() {
  return (
      <ScrollableTabView
        ref={rf => (this.scrollableTabView = rf)}
        mappingProps={{
          fromRootEst: this.state.est,
        }}
        badges={[
          null,
          [
            <View
              style={{
                position: 'absolute',
                zIndex: 100,
                top: 10,
                right: 0,
              }}
            >
              <Text>new</Text>
            </View>,
            <View
              style={{
                position: 'absolute',
                width: 150,
                height: 50,
                zIndex: 100,
                marginTop: 35,
                right: 0,
                opacity: 0.6,
                backgroundColor: 'pink',
                justifyContent: 'center',
                alignItems: 'center',
              }}
            >
              <Text>Three Tips</Text>
            </View>,
          ],
        ]}
        stacks={[
          {
            screen: One,
            sticky: Sticky,
            tabLabel: 'OneTab',
            tabLabelRender: tabLabel => {
              return `--- ${tabLabel} ---`;
            },
            badge: [<Text>one</Text>, <Text>two</Text>],
            toProps: {
              xx: 123,
            },
          }, {
            screen: ({
              layoutHeight,
              refresh,
              scrollTo,
              toTabView,
              initScreen,
              onRefresh,
              onEndReached,
            }) => {
              // The code is required
              initScreen();
              const [datetime, setDatetime] = useState(Date.now());
              useEffect(() => {
                setInterval(() => {
                  setDatetime(Date.now());
                }, 1000);
              }, []);
              onRefresh((toggled) => {
                toggled(true);
                alert("onRefresh start");
                setTimeout(() => {
                  toggled(false);
                  alert("onRefresh stop");
                }, 3000);
              });
              onEndReached(() => {
                alert("onEndReached");
              });
              return (
                <View
                  style={{
                    flex: 1,
                    backgroundColor: "#151723",
                    justifyContent: "center",
                    alignItems: "center",
                  }}
                >
                  <Text style={{ color: "#ffffff" }}>
                    Test function component {datetime}
                  </Text>
                </View>
              );
            },
            tabLabel: "TestFunctionComponent",
          }
        ]}
        tabsStyle={{}}
        tabWrapStyle={{}}
        tabInnerStyle={{}}
        tabActiveOpacity={0.6}
        tabStyle={{}}
        textStyle={{}}
        textActiveStyle={{}}
        tabUnderlineStyle={{}}
        firstIndex={0}
        syncToSticky={true}
        onEndReachedThreshold={0.1}
        onBeforeRefresh={(next, toggled) => {
          toggled();
          next();
        }}
        onBeforeEndReached={next => {
          next();
        }}
        onTabviewChanged={(index, tabLabel, isFirst) => {
          alert(index);
        }}
        header={() => {
          return <View style={{ backgroundColor: 'pink', height: 120 }}></View>;
        }}
        oneTabHidden={true}
        enableCachePage={true}
        carouselProps={{}}
        sectionListProps={{}}
        toHeaderOnTab={true}
        toTabsOnTab={true}
        tabsShown={false}
        fixedTabs={false}
        fixedHeader={false}
        useScroll={false}
        fillScreen={true}
      ></ScrollableTabView>
  );
}

Props

All props are optional

PropTypeDefaultDescription
stacksArray[]Page Stack < [Read Stack Property](#StackProperty) >
mappingPropsObject{}Associate mapping data to Stack / Sticky
badgesArray[]Badges for each Tab < [Read Badge Property](#BadgeProperty) >
tabsStyleObject{}The entire Tabs style
tabWrapStyleObject / Function{}Single Tab wrap style (The function parameters provide item, index, and need to return the style object, eg. return index == 1 && {zIndex: 10})
tabInnerStyleObject{}Single Tab inner style
tabActiveOpacityNumber0.6Transparency after Tab button click
tabStyleObject{}Single Tab style
textStyleObject{}Text style in Tab
textActiveStyleObject{}Select the active text style
tabUnderlineStyleObject{}Select the active underline style
firstIndexNumber / NullnullSet the stack of firstIndex to active (make sure that the number of stacks is greater than to firstIndex when setting the firstIndex value)
syncToStickyBooleantrueWhether it is synchronized (render triggered in the Screen componentDidUpdate will update Sticky)
onEndReachedThresholdNumber0.2Bottom callback threshold
onBeforeRefreshFunctionnullPull down to refresh the pre-functions, execute next to execute onRefresh function in Screen, execute toggled to switch system loading, you can pass true / false to specify (callback contains next, toggled two formal parameters)
onBeforeEndReachedFunctionnullSlide up to load more pre-functions, execute next will execute the onEndReached function in the Screen (callback contains next formal parameters)
onTabviewChangedFunctionnullTab switch completion callback (callback contains index, tabLabel, isFirst parameters)
screenScrollThrottleNumber60Screen Throttle parameters during lateral sliding, Unit (ms)
headerFunction / JSX Element / Class ComponentnullTop component (if the function needs to return Element)
stickyHeaderFunction / JSX Element / Class ComponentnullTop component (if the function needs to return Element) for sticky
oneTabHiddenBooleanfalseHide itself when there is only one Tab
enableCachePageBooleantrueWhether the persistent page will not be destroyed after switching
carouselPropsObject{}The remaining attributes passed to Carousel < [Read Carousel](https://github.com/meliorence/react-native-snap-carousel/blob/master/doc/PROPS_METHODS_AND_GETTERS.md) >
sectionListPropsObject{}Remaining attributes passed to SectionList < [Read SectionList](https://reactnative.dev/docs/sectionlist) >
toHeaderOnTabBooleanfalseClick to trigger the activated Tab will scroll to Header (high priority)
toTabsOnTabBooleanfalseClick to trigger the activated Tab will scroll to Tabs
tabsShownBooleantrueConfigure Tabs display and hide
fixedTabsBooleanfalseWhen enableCachePage is true, slide to switch Screen to set the minimum height to ensure that the Header and Tabs will not bounce
fixedHeaderBooleanfalseRender together with Tabs, fix the top Header, do not follow the scroll
useScrollBooleanfalseDoes Tabs support horizontal scrolling (it needs to be enabled when there are multiple category Tabs, it is recommended that tabStyle pass in a fixed width)
useScrollStyleObject{}Set contentContainerStyle for scrolling Tabs, usually add margins to the left and right sides paddingLeft paddingHorizontal
fillScreenBooleantrueFill the entire Screen
titleFunction / JSX Element / Class ComponentnullAnimation title
titleArgsObject{ style: {}, interpolateOpacity: {}, interpolateHeight: {} }Title parameter configuration < [Read interpolate](https://reactnative.dev/docs/animations#interpolation) >
onScrollFunctionnullScroll event monitoring
onScroll2HorizontalFunctionnullScroll event monitoring for orizontal
tabsEnableAnimatedBooleanfalseEnable sliding effect for Tabs, Need to specify width for tabStyle
tabsEnableAnimatedUnderlineWidthNumber0To set a fixed width for the Tabs Underline and add a jumping animation, you need to enable tabsEnableAnimated=true. (It is recommended to pass in one third of tabStyle.width or a fixed 30px)
errorToThrowBooleanfalseconsole.error will throw an error throw new Error()

Method

  <ScrollableTabView
    ref={rf => (this.scrollableTabView = rf)}
  >
  </ScrollableTabView> 
  this.scrollableTabView.getCurrentRef();
  this.scrollableTabView.toTabView(1);
  this.scrollableTabView.scrollTo(0);
  this.scrollableTabView.clearStacks(()=>alert('done'));
NameTypeDescription
getCurrentRef(index: number.optional)FunctionGet the instance of the currently active view, you can pass index to get the specified instance
toTabView(index: number.required / label: string.required)FunctionJump to the specified Screen
scrollTo(index: number.required)FunctionSwipe up and down to the specified position (passing in 0 is the default positioning to tabs / passing in a negative number is set to the top)
clearStacks(callback: function.optional)FunctionClear the Stacks and related state (Tabs / Badge / Stacks))

Stack Property

NameTypeDescription
screenClass / Function ComponentScreen components ( If the function component must call initScreen )
stickyClass ComponentSticky component, The context of this type of component will be returned in the instance
tabLabelStringTab display name
tabLabelRenderFunctionCustom Tab rendering function, priority is higher than tabLabel
badgeArrayFor the current Tab badge, it is mutually exclusive with the badges attribute, and has a higher priority than the outermost attribute badges < [Read Badge Property](#BadgeProperty) >
toPropsObjecttoProps Only pass to Screen without data association

Badge Property

TypeDescription
JSX ElementBadges/Hovering Tips, etc. rendered based on the current Tab

Injection lifecycle to Screen (On Class Component)

NameTypeDescription
onRefreshFunctionTriggered when pull-down refresh, the formal parameter toggled function is used to switch the display of the native loading state, if the user switches the tab during loading, it will be forced to hide and reset the state
onEndReachedFunctionSwipe up to load more triggers

Injection props to Screen

NameTypeDescription
refresh()FunctionManually trigger refresh and synchronize Screen status to Sticky
scrollTo(index: number.required)FunctionSwipe up and down to the specified position (passing in 0 is the default positioning to tabs / passing in a negative number is set to the top)
toTabView(index: number.required / label: string.required)FunctionJump to the specified Screen
layoutHeight.containerNumberTotal height of the Container
layoutHeight.headerNumberTotal height of the Header
layoutHeight.tabsNumberTotal height of the Tabs
layoutHeight.screenNumberTotal height of the Screen
initScreenFunction(On Function Component) If it is a function component, it must be called
onRefreshFunction(On Function Component) < [Read onRefresh description](#InjectionLifecycle) >
onEndReachedFunction(On Function Component) < [Read onEndReached description](#InjectionLifecycle) >

Injection props to Sticky

NameTypeDescription
screenContextObjectGet Screen context

Known Issues

  • If you just add a Stack, you can Push, but if you need to update or delete a Stack, please use [clearStacks](#Method) and then add the Stacks you need

Snapshot

Android (Sliding Tabs)

iOS (Bounce Tabs)

API Example


MIT Licensed

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago