1.1.9 • Published 9 months ago

react-native-option-dropdown v1.1.9

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

react-native-option-dropdown

Demo 1Demo 2

Why ?

This library is created in an attempt to provide a lightweight, simple and customizable dropdown solution for react native apps .

It try to solve the problem of having to install very heavy and big libraries for something as simple as a dropdown, as react native does not have any by default. this library is build by deafult react native tools so it's not dependent on other libraries.

It is so simple you can go to your project node_modules/react-native-option-dropdown/index.js and edit the code yourself and cusomize it even more. OR copy the code from there and use it anywhere as a component, no need to installing anything else. 🎉

Getting started 🤖

$ npm i react-native-option-dropdown

MacOS 🖥

CocoaPods on MacOS needs this extra step , Go to ios folder and run.

pod install

Usage 🛠

Import Dropdown from react-native-option-dropdown

import Dropdown from 'react-native-option-dropdown';

Create state which will be used by the Dropdown:

const [selectedItem, setSelectedItem] = useState(null);

Add Dropdown like this:

import { StyleSheet, Text, View } from 'react-native'
import React, {useState} from 'react';
import Dropdown from 'react-native-option-dropdown'

const App = () => {
    const [selectedItem, setSelectedItem] = useState(null);

    let data = [
        {id: 1, name: 'All'},
        {id: 2, name: 'Today'},
        {id: 3, name: 'Yesterday'},
        {id: 4, name: 'Current Week'},
      ];

      const onSelect = item=>{
        setSelectedItem(item);
        alert(item.name)
      } 
  return (
    <View style={{marginTop:'10%'}}>
          <Dropdown
          data={data}
          onSelect={onSelect}
          value={selectedItem}
          transparent ={false}
          alignList={'center'}
          fontSize={20}
          defaultText={"Please Select"}
          animationType={'slide'}
          DropdownWidth={'50%'}
          dropDownStyle ={
               {paddingVertical: 4,
               paddingHorizontal: 8,
               borderRadius: 3,
               minHeight: 32,
               justifyContent: 'space-between',
               flexDirection: 'row',
               alignItems: 'center',
               marginBottom: 8,
               borderColor: '#000',
               borderWidth: 0.5,
             overflow:'scroll' }
          }
        />
    </View>
  )
}

export default App

Props 🗝

PropTypeOptionalDefaultDescription
dataArray of objects . (id: Key must be there in every object) as shown aboveNofalseData for the dropdown options.
onSelectFunctionNofalsefunction that will run after selecting the option from dropdown.
transparentBoolNofalseIt will change the dropdown backround, will take true & false .
valueStringNofalseIt will take the value of state to show after selecting a option (as shown in the example above).
alignListStringNofalseIt is for postion of dropdown list, will take tree options as string center , flex-end & flex-start.
fontSizeNumberNofalseIt will change the font size.
animationTypeStringNofalseThe animationType prop controls how the modal animates. It will take three values none , slide & fade as String.
defaultTextStringNofalseIt is default text when nothing is selected.
dropDownStyleObjectNofalseThis is for dropdown style. It will take any default React Native style .

Suggestions and feedback are welcome at sahilbakoru1999@gmail.com .

1.1.9

9 months ago

1.1.8

9 months ago

1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago