Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-segmented-picker

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-segmented-picker

A segmentable dropdown picker wheel with no native dependencies.

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Native Segmented Picker

CircleCI NPM Version MIT Licence

A pure JavaScript implementation of the iOS style wheel spinner dropdown picker that is typically used for date and time selection.

  • Supports one or many columns (list segments).
  • Show any data in the picklists, not just dates and times.
  • Customisable colors and sizing.
  • Does not rely on native dependencies (npm link not required).
  • Works with apps built on Expo.

Installation

$ yarn add react-native-segmented-picker
# or
# $ npm install --save react-native-segmented-picker

Usage

import React, { Component } from 'react';
import SegmentedPicker from 'react-native-segmented-picker';

class Example extends Component {
  constructor(props) {
    super(props);
    this.segmentedPicker = React.createRef();
  }

  componentDidMount() {
    // Can alternatively be shown with the `visible` prop for redux etc.
    this.segmentedPicker.show();
  }

  onConfirm = (selections) => {
    console.info(selections);
    // => { column1: { label: 'Option 1' }, column2: { label: 'Option 3' } }
  }

  render() {
    return (
      <SegmentedPicker
        ref={this.segmentedPicker}
        onConfirm={this.onConfirm}
        options={{
          column1: [
            { label: 'Option 1' },
            { label: 'Option 2' },
          ],
          column2: [
            { label: 'Option 3' },
          ],
        }}
      />
    );
  }
}

Further examples can be found in ./examples/src.

Props, Events & Methods Reference

Props

PropDescriptionDefault
optionsData to be populated into the picklists. {columnId: [{label: ''}, ...], ...}
visibleNot used by default. Set to true or false to manually handle visibility.null
defaultSelectionsEg: {columnId: 'label string to auto-select', ...}{}
confirmTextText displayed in the top right hand corner.'Done'
sizeFixed percentage of the screen to render the picklist container over.40
confirmTextColorColor of the confirmText button.'#0A84FF'
toolbarBackgroundBackground color of the top container where the confirmText is displayed.'#FAFAF8'
toolbarBorderColorBottom border color of the toolbarContainer.'#E7E7E7'
listItemTextColorColor of the text for each item in the picklist.'#282828'
selectionMarkerBackgroundBackground color of the container which overlays the current selected item.'#F8F8F8'
selectionMarkerBorderColorBorder color (top and bottom) of the selection marker overlay.'#DCDCDC'
containerBackgroundBackground color of the inner SegmentedPicker container.'#FFFFFF'

Event Props

Event PropWhen and how?
onValueChange={(columnId, value) => ...}Emitted each time a picklist value is modified by a user.
onCancel={(selections) => ...}Emitted when a user touches out of the modal, or presses the hardware back button on Android.
onConfirm={(selections) => ...}Emitted when a user presses the confirm text button.

Methods

Remember that you will need to set a ref for the <SegmentedPicker /> component in order to use the methods outlined below.

ref.show();

Display the Segmented Picker modal over all other content on the screen. This is the preferred method of showing a <SegmentedPicker /> so that you don't have to manually hide the component after listening to the onCancel and onConfirm events.

Note that this method will have no effect if the visible prop is set.

ref.hide();

Hide the Segmented Picker modal from the screen. Generally should not be required, as this method is automatically called by this library after events where visibility should be toggled off.

ref.selectLabel(label, columnId, animated=true, emitEvent=true, zeroFallback=false);

Programmatically select a label from a list column while the component is displaying.

  • {string} label: Eg 'Option 1'
  • {string} columnId: Eg 'column1'
  • {boolean=true} animated: Scroll or snap to the item?
  • {boolean=true} emitEvent: Specify whether to emit the onValueChange event.
  • {boolean=false} zeroFallback Select the first list item if not found.
ref.selectIndex(index, columnId, animated=true, emitEvent=true);

Programmatically select an array index from a list column while the component is displaying. This method will give you better performance than the above if you already know the index of the item that you want to select.

  • {number} index: Eg 0
  • {string} columnId: Eg 'column1'
  • {boolean=true} animated: Scroll or snap to the item?
  • {boolean=true} emitEvent: Specify whether to emit the onValueChange event.
ref.getCurrentSelections();

Returns the current selected items as they appear in the UI. This is the same method that's used internally when the onCancel and onConfirm events are fired.

Contributions

This is an open source project. Bug fixes, improvements and the addition of useful new features to this package are greatly appreciated.

  1. Fork and clone the repository from GitHub.
  2. Setup: yarn install.
  3. Checkout a new branch, eg: feature/my-thing or bugfix/terrible-thing.
  4. After making any changes, make sure that yarn run test still passes.
  5. Ask yourself if there's a new unit test that you could write to capture your changes?
  6. Submit a pull request to master outlining what your change is and how you tested it.

Made with love in Melbourne Adam McArthur.

Keywords

FAQs

Package last updated on 13 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc