Skip to content

Commit ed0c925

Browse files
pandiaraj44Facebook Github Bot
authored andcommitted
Android datepicker mode configurations added
Summary: Currently, The **DatePickerAndroid** component opens the native date picker with default mode. We can't able to change the mode via configurations. To support android **[date-picker mode](https://developer.android.com/reference/android/widget/DatePicker.html)**, existing component needs to be changed. **For Android >= 5.0**, The DatePickerDialog doesn't provide the default method to change the mode of a date picker. So I have added custom theme which will support two kinds of **mode('spinner','calendar')** ref:https://developer.android.com/reference/android/R.attr.html#datePickerStyle. **For Android < 5.0,** The DatePickerDialog provides the default method to change the mode of a date picker. ref:https://developer.android.com/reference/android/widget/DatePicker.html#setCalendarViewShown(boolean). With the help of **Build.VERSION.SDK_INT** I have done the above functionality with limited lines of code changes and also I have added the example to UIExplorer. Closes react/react-native#10932 Differential Revision: D4176089 Pulled By: ericvicenti fbshipit-source-id: 7dfa9101214501ac2124bda7ee273a538f04e7cf
1 parent 8b43d9d commit ed0c925

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

UIExplorer/js/DatePickerAndroidExample.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class DatePickerAndroidExample extends React.Component {
4040
presetDate: new Date(2020, 4, 5),
4141
allDate: new Date(2020, 4, 5),
4242
simpleText: 'pick a date',
43+
spinnerText: 'pick a date',
44+
calendarText: 'pick a date',
45+
defaultText: 'pick a date',
4346
minText: 'pick a date, no earlier than today',
4447
maxText: 'pick a date, no later than today',
4548
presetText: 'pick a date, preset to 2020/5/5',
@@ -72,6 +75,24 @@ class DatePickerAndroidExample extends React.Component {
7275
<Text style={styles.text}>{this.state.simpleText}</Text>
7376
</TouchableWithoutFeedback>
7477
</UIExplorerBlock>
78+
<UIExplorerBlock title="Simple spinner date picker">
79+
<TouchableWithoutFeedback
80+
onPress={this.showPicker.bind(this, 'spinner', {date: this.state.spinnerDate, mode: 'spinner'})}>
81+
<Text style={styles.text}>{this.state.spinnerText}</Text>
82+
</TouchableWithoutFeedback>
83+
</UIExplorerBlock>
84+
<UIExplorerBlock title="Simple calendar date picker">
85+
<TouchableWithoutFeedback
86+
onPress={this.showPicker.bind(this, 'calendar', {date: this.state.calendarDate, mode: 'calendar'})}>
87+
<Text style={styles.text}>{this.state.calendarText}</Text>
88+
</TouchableWithoutFeedback>
89+
</UIExplorerBlock>
90+
<UIExplorerBlock title="Simple default date picker">
91+
<TouchableWithoutFeedback
92+
onPress={this.showPicker.bind(this, 'default', {date: this.state.defaultDate, mode: 'default'})}>
93+
<Text style={styles.text}>{this.state.defaultText}</Text>
94+
</TouchableWithoutFeedback>
95+
</UIExplorerBlock>
7596
<UIExplorerBlock title="Date picker with pre-set date">
7697
<TouchableWithoutFeedback
7798
onPress={this.showPicker.bind(this, 'preset', {date: this.state.presetDate})}>

0 commit comments

Comments
 (0)