0.1.1 • Published 2 years ago

@jaichaudhary/react_native_dropdown v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react_native_dropdown

A React Native dropdown component easy to customize for both iOS and Android.

Features

  • Multiple Dropdown types in one package
  • Easy to use
  • Consistent look and feel on iOS and Android
  • Customizable font size, colors and styling
  • Implemented with javascript

Getting started

npm install @jaichaudhary/react_native_dropdown --save

or

yarn add @jaichaudhary/react_native_dropdown

Dropdown types

import { HandyDrop } from "@jaichaudhary/react_native_dropdown";

and

import { ModalDrop } from "@jaichaudhary/react_native_dropdown";

Demo

HandyDrop

HandyDrop

ModalDrop

ModalDrop

Example

const App = () => {
  const [isOpen, setIsOpen] = useState(false);
  const [output, setOutput] = useState("");
  const arr = [
    "text",
    "kill me!",
    "hello ji",
    "text",
    "kill me!",
    "hello ji",
    "text",
    "kill me!",
    "hello ji",
    "text",
    "kill me!",
    "hello ji",
  ];
  const returnVal = (val) => {
    setOutput(val);
    setIsOpen(false);
  };
  return (
    <View contentContainerStyle={{ flex: 1 }}>
      <View
        style={{
          displya: "flex",
          flex: 1,
          alignItems: "center",
          justifyContent: "center",
        }}
      >
        <Text>{output}</Text>
        <TouchableOpacity
          style={{ backgroundColor: "pink", padding: 10 }}
          onPress={() => {
            setIsOpen(true);
          }}
        >
          <Text>Click here!</Text>
        </TouchableOpacity>
        {isOpen && (
          <HandyDrop value={arr} returnVal={returnVal} />
          // <ModalDrop
          //   value={arr}
          //   returnVal={returnVal}
          //   // modalViewStyle={{backgroundColor: 'yellow'}}
          // />
        )}
      </View>
    </View>
  );
};

Dropdown Props

PropsParamsisRequireDescription
valueArrayYesData is a plain array
returnValCallback functionYesGives us the slected data
parentViewStyleObjectNoStyling for the parent View
modalViewStyleObjectNoStyling for the modal View
textParentStyleObjectNoStyling for the parent View of text
selectTextStyleObjectNoStyling for the select an item text
textStyleObjectNoStyling for the text in dropdown