index.js 2.33 KB
Newer Older
xwenliang's avatar
xwenliang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
'use strict';

import React, {
	StyleSheet, 
	PropTypes, 
	View, 
	Text,
	Animated,
	Platform,
	Dimensions
} from 'react-native';

import PickerAndroid from 'react-native-picker-android';

let Picker = Platform.OS === 'ios' ? PickerIOS : PickerAndroid;
let PickerItem = Picker.Item;
let width = Dimensions.get('window').width;
let height = Dimensions.get('window').height;

export default class PickerAny extends React.Component {

	constructor(props, context){
		super(props, context);
		this.state = {

		};
	};

	_prePressHandle(callback){
		this.picker.moveUp();
	};

	_nextPressHandle(callback){
		this.picker.moveDown();
	};
	
	render(){
		<Animated.View style={[styles.picker, {bottom: this.state.slideAnim}]}>
			<View style={styles.pickerToolbar}>
				<View style={styles.pickerBtnView}>
					<Text style={styles.pickerMoveBtn} onPress={this._prePressHandle}>上一个</Text>
					<Text style={styles.pickerMoveBtn} onPress={this._nextPressHandle}>下一个</Text>
				</View>
				<View style={styles.pickerFinishBtn}>
					<Text style={styles.pickerFinishBtnText} 
						onPress={() => {
							this.setState({course: this.state.courseData[this.index || 0]})
							this._pickerToggle();
						}}>完成</Text>
				</View>
			</View>
			<Picker
				ref={(picker) => { this.picker = picker }}
				selectedValue={this.props.selectedValue}
				onValueChange={(index) => this.index = index} >
				{this.props.pickerData.map((value, index) => (
					<PickerAndroid.Item
						key={index}
						value={value}
						label={value}
					/>)
				)}
			</Picker>
		</Animated.View>
	};
};

let styles = StyleSheet.create({
	picker: { 
		flex: 1,
		position: 'absolute',
		bottom: 0,
		left: 0,
		backgroundColor: 'rgb(189, 192, 199)',
		width: width,  
		height: height / 3, 
		overflow: 'hidden', 
	},
	pickerToolbar: {
		height: 30,
		width: width,
		backgroundColor: '#e6e6e6',
		flexDirection: 'row',
		borderTopWidth: 1,
		borderBottomWidth: 1,
		borderColor: '#c3c3c3'
	},
	pickerBtnView: {
		flex: 1,
		flexDirection: 'row',
		justifyContent: 'flex-start',
		alignItems: 'center',
		paddingLeft: 20
	},
	pickerMoveBtn: {
		paddingLeft: 20,
		color: '#149be0',
		fontSize: 16,
	},
	pickerFinishBtn: {
		flex: 1,
		flexDirection: 'row',
		justifyContent: 'flex-end',
		alignItems: 'center',
		paddingRight: 20,
	},
	pickerFinishBtnText: {
		fontSize: 16,
		color: '#149be0'
	}
});