1.0.2 • Published 4 years ago

react-native-action-sheet-modal v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

react-native-action-sheet-modal

Highly customizable Action sheet modal for react native.

Setup

This library is available on npm, install it with: npm i react-native-action-sheet-modal.

Usage

  1. Import Actionsheet from react-native-action-sheet-modal:
import Actionsheet from 'react-native-action-sheet-modal';
  1. Create a modal and nest its content inside of it:
function OptionsWindow() {
  return (
    <ActionSheet options={list} isVisible={visible} onClose={()=>onClose()} onChange={onChange}/>
  )
}

A complete example

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow strict-local
 */

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

import ActionSheet from 'react-native-action-sheet-modal'

const App = () => {
  const [visible, setVisible] = useState(false)
  const [result, setResult] = useState('')
  const list = [{ name: "Choose from camera", value: 'Choose from camera', extraData:{type:"video"} }, { name: "Choose from gallery", value: 'Choose from gallery', extraData:{type:"video"} }]

  function onChange(value, extraData) {
    setResult(value)
    onClose()
  }

  function onClose(){
    setVisible(false)
  }

  return (
    <>
      <ActionSheet options={list} isVisible={visible} onClose={()=>onClose()} onChange={onChange}/>
      <View style={styles.container}>
        <TouchableOpacity 
        onPress={()=>setVisible(true)}
        style={styles.button}><Text>Open</Text></TouchableOpacity>
        <Text>{result}</Text>
      </View>
    </>
  );
};



const styles = StyleSheet.create({
  container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  button:{ paddingHorizontal: 20, marginVertical:20, paddingVertical: 10, backgroundColor: "cyan", borderRadius: 10, },
});

export default App;

Props

NameTypeRequiredDescriptionDefault
isVisiblebooleanYesboolean value(true/false) to open/close the action sheet.false
onClosefunctionYesfunction to call while clicking cancel button and the backdrop area() => {}
optionsarrayYeslist of options to display[]
onChangefunctionYesfunction to call while choosing an option() => {}
hideCancelbooleanNoto hide the bottom cancel buttonfalse
cancelTextstringNotext to be display on the cancel button"Cancel"
cancelTextStyleobjectNoto update the style of the cancel button text
cancelContainerStyleobjectNoto update the style of the cancel button container
optionsTextStyleobjectNoto update the text style of the options
optionsContainerStyleobjectNoto update the options container style
modalPropsobjectNoIt accepts all the props of the react-native-modal package. For all props, Kindly refer the react-native-modal package.

Pull requests, feedbacks and suggestions are welcome!