Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown option for selecting the year #25

Closed
wants to merge 8 commits into from
Closed
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Here is a quick example of how it works, with custom appearance:

## Installation

`npm install --save react-native-calendar-datepicker`
`npm install --save react-native-calendar-datepicker && react-native link react-native-vector-icons`

__Minimum react-native: "^0.33.0"__

Expand Down Expand Up @@ -50,7 +50,8 @@ import Moment from 'moment';
| *startStage* | "day"/"month"/"year" | **[Default: "day"]** Whether you would like to select the day, month or year first.
| *finalStage* | "day"/"month"/"year" | **[Default: "day"]** The last level of selection you want.
| *slideThreshold* | number | **[Default: min([width / 3, 250])]** The number of pixels after which the slide event will be triggered.
| *showArrows* | boolean | **[Default: false]** Whether you would like to show arrow buttons for moving between months.
| *showArrows* | boolean | **[Default: true]** Whether you would like to show arrow buttons for moving between months.
| *yearSelectorType* | "slider" or "dropdown" | **[Default: "slider"]** Whether you would like to use a slider or dropdown for selectin the year in your calendar

### Locale specific calendar

Expand Down Expand Up @@ -109,9 +110,10 @@ Below is the list of properties that can be used for styling. For a concrete exa

Main Developer: [Vlad-Doru Ion](http://github.com/vlad-doru)

Pull requests by:
Pull requests by:
* [Jason Gaare](http://github.com/jasongaare)
* [Igor Kurr](http://github.com/igorrKurr)
* [Igor Kurr](http://github.com/igorrKurr)
* [Hossein Ahmadian-Yazdi](http://github.com/hahmadia)

## License

Expand Down
1 change: 1 addition & 0 deletions demo/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class demo extends Component {
//finalStage="month"
minDate={Moment().startOf('day')}
maxDate={Moment().add(10, 'years').startOf('day')}
yearSelectorType={'dropdown'}
//General Styling}
style={{
borderWidth: 1,
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"dependencies": {
"react": "^15.4.2",
"react-native": "^0.41.2",
"react-native-calendar-datepicker": "^1.2.2"
"react-native-calendar-datepicker": "git://github.com/EdevMosaic/react-native-calendar-datepicker.git#year-selector-dropdown"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"dependencies": {
"lodash": "^4.15.0",
"moment": "^2.14.1",
"prop-types": "^15.6.0"
"prop-types": "^15.6.0",
"react-native-vector-icons": "^4.4.2"
},
"description": "Cross platform calendar datepicker library for React Native.",
"main": "index.js",
Expand Down
3 changes: 3 additions & 0 deletions src/container/Calendar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Props = {
yearMaxTintColor?: string,
yearSlider?: Slider.propTypes.style,
yearText?: Text.propTypes.style,
yearSelectorType?: string,
};
type State = {
stage: Stage,
Expand Down Expand Up @@ -240,6 +241,7 @@ export default class Calendar extends Component {
maximumTrackTintColor={this.props.yearMaxTintColor}
yearSlider={this.props.yearSlider}
yearText={this.props.yearText}
yearSelectorType={this.props.yearSelectorType}
/> :
null
}
Expand All @@ -254,6 +256,7 @@ Calendar.defaultProps = {
startStage: DAY_SELECTOR,
finalStage: DAY_SELECTOR,
showArrows: true,
yearSelectorType: 'slider',
};

const styles = StyleSheet.create({
Expand Down
3 changes: 2 additions & 1 deletion src/pure/DaySelector.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
View,
Text,
StyleSheet,
Platform
} from 'react-native';
import ViewPropTypes from '../util/ViewPropTypes';

Expand Down Expand Up @@ -62,7 +63,7 @@ export default class DaySelector extends Component {
_slide = (dx : number) => {
this.refs.wrapper.setNativeProps({
style: {
left: dx,
left: Platform.OS === 'ios' ? dx : 0,
}
})
};
Expand Down
62 changes: 47 additions & 15 deletions src/pure/YearSelector.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
View,
Text,
StyleSheet,
Picker,
} from 'react-native';
import ViewPropTypes from '../util/ViewPropTypes';

// Component specific libraries.
import _ from 'lodash';
import Moment from 'moment';
import Icon from 'react-native-vector-icons/dist/FontAwesome';

type Props = {
style?: ViewPropTypes.style,
Expand All @@ -30,6 +32,7 @@ type Props = {
maximumTrackTintColor?: string,
yearSlider?: Slider.propTypes.style,
yearText?: Text.propTypes.style,
yearSelectorType?: string,
};
type State = {
year: Number,
Expand All @@ -53,27 +56,56 @@ export default class YearSelector extends Component {
this.props.onFocus && this.props.onFocus(date);
}

renderSliderOrDropdown(values) {
if (this.props.yearSelectorType === 'dropdown') {
return(
<View>
<Picker
selectedValue={`${this.state.year}`}
onValueChange={(year) => this.setState({year})}
>
{values}
</Picker>
<Icon.Button name="check" size={40} alignSelf="center" underlayColor="transparent" backgroundColor="transparent" borderRadius={0} color={"black"} onPress={() => this._onFocus(this.state.year)}/>
</View>
);
}

return(
<View>
<Slider
minimumValue={this.props.minDate.year()}
maximumValue={this.props.maxDate.year()}
// TODO: Add a property for this.
minimumTrackTintColor={this.props.minimumTrackTintColor}
maximumTrackTintColor={this.props.maximumTrackTintColor}
step={1}
value={this.props.focus.year()}
onValueChange={(year) => this.setState({year})}
onSlidingComplete={(year) => this._onFocus(year)}
style={[this.props.yearSlider]}
/>
<Text style={[styles.yearText, this.props.yearText]}>
{this.state.year}
</Text>
</View>
);
}

render() {
const values = Array(this.props.maxDate.year() - this.props.minDate.year() + 1).fill().map((_,i) => (
<Picker.Item
key={`${this.props.minDate.year() + i}`}
value={`${this.props.minDate.year() + i}`}
label={`${this.props.minDate.year() + i}`}
/>
));
return (
<View style={[{
flexGrow: 1,
// Wrapper view default style.
},this.props.style]}>
<Slider
minimumValue={this.props.minDate.year()}
maximumValue={this.props.maxDate.year()}
// TODO: Add a property for this.
minimumTrackTintColor={this.props.minimumTrackTintColor}
maximumTrackTintColor={this.props.maximumTrackTintColor}
step={1}
value={this.props.focus.year()}
onValueChange={(year) => this.setState({year})}
onSlidingComplete={(year) => this._onFocus(year)}
style={[this.props.yearSlider]}
/>
<Text style={[styles.yearText, this.props.yearText]}>
{this.state.year}
</Text>
{this.renderSliderOrDropdown(values)}
</View>
);
}
Expand Down