All Projects → PedroBern → react-native-collapsible-segmented-view

PedroBern / react-native-collapsible-segmented-view

Licence: MIT license
A cross-platform Collapsible Segmented View component for React Native

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-collapsible-segmented-view

PageSegment
左右滑动切换页面,TabBar支持小红点显示。
Stars: ✭ 89 (+140.54%)
Mutual labels:  tabbar, segmented-controls
react-native-segment-controller
A react-native segment controller(Tab) for both ios and android.
Stars: ✭ 18 (-51.35%)
Mutual labels:  tabbar, segmented-controls
react-native-appsync-s3
React Native app for image uploads to S3 and storing their records in Amazon DynamoDB using AWS Amplify and AppSync SDK
Stars: ✭ 18 (-51.35%)
Mutual labels:  expo
status-bar-height
Listen to status bar changes during incoming calls and other multi-tasking events
Stars: ✭ 73 (+97.3%)
Mutual labels:  expo
Motion-Tab-Bar
A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.
Stars: ✭ 237 (+540.54%)
Mutual labels:  tabbar
react-native-expo-web
All-in-one React Native project (Expo + react-native-web)
Stars: ✭ 16 (-56.76%)
Mutual labels:  expo
expo-doodle-jump
No description or website provided.
Stars: ✭ 44 (+18.92%)
Mutual labels:  expo
react-native-walkthrough
React Native Walkthrough User Onboarding Flow to start your react native app development
Stars: ✭ 37 (+0%)
Mutual labels:  expo
react-native-viewpager-carousel
a flexible viewpager library with carousel functionality
Stars: ✭ 39 (+5.41%)
Mutual labels:  tabbar
smovie-expo
[New] New version with more examples: https://github.com/theo-mesnil/WhatToWatch [Old version] Smovie is the simplest and fastest way to discover movies, series and actors. With React Native, Expo and themoviedb 🎥
Stars: ✭ 19 (-48.65%)
Mutual labels:  expo
react-native-news-app
Get breaking news headlines with short description filtered by your interests and country preferences
Stars: ✭ 75 (+102.7%)
Mutual labels:  expo
maker
Maker is a advanced mobile ToDo app for Android and iOS
Stars: ✭ 35 (-5.41%)
Mutual labels:  expo
rn-mirror-lists
🪞 Mirror scroll lists for React Native
Stars: ✭ 38 (+2.7%)
Mutual labels:  expo
expo-ui-kit
expo-ui-kit - a components based React-Native UI Kit
Stars: ✭ 88 (+137.84%)
Mutual labels:  expo
Expo-Super-Mario-World
Native Super Mario World in Expo
Stars: ✭ 24 (-35.14%)
Mutual labels:  expo
RN-Book-Search
A Book search app using Expo (React Native) and Google Books API
Stars: ✭ 29 (-21.62%)
Mutual labels:  expo
react-native-firebase-redux-authentication
Firebase Authentication using React Native, Redux, Router flux.
Stars: ✭ 45 (+21.62%)
Mutual labels:  expo
ViewPagers
When using the ViewPager widget it is not always obvious to the user that there are adjacent views they can navigate to. By implementing this widget you provide a clear indicator that there exists additional content which they can click or swipe to see.
Stars: ✭ 43 (+16.22%)
Mutual labels:  segmented-controls
react-native-multi-selectbox
Platform independent (Android / iOS) Selectbox | Picker | Multi-select | Multi-picker. The idea is to bring out the common user interface & user experience on both platforms.
Stars: ✭ 169 (+356.76%)
Mutual labels:  expo
react-native-msal
MSAL for React Native
Stars: ✭ 62 (+67.57%)
Mutual labels:  expo

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].