0.1.12 • Published 5 years ago

rn-scrollable-picker v0.1.12

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

rn-scrollable-picker

All Contributors

A pure JS scrollable picker solution for react-native, highly customizable.

-Auto height detection

example

Usage

npm i rn-scrollable-picker
import React, {Component} from 'react';
import ScrollPicker from 'rn-scrollable-picker';

export default class SimpleExample extends Component {


    handleClick = (index, options, onValueChange) => {
        this.sp.scrollToIndex(index);   // select 'c'
        onValueChange(options[index]);
    }

    render() {
        return(
            <ScrollPicker
                ref={(sp) => {this.sp = sp}}
                dataSource={options}
                selectedIndex={0}
                itemHeight={ITEM_HEIGHT}
                wrapperHeight={500}
                wrapperStyle={{
                    backgroundColor: 'transparent'
                }}
                renderItem={(data, index, isSelected) => {
                    return(
                        <TouchableOpacity 
                        onPress={() => this.handleClick(index, options, onValueChange)} 
                        style={{height: ITEM_HEIGHT}}>
                            <Text style={isSelected ? {
                                    color: '#fff',
                                    textAlign: 'center',
                                    fontSize: 34,
                                    height: 50,
                                    fontWeight: 'bold'
                                } : {
                                    color: '#fff',
                                    textAlign: 'center',
                                    fontSize: 20,
                                    height: 50,
                                    fontWeight: '300'
                                }}
                            >
                                {data}
                            </Text>
                        </TouchableOpacity>
                    )
                }}
                onValueChange={(data, selectedIndex) => {
                    onValueChange(options[selectedIndex]);
                }}
            />
    );
    }
}

Props

PropRequiredDefaultParams typeDescription
dataSourceyesArrayPicker data
wrapperHeightyesNumberPicker window height
renderItemnoFunctionRenders picker options
selectedIndexno0NumberDefault selected value
onValueChangeno() => {}FunctionCalled on valie change
highlightStylenoStyle arrayCalled when epg boundaries are left
wrapperStylenoStyle arrayCalled when epg boundaries are left
itemHeightno30NumberPicker's single item height
fixedHeightnofalseBoolDisable dynamic height calculation
rotationEnablednotrueBoolAuto rotation support which is calling handleWrapperHeightChange method

Default styles

        wrapperStyle = {
            height: this.wrapperHeight,
            flex: 1,
            overflow: 'hidden',
        },
        highlightStyle = {
            position: 'absolute',
            top: (this.wrapperHeight - this.itemHeight) / 2,
            height: this.itemHeight,
            width: highlightWidth,
        },
        itemWrapper: {
            height: 30,
            justifyContent: 'center',
            alignItems: 'center',
        },
        itemText: {
            color: '#999',
        },
        itemTextSelected: {
            color: '#333',
        },

Contributors ✨

Thanks goes to these wonderful people :shipit:

This project follows the all-contributors specification. Contributions of any kind welcome!

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago