1.2.4 • Published 3 years ago

react-native-cross-picker v1.2.4

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

react-native-cross-picker

npm version

A Picker component for React Native which emulates the native <select> interfaces for iOS and Android

For iOS, Android or other platform this component looks same.

View examples on snack.expo.io

Getting Started

Installing

npm install react-native-cross-picker

Basic Usage

import React, { useState } from 'react';
import { StyleSheet, View } from 'react-native';
import { MaterialCommunityIcons } from "@expo/vector-icons"; // for expo and any other for react-native-cli

import ReactNativeCrossPicker from "react-native-cross-picker"


export default function Picker() {
  const [selectedItem, setItem] = useState('')

 const items = [
    { label: "label1", value: 1 },
    { label: "label2", value: 2 },
    { label: "label3", value: 3 },
    { label: "label4", value: 4 },
    { label: "label5", value: 5 },
    { label: "label6", value: 6 },
    { label: "label7", value: 7 },
    { label: "label8", value: 8 },
    { label: "label9", value: 9 },
  ]

  const iconComponent = () => {
    return <MaterialCommunityIcons
      name={"chevron-down"}
      size={20}
      color={"grey"}
    />
  }

  return (
    <View style={styles.container}>
      <ReactNativeCrossPicker
          modalTextStyle={{ color: "rgb(0, 74, 173)" }}
          mainComponentStyle={{ borderColor: "rgb(0, 74, 173)" }}
          iconComponent={iconComponent}
          items={items}
          setItem={setItem} selectedItem={selectedItem}
          placeholder="Select Item" 
          modalMarginTop={"50%"} // popup model margin from the top 
      />
    </View>
  );
}

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

Props

NameDescriptionDetails
setItemWill set the selected value to selectedItemrequireduseState hook
itemsThe items for the component to render - Each item should be in the following format:{label: 'Orange', value: 'orange'}- label and value are required- value can be any data type-requiredarray
placeholder- An override for the default placeholder, a label of Select itemstring
placeholderStyle- An override for the default placeholder stylestyle
modalTextStyleStyle overrides for text parts of the popup component.style
modalComponentStyleStyle overrides the style of the popup component.style
mainComponentStyleStyle overrides style of the main component.style
modalBottomBorderColorAdditional props to pass to the Picker to display the bottom border of main componentcolor
iconComponentCustom icon component to be rendered.function that return component
widthAdditional props to pass to the main component to set the width default will be 100%.number, percentage like width="80%".
placeholderDefault placeholder when item is not selectedstring
modalMarginTopmargin of the popup model from the top default will be 50%number, percentage etc.
modalMaxHeightMaximum hight of the popup modalnumber, percentage etc.

License

react-native-cross-picker is MIT licensed and built with :heart: by Zahid Ali.