1.0.5 • Published 12 months ago

react-native-sheet-view v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

React Native Sheet View

A simple bottom sheet component for any React Native project
iOSAndroid
MainDemonstrationMainDemonstration

Installation

npm install --save react-native-sheet-view

or

yarn add react-native-sheet-view

Import the BottomSheet component

import BottomSheet from 'react-native-sheet-view';

Usage

import React, { useState } from 'react';
import {
  Text,
  View,
  StyleSheet,
  Button,
  Alert,
} from 'react-native';

import BottomSheet from 'react-native-sheet-view';

const App = () => {
  const [isBottomSheetVisible, setBottomSheetVisible] = useState(false);

  const showBottomSheet = () => {
    setBottomSheetVisible(true);
  }

  const hideBottomSheet = () => {
    setBottomSheetVisible(false);
  }

  const options = [
    'Option 1',
    'Option 2',
    'Option 3',
  ];

  return (
    <View
      style={styles.container}
    >
      <Text>React Native Sheet View</Text>

      <Button
        title='Show Bottom Sheet'
        onPress={showBottomSheet}
      />

      <BottomSheet
        visible={isBottomSheetVisible}
        options={options}
        onSelect={(index) => {
          Alert.alert(
            `${options[index]`,
            `You selected ${options[index]}`,
            [
              {
                text: 'OK',
              },
            ],
          )
        }}
        onCancel={hideBottomSheet}
        showCancelText={true}
        cancelText='Cancel'
        headerTitle='Bottom Sheet'
      />
    </View>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
})

export default App;

Props

PropTypeRequiredDescription
visibleuseState HookYesDisplay or hide the bottom sheet
optionsstring arrayYesDisplays the options available for your bottom sheet
onSelectfunctionYesDispatches the action selected for the option once selected
onCancelfunctionYesDispatches the action canceled for the option already selected
headerTitlestringNoShows your input as the header title of your bottom sheet
titleColorstringNoChange the color of your title text if you have a headerTitle
showCancelTextbooleanNoShows the Cancel button detached below the bottom sheet
cancelTextstringNoShows your input as the cancel text in the cancel button
lineColorstringNoChange the color of the lines between each option
backgroundColorstringNoChange the color of the background of your bottom sheet

headerTitle

Shows your input as the header title of your bottom sheet

iOSAndroid
HeaderTitleHeaderTitle

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  headerTitle='Header Title'
/>

titleColor

Change the color of your title text if you have a headerTitle

You won't see any changes if you don't have a headerTitle

iOSAndroid
TitleColorTitleColor

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  headerTitle='Header Title'
  titleColor='purple'
/>

showCancelText

Shows the Cancel button detached below the bottom sheet

Default: false

iOSAndroid
ShowCancelTextShowCancelText

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  showCancelText={true}
/>

cancelText

Shows your input as the cancel text in the cancel button

You won't see any changes if you don't have showCancelText set to true

iOSAndroid
CancelTextCancelText

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  showCancelText={true}
  cancelText='Cancelar' // <- Spanish word for 'Cancel'
/>

lineColor

Change the color of the lines between each option

iOSAndroid
LineColorLineColor

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  lineColor='red'
/>

backgroundColor

Change the color of the background of your bottom sheet

iOSAndroid
BackgroundColorBackgroundColor

<BottomSheet
  visible={isBottomSheetVisible}
  options={options}
  onSelect={(index) => {
    Alert.alert(
      `${options[index]`,
      `You selected ${options[index]}`,
      [
        {
          text: 'OK',
        },
      ],
    )
  }}
  onCancel={hideBottomSheet}
  backgroundColor='purple'
/>

License

React Native Sheet View is under the MIT License. See bundled LICENSE file for details.

1.0.5

12 months ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago