Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 1 addition & 132 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,137 +1,6 @@
# react-native-wheel-picker
[![npm version](http://img.shields.io/npm/v/react-native-wheel-picker.svg?style=flat-square)](https://npmjs.org/package/react-native-wheel-picker "View this project on npm")
[![npm version](http://img.shields.io/npm/dm/react-native-wheel-picker.svg?style=flat-square)](https://npmjs.org/package/react-native-wheel-picker "View this project on npm")

## Introduction
Cross platform Picker component based on React-native.

Since picker is originally supported by ios while Android only supports a ugly Spinner component. If you want to have the same user behaviour, you can use this.

The android component is based on https://github.com/AigeStudio/WheelPicker which runs super fast and smoothly. It also supports curved effect which make it exactly the same looking and feel as the ios picker.
![](https://raw.githubusercontent.com/lesliesam/react-native-wheel-picker/master/demo.gif)
![](https://raw.githubusercontent.com/lesliesam/react-native-wheel-picker/master/demo_android.gif)

## How to use

Run command

For apps using RN 0.40 or higher, please run
```
npm i react-native-wheel-picker --save
```
For apps using RN 0.39 or less, please run
```
npm install --save --save-exact react-native-wheel-picker@1.1.2
```
Add in settings.gradle
```
include ':react-native-wheel-picker'
project(':react-native-wheel-picker').projectDir = new File(settingsDir, '../node_modules/react-native-wheel-picker/android')
```
Add in app/build.gradle
```
compile project(':react-native-wheel-picker')
```
Modify MainApplication
```
import com.zyu.ReactNativeWheelPickerPackage;
......

protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(), new ReactNativeWheelPickerPackage()
);
}
```

## Example code
```
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
} from 'react-native';


import Picker from 'react-native-wheel-picker'
var PickerItem = Picker.Item;

export default class App extends Component<{}> {

constructor(props) {
super(props);
this.state = {
selectedItem : 2,
itemList: ['刘备', '张飞', '关羽', '赵云', '黄忠', '马超', '魏延', '诸葛亮']
};
}

onPickerSelect (index) {
this.setState({
selectedItem: index,
})
}

onAddItem = () => {
var name = '司马懿'
if (this.state.itemList.indexOf(name) == -1) {
this.state.itemList.push(name)
}
this.setState({
selectedItem: this.state.itemList.indexOf(name),
})
}

render () {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>

<Picker style={{width: 150, height: 180}}
lineColor="#000000" //to set top and bottom line color (Without gradients)
lineGradientColorFrom="#008000" //to set top and bottom starting gradient line color
lineGradientColorTo="#FF5733" //to set top and bottom ending gradient line color
selectedValue={this.state.selectedItem}
itemStyle={{color:"white", fontSize:26}}
onValueChange={(index) => this.onPickerSelect(index)}>
{this.state.itemList.map((value, i) => (
<PickerItem label={value} value={i} key={"money"+value}/>
))}
</Picker>
<Text style={{margin: 20, color: '#ffffff'}}>
你最喜欢的是:{this.state.itemList[this.state.selectedItem]}
</Text>

<Text style={{margin: 20, color: '#ffffff'}}
onPress={this.onAddItem}>
怎么没有司马懿?
</Text>
</View>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#1962dd',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
color: '#ffffff',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
```
Forked from https://github.com/m3rlin94/react-native-wheel-picker
48 changes: 0 additions & 48 deletions WheelCurvedPicker.android.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,20 @@
'use strict';

import React from 'react';
import PropTypes from 'prop-types'
import {
View,
ColorPropType,
requireNativeComponent,
} from 'react-native';

const defaultItemStyle = { color: 'white', fontSize: 26 };

const WheelCurvedPickerNativeInterface = {
name: 'WheelCurvedPicker',
propTypes: {
...View.propTypes,
data:PropTypes.array,
textColor: ColorPropType,
textSize: PropTypes.number,
itemStyle: PropTypes.object,
itemSpace: PropTypes.number,
lineColor: PropTypes.string,
lineGradientColorFrom: PropTypes.string,
lineGradientColorTo: PropTypes.string,
onValueChange: PropTypes.func,
selectedValue: PropTypes.any,
selectedIndex: PropTypes.number,
}
}

const WheelCurvedPickerNative = requireNativeComponent('WheelCurvedPicker', WheelCurvedPickerNativeInterface);

class WheelCurvedPicker extends React.Component {

propTypes: {
...View.propTypes,

data: PropTypes.array,

textColor: ColorPropType,

textSize: PropTypes.number,

itemStyle: PropTypes.object,

itemSpace: PropTypes.number,

onValueChange: PropTypes.func,

selectedValue: PropTypes.any,

selectedIndex: PropTypes.number,

lineColor: PropTypes.string,

lineGradientColorFrom: PropTypes.string,

lineGradientColorTo: PropTypes.string,
}

constructor(props){
super(props)
this.state = this._stateFromProps(props)
Expand Down Expand Up @@ -106,11 +63,6 @@ class WheelCurvedPicker extends React.Component {
}

class Item extends React.Component {
propTypes: {
value: React.PropTypes.any, // string or integer basically
label: React.PropTypes.string,
}

render () {
// These items don't get rendered directly.
return null;
Expand Down
19 changes: 12 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}


android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion safeExtGet('compileSdkVersion', 26)
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
minSdkVersion safeExtGet('minSdkVersion', 16)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
ndk {
Expand All @@ -15,7 +20,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "cn.aigestudio.wheelpicker:WheelPicker:1.0.3"
compile 'com.facebook.react:react-native:+'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "cn.aigestudio.wheelpicker:WheelPicker:1.0.3"
implementation 'com.facebook.react:react-native:+'
}
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "react-native-wheel-picker",
"version": "1.2.0",
"description": "React native cross platform picker.",
"name": "react-native-wheel-picker-cross-platform",
"version": "1.0.2",
"description": "React native cross platform picker. Forked https://github.com/lesliesam/react-native-wheel-picker.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/lesliesam/react-native-wheel-picker.git"
},
"keywords": [
"react-native",
"picker",
"wheel"
"wheel"
],
"author": "Yu Zheng",
"license": "ISC",
"bugs": {
"url": "https://github.com/lesliesam/react-native-wheel-picker/issues"
"homepage": "https://github.com/WesleyFaveri/react-native-wheel-picker/blob/master/README.md",
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/WesleyFaveri/react-native-wheel-picker.git"
},
"homepage": "https://github.com/lesliesam/react-native-wheel-picker#readme",
"dependencies": {}
"bugs": {
"url": "https://github.com/WesleyFaveri/react-native-wheel-picker/issues"
}
}