1.0.3 • Published 3 years ago

@wowmaking/react-native-ios-scroll-picker v1.0.3

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

@wowmaking/react-native-ios-scroll-picker

React Native Scroll Picker like IOS UIDatePicker on iOS and Android.

npm version License: MIT

npm.ionpm.ionpm.ionpm.io

Installation

Open a Terminal in the project root and run:

yarn add @wowmaking/react-native-ios-scroll-picker

Or if you use npm:

npm i @wowmaking/react-native-ios-scroll-picker --save

Now we need to install: react-native-gesture-handler; react-native-reanimated; react-native-haptic-feedback;

Usage

import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import Picker from '@wowmaking/react-native-ios-scroll-picker';

const start = 2000;
const years = new Array(new Date().getFullYear() - start + 1)
  .fill(0)
  .map((_, i) => {
    const value = start + i;
    return { value, label: value };
  })
  .reverse();

const App = () => {
  const defaultValue = 2010;
  const [currentValue, setCurrentValue] = useState(defaultValue);

  const handelPickerItemChange = (value) => {
    setCurrentValue(value);
  };

  return (
    <View style={styles.pickerContainer}>
      <Picker
        values={years} 
        containerWidth={120}
        defaultValue={defaultValue} 
        withTranslateZ={true}
        withOpacity={true}
        withScale={true}
        visibleItems={5}
        itemHeight={32}
        deviderStyle={styles.pickerDevider}
        labelStyle={styles.pickerItemLabel}
        onChange={handelPickerChange}
      />

      <Text>{currentValue}</Text>
    </View>
  );
};

export default App;

const styles = StyleSheet.create({
  pickerContainer: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center',
  },
  pickerDevider: {
    borderColor: 'rgba(0,0,0,0.1)',
    borderTopWidth: 1,
    borderBottomWidth: 1, 
  },
  pickerItemLabel: {
    color: '#000000',
    fontSize: 25,
  },
});

Props

namerequireddefaultdescription
valuesyesItems Array
containerWidthyesDefines width of gesture container
visibleItemsyesDefines how many items will be visible
itemHeightyesItem height
defaultValueno0Defines selected item by default
withTranslateZnofalseEnable
withScalenofalse
withOpacitynofalse
deviderStylenoStyles for the Devider
labelStylenoStyles for label Items