New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-native-spin-picker

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-spin-picker

A simple picker for React Native

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

react-native-spin-picker

A pure react native, spinner style select list with a simple interface.

Features

  • Snap to element selection
  • Text input
  • Single or long-press button navigation
  • Flat list style jsx interface
  • Customisable

Setup

This library is available on npm, install it with: npm i react-native-spin-picker or yarn add react-native-spin-picker.

Usage

    render() {
        return (
            <SpinPicker
                data={[...Array(100).keys()]}
                value={this.state.selectedItem}
                onValueChange={selectedItem => this.setState({selectedItem})}
                keyExtractor={number => number.toString()}
                renderItem={item => <Text>{item.toString()}</Text>}/>
        );
    }

A complete example

import React from 'react';
import {SafeAreaView, Text, View} from 'react-native';
import {SpinPicker} from 'react-native-spin-picker'

interface AppState {
  selectedItem: number
}

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

export default class App extends React.Component<{}, AppState> {
  constructor(props) {
    super(props);

    this.state = {
      selectedItem: 57
    };
  }

  render() {
    return (
        <SafeAreaView style={styles.container}>
          <View>
            <SpinPicker 
                    data={[...Array(100).keys()]}
                    value={this.state.selectedItem}
                    onValueChange={selectedItem => this.setState({selectedItem})}
                    keyExtractor={number => number.toString()}
                    showArrows
                    onInputValueChanged={this.onValueChanged}
                    renderItem={item => <Text>{item.toString()}</Text>}/>
          </View>
        </SafeAreaView>
    );
  }

  private onValueChanged = (value: string, previousValue: string): string => {
    const numberValue = Number(value);
    if (!isNaN(numberValue) && numberValue < 100) {
      this.setState({selectedItem: numberValue});
      return value;
    }

    return previousValue;
  };
}

Available props

NameTypeDefaultDescription
dataarrayrequiredAn array of any data to be presented
valueanyrequiredValue that is currently selected
onValueChangefunctionrequiredCalled whenever the selected item changed, should update value prop
renderItemfunctionrequiredRenders list items, all items should be rendered with the same height (use fixed height if possible)
keyExtractorfunctionrequiredExtracts a unique key from each data item, used for object comparison
showArrowsboolfalseShows navigation arrows
onInputValueChangedfunctionundefined (no text input)Include to enable text entry, return value updates input (allows formatting or restrictions)
textInputPropsobjectundefinedInput props applied to text input when enabled by onInputValueChanged (allows for input type, etc)
textInputStyleobjectundefinedInput style applied to text input when enabled by onInputValueChanged

Keywords

expo

FAQs

Package last updated on 12 Sep 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