Giter Site home page Giter Site logo

novlr / react-native-smooth-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rdhox/react-native-smooth-picker

0.0 2.0 0.0 3.61 MB

A smooth picker for react-native

License: MIT License

Python 7.90% Java 6.52% JavaScript 67.81% Objective-C 17.76%

react-native-smooth-picker's Introduction

React Native Smooth Picker

alt text

install

npm i react-native-smooth-picker

A React Native picker that used Flatlist component to easily display vertical or horizontal list.
The item in the middle of the list (per default) is selected. Work exactly like a Flatlist component with the additionnals props:

Props

Props Description Type Default
onSelected function that have for argument ({ item, index }) of the selected item. function
offsetSelection offset to move the abstract line from the middle of the list where items are selected number 0
magnet scroll automatically on the selected item boolean false
initialScrollToIndex if you want the list to scroll to an initial index after mounting number
scrollAnimation true if you want the scroll te be animated boolean false
snapInterval if all items of the list have the same height (vertical) or width (horizontal), enter the dimension here to activate the snapToInterval props. Notice that if you use this prop, the magnet comportment will not work. number null
snapToAlignment If you use snapInterval, you can set snapToAlignment to 'start', 'center', 'end'. enum 'center'
startMargin Values of margins at the extremities of the list are calculated automatically. If values do not correspond to your need, you can enter them manually. number
endMargin Values of margins at the extremities of the list are calculated automatically. If values do not correspond to your need, you can enter them manually. number

Using Flatlist's methods

To use flatlist's methods with SmoothPicker, use the reference name "smoothPicker" (see /example/example.js) :

this.myref.refs.smoothPicker.scrollToIndex();

Simple Example

import SmoothPicker from "react-native-smooth-picker";

export default class App extends Component {
  state = {
    selected: null
  };

  handleChange = index => {
    this.setState({
      selected: index
    });
  };

  render() {
    const { selected } = this.state;
    return (
      <SmoothPicker
        offsetSelection={40}
        magnet
        scrollAnimation
        data={Array.from({ length: 16 }, (_, i) => i)}
        onSelected={({ item, index }) => this.handleChange(index)}
        renderItem={({ item, index }) => (
          <Number selected={index === selected}>{item}</Number>
        )}
      />
    );
  }
}

You can find the code of the gif above in the example/ folder.

Author

rdhox - Steed Monteiro

react-native-smooth-picker's People

Contributors

rdhox avatar steedmonteiro avatar muhleder avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.