npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-simple-wheel-picker

v0.2.1

Published

[![Version][version-badge]][package] [![MIT License][license-badge]][license]

Downloads

73

Readme

React Native Simple Wheel Picker

Version MIT License

A cross-platform wheel picker component for React Native in pure Javascript.

  • Checkout the example/ folder for source code.

Features

  • 100% Javascript
  • Highly customizable
  • Provides accesibility labels

Demo

Installation

Open a Terminal in the project root and run:

npm install react-native-simple-wheel-picker

We're done! Now you can build and run the app on your device/simulator.

Quick Start

import React, { useState, useCallback } from 'react';
import { TextInput, View, Text, ScrollView, StyleSheet } from 'react-native';
import { WheelPicker } from "react-native-simple-wheel-picker"

const styles = StyleSheet.create({
  input: { margin: 20, backgroundColor: 'gray', color: '#ECEFF0', marginTop: 5 }
})

const App = () => {
  const [index, setIndex] = useState(0)
  const onChangeIndex = useCallback((index) => {
    const result = parseInt(index)
    if (isNaN(result)) {
      setIndex(0)
    }
    else {
      setIndex(result)
    }
  })
  const [countItem] = useState(12)
  const items = [...Array(countItem).keys()].map((index) => `This is item ${index}`)

  return (
    <View style={{ flex: 1, justifyContent: 'flex-end' }}>
      <TextInput style={styles.input} keyboardType={'numeric'} value={'' + index || ''} onChangeText={onChangeIndex} />
      <WheelPicker
        onSelected={onChangeIndex}
        selectedIndex={index}
        items={items}
        backgroundColor={'#ECEFF0'} />
    </View>
  )
}
export default App;

API reference

The package exports a WheelPicker component which is the one you'd use to render the wheel picker view.

WheelPicker

Container component responsible for rendering and the wheel picker.

Basic usage look like this:

<WheelPicker
  onSelected={setIndex}
  selectedIndex={index}
  items={items}
/>

Props

onSelected (required)

Callback which is called on wheel picker change, receives the index of the new selected item as argument. The current selected index state needs to be updated when it's called, otherwise the change is dropped.

selectedIndex (required)

This is the current selected index that needs to be updated when the picker change. You can use this property to update the selected item. Default value is 0.

itemHeight (optional)

Height of each item of the picker needs to be upper to zero. The global height of the container depends on the height of each item. Default value is 40.

<WheelPicker
  onSelected={setIndex}
  selectedIndex={index}
  itemHeight={30}
/>
countVisibleItems (optional)

The minimum number of visible items to be displayed. The global height of the container depends on the number of visible items. Default value is 2

<WheelPicker
  onSelected={setIndex}
  selectedIndex={index}
  countVisibleItems={6}
/>
items (optional)

An array of string items that needs to be displayed. This array can be updated any time, the picker will refresh its content according to the new array. Default value is [].

<WheelPicker
  onSelected={setIndex}
  selectedIndex={index}
  items={["A", "B", "C"]}
/>

You need to extract the corresponding value using the selectedIndex property, eg:

const [data, setData] = useState(["A", "B", "C"])
<TextInput value={data[index]} />
<WheelPicker
  onSelected={setIndex}
  selectedIndex={index}
  items={data}
/>
backgroundColor (optional)

Define background of the wheel picker. Default value is undefined.

separatorBackgroundColor (optional)

Define color of the separators. Default value is #4DB6AC.

separatorMarginHorizontal (optional)

Define the horizontal margin of the separators. Default value is 20.

separatorHeight (optional)

Define the size of the separators. Default value is 1.

itemTextStyle (optional)

Define the text style of each displayed item. Default value is undefined.

selectedItemTextStyle (optional)

Define the text style of each selected item. Default value is { fontWeight: 'bold', color: '#37474F' }.

unselectedItemTextStyle (optional)

Define the text style of each selected item. Default value is { fontWeight: 'normal', color: '#ADADAD' }.

Accessibility labels

The component provides some accessilibility labels, the general format is picker:<accessibility label>

Items of the picker

picker_item

Accessibility label for This is item 0 would be picker:This is item 0

Contributing

While developing, you can run the example app to test your changes.

Make sure your code passes unit tests. Run the following to verify:

npm run test

Remember to add tests for your change.