npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-collapsible-segmented-view

v1.2.1

Published

Collapsible segmented view component for React Native

Downloads

327

Readme

react-native-collapsible-segmented-view

Build Status Version MIT License runs with expo

Expo app

Collapsible Segmented View for React Native.

Credits

The react-native-tab-view example app was used as template for the demos.

Demo

| ios | android | | :----------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------: | | | |

Features

Installation

Open a Terminal in the project root and run:

yarn add react-native-collapsible-segmented-view

expo install @react-native-community/segmented-control

Quick Start

import React from 'react'
import { View, StyleSheet, ListRenderItem, Text } from 'react-native'
import { Segmented } from 'react-native-collapsible-segmented-view'

const Header = () => {
  return (
    <View style={styles.box} pointerEvents="box-none">
      <Text style={styles.text}>Collapsible Header</Text>
    </View>
  )
}

const Example: React.FC = () => {
  return (
    <Segmented.View header={Header}>
      <Segmented.Segment label="A" component={SegmentA} />
      <Segmented.Segment label="B" component={SegmentB} />
      <Segmented.Segment label="C" component={SegmentC} />
    </Segmented.View>
  )
}

const buildRenderItem = (color0: string, color1: string) => {
  const renderItem: ListRenderItem<number> = (data) => {
    const backgroundColor = data.index % 2 === 0 ? color0 : color1
    const color = data.index % 2 === 0 ? color1 : color0
    return (
      <View style={[styles.box, { backgroundColor }]}>
        <Text style={[{ color }, styles.text]}>{data.index}</Text>
      </View>
    )
  }
  return renderItem
}

const buildSegment = (data: number[], color0: string, color1: string) => {
  const Segment = () => {
    return (
      <Segmented.FlatList
        data={data}
        renderItem={buildRenderItem(color0, color1)}
        keyExtractor={(v) => v + ''}
      />
    )
  }
  return Segment
}

const data0 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
const data1 = [0, 1]

const SegmentA = buildSegment(data0, '#FBC02D', '#FFF9C4')
const SegmentB = buildSegment(data0, '#0097A7', '#B2EBF2')
const SegmentC = buildSegment(data1, '#D32F2F', '#FFCDD2')

const styles = StyleSheet.create({
  box: {
    justifyContent: 'center',
    alignItems: 'center',
    height: 250,
    width: '100%',
  },
  text: {
    fontSize: 32,
  },
})

export default Example

API reference

Core

Segmented.View

Basic usage looks like this:

import { Segmented } from 'react-native-collapsible-segmented-view'

const Example = () => {
   return (
     <Segmented.View hader={MyHeader}>
       <Segmented.Segment label="A" component={ScreenA} />
       <Segmented.Segment label="B" component={ScreenB} />
        <Segmented.Segment label="C" component={ScreenC} />
     </Tabs.Container>
   )
}

Props

|name|type|default| |:----:|:----:|:----:| |animatedValue|Value \| undefined|new Animated.Value(0)| |containerHeight|number \| undefined|0| |containerStyle|ViewStyle \| undefined|| |control|(props: ControlProps) => React.ReactElement|IS_IOS ? SegmentedControl : MaterialTabBar| |controlHeight|number \| undefined|48| |disableFadeIn|boolean \| undefined|false| |header|() => React.ReactElement|| |headerHeight|number \| undefined|| |initialIndex|number \| undefined|0| |lazy|boolean \| undefined|false| |topStyle|ViewStyle \| undefined||

Segmented.Segment

Wrap your screens with Segmented.Segment. Basic usage looks like this:

<Segmented.View ...>
  <Segmented.Segment label="A" component={ScreenA} />
  <Segmented.Segment label="B" component={ScreenB} />
  <Segmented.Segment label="C" component={ScreenC} />
</Segmented.Container>

Props

|name|type| |:----:|:----:| |component|() => React.ReactElement| |label|string|

Segmented.FlatList

Use like a regular flatlist.

Segmented.ScrollView

Use like a regular ScrollView.

Controls

SegmentedControl

Default iOS control. Props are passed down to the original SegmentedControl.

Example usage:

import {
  Segmented,
  SegmentedControl
} from 'react-native-collapsible-segmented-view

...

<Segmented.View
  control={(props) => <SegmentedControl {...props} appearance='dark' />}
>
  ...

Props

|name|type| |:----:|:----:| |containerStyle|ViewStyle \| undefined|

MaterialTabBar

Default android control.

Example usage:

import {
  Segmented,
  MaterialTabBar
} from 'react-native-collapsible-segmented-view

...

<Segmented.View
  control={(props) => <MaterialTabBar {...props} indicatorStyle='red' />}
>
  ...

Props

|name|type|default| |:----:|:----:|:----:| |containerStyle|ViewStyle \| undefined|| |inactiveOpacity|number \| undefined|0.7| |indicatorStyle|ViewStyle \| undefined|| |labelStyle|TextStyle \| undefined|| |pressColor|string \| undefined|DDDDDD| |pressOpacity|number \| undefined|IS_IOS ? 0.2 : 1| |tabStyle|ViewStyle \| undefined||

Hooks

useIsFocused

Returns true if the segment is focused, else returns false.

const isFocused = useIsFocused()

useSelectedIndex

Returns the current segment selected index.

const selectedIndex = useSelectedIndex()

useHeaderMeasurements

Returns translateY interpolation and the height of the header. See the animated header example.

const { translateY, height } = useHeaderMeasurements()

Alternative libraries

If you are looking for a full-featured tab bar with swiping, scrollable tabs, dynamic rendering, snapping and diffClamp:

Contributing

While developing, you can run the example app to test your changes.

Please follow the angular commit message format.

Make sure your code passes TypeScript and ESLint. Run the following to verify:

yarn typescript
yarn lint

To fix formatting errors, run the following:

yarn lint -- --fix

Remember to add tests for your change if possible.

Documentation changes

Edit the README_TEMPLATE, or update the docstrings inside the src folder, and run:

yarn docs