Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A cross-platform Collapsible Segmented View component for React Native

License

NotificationsYou must be signed in to change notification settings

PedroBern/react-native-collapsible-segmented-view

Repository files navigation

Build StatusVersionMIT Licenseruns with expo

Expo app

Collapsible Segmented View for React Native.

Credits

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

Demo

iosandroid

Features

Installation

Open a Terminal in the project root and run:

yarn add react-native-collapsible-segmented-viewexpo install @react-native-community/segmented-control

Quick Start

importReactfrom'react'import{View,StyleSheet,ListRenderItem,Text}from'react-native'import{Segmented}from'react-native-collapsible-segmented-view'constHeader=()=>{return(<Viewstyle={styles.box}pointerEvents="box-none"><Textstyle={styles.text}>Collapsible Header</Text></View>)}constExample:React.FC=()=>{return(<Segmented.Viewheader={Header}><Segmented.Segmentlabel="A"component={SegmentA}/><Segmented.Segmentlabel="B"component={SegmentB}/><Segmented.Segmentlabel="C"component={SegmentC}/></Segmented.View>)}constbuildRenderItem=(color0:string,color1:string)=>{constrenderItem:ListRenderItem<number>=(data)=>{constbackgroundColor=data.index%2===0 ?color0 :color1constcolor=data.index%2===0 ?color1 :color0return(<Viewstyle={[styles.box,{ backgroundColor}]}><Textstyle={[{ color},styles.text]}>{data.index}</Text></View>)}returnrenderItem}constbuildSegment=(data:number[],color0:string,color1:string)=>{constSegment=()=>{return(<Segmented.FlatListdata={data}renderItem={buildRenderItem(color0,color1)}keyExtractor={(v)=>v+''}/>)}returnSegment}constdata0=[0,1,2,3,4,5,6,7,8,9,10]constdata1=[0,1]constSegmentA=buildSegment(data0,'#FBC02D','#FFF9C4')constSegmentB=buildSegment(data0,'#0097A7','#B2EBF2')constSegmentC=buildSegment(data1,'#D32F2F','#FFCDD2')conststyles=StyleSheet.create({box:{justifyContent:'center',alignItems:'center',height:250,width:'100%',},text:{fontSize:32,},})exportdefaultExample

API reference

Core

Segmented.View

Basic usage looks like this:

import{Segmented}from'react-native-collapsible-segmented-view'constExample=()=>{return(<Segmented.Viewhader={MyHeader}><Segmented.Segmentlabel="A"component={ScreenA}/><Segmented.Segmentlabel="B"component={ScreenB}/><Segmented.Segmentlabel="C"component={ScreenC}/></Tabs.Container>)}

Props

nametypedefault
animatedValueValue | undefinednew Animated.Value(0)
containerHeightnumber | undefined0
containerStyleViewStyle | undefined
control(props: ControlProps) => React.ReactElementIS_IOS ? SegmentedControl : MaterialTabBar
controlHeightnumber | undefined48
disableFadeInboolean | undefinedfalse
header() => React.ReactElement
headerHeightnumber | undefined
initialIndexnumber | undefined0
lazyboolean | undefinedfalse
topStyleViewStyle | undefined

Segmented.Segment

Wrap your screens withSegmented.Segment. Basic usage looks like this:

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

Props

nametype
component() => React.ReactElement
labelstring

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 originalSegmentedControl.

Example usage:

import{Segmented,SegmentedControl}from'react-native-collapsible-segmented-view...<Segmented.Viewcontrol={(props)=><SegmentedControl{...props}appearance='dark'/>}>  ...

Props

nametype
containerStyleViewStyle | undefined

MaterialTabBar

Default android control.

Example usage:

import{Segmented,MaterialTabBar}from'react-native-collapsible-segmented-view...<Segmented.Viewcontrol={(props)=><MaterialTabBar{...props}indicatorStyle='red'/>}>  ...

Props

nametypedefault
containerStyleViewStyle | undefined
inactiveOpacitynumber | undefined0.7
indicatorStyleViewStyle | undefined
labelStyleTextStyle | undefined
pressColorstring | undefinedDDDDDD
pressOpacitynumber | undefinedIS_IOS ? 0.2 : 1
tabStyleViewStyle | undefined

Hooks

useIsFocused

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

constisFocused=useIsFocused()

useSelectedIndex

Returns the current segment selected index.

constselectedIndex=useSelectedIndex()

useHeaderMeasurements

ReturnstranslateY 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 theexample app to test your changes.

Please follow theangular commit message format.

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

yarn typescriptyarn lint

To fix formatting errors, run the following:

yarn lint -- --fix

Remember to add tests for your change if possible.

Documentation changes

Edit theREADME_TEMPLATE, or update the docstrings inside thesrc folder, and run:

yarn docs

About

A cross-platform Collapsible Segmented View component for React Native

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp