1.0.2 • Published 4 years ago

react-native-opt-picker v1.0.2

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

React Native Picker with super easy adaptibility

demo

Documentation

Params

KeyTypeDefaultSupportDescription
isLoopBooleanfalseAndroid
pickerTextEllipsisLennumber6Android
pickerConfirmBtnTextstringconfirmiOS/Android
pickerCancelBtnTextstringcanceliOS/Android
pickerTitleTextstringpls selectiOS/Android
pickerConfirmBtnColorarray1, 186, 245, 1iOS/Android
pickerCancelBtnColorarray1, 186, 245, 1iOS/Android
pickerTitleColorarray20, 20, 20, 1iOS/Android
pickerToolBarBgarray232, 232, 232, 1iOS/Android
pickerBgarray196, 199, 206, 1iOS/Android
pickerToolBarFontSizenumber16iOS/Android
wheelFlexarray1, 1, 1iOS/Android
pickerFontSizenumber16iOS/Android
pickerFontColorarray31, 31, 31, 1iOS/Android
pickerFontFamilystringiOS/Android
pickerRowHeightnumber24iOS
pickerDataarrayiOS/Android
selectedValuearrayiOS/Android
onPickerConfirmfunctioniOS/Android
onPickerCancelfunctioniOS/Android
onPickerSelectfunctioniOS/Android

Methods

KeySupportDescription
initiOS/Androidinit and pass parameters to picker
toggleiOS/Androidshow or hide picker
showiOS/Androidshow picker
hideiOS/Androidhide picker
selectiOS/Androidselect a row
isPickerShowiOS/Androidget status of picker, return a boolean

Usage

Step 1 - install

	yarn add react-native-opt-picker

Step 2 - install native module

	cd ios && pod install && cd ..

Step 2 - import and use in project

import Picker from 'react-native-opt-picker';
let data = [];
for (var i = 0; i < 100; i++) {
	data.push(i);
}

Picker.init({
	pickerData: data,
	selectedValue: [59],
	onPickerConfirm: data => {
		console.log(data);
	},
	onPickerCancel: data => {
		console.log(data);
	},
	onPickerSelect: data => {
		console.log(data);
	}
});
Picker.show();

Notice

support two modes:

1. parallel: such as time picker, wheels have no connection with each other

2. cascade: such as date picker, address picker .etc, when front wheel changed, the behind wheels will all be reset

parallel:

  • single wheel:
pickerData = [1, 2, 3, 4];
selectedValue = 3;
  • two or more wheel:
pickerData = [
    [1,2,3,4],
    [5,6,7,8],
    ...
];
selectedValue = [1, 5];

cascade:

  • two wheel
pickerData = [
    {
        a: [1, 2, 3, 4]
    },
    {
        b: [5, 6, 7, 8]
    },
    ...
];
selectedValue = ['a', 2];
  • three wheel
pickerData = [
    {
        a: [
            {
                a1: [1, 2, 3, 4]
            },
            {
                a2: [5, 6, 7, 8]
            },
            {
                a3: [9, 10, 11, 12]
            }
        ]
    },
    {
        b: [
            {
                b1: [11, 22, 33, 44]
            },
            {
                b2: [55, 66, 77, 88]
            },
            {
                b3: [99, 1010, 1111, 1212]
            }
        ]
    },
    {
        c: [
            {
                c1: ['a', 'b', 'c']
            },
            {
                c2: ['aa', 'bb', 'cc']
            },
            {
                c3: ['aaa', 'bbb', 'ccc']
            }
        ]
    },
    ...
]