Repository navigation
Introduce neutral button via neutralButtonLabel on Android pickers - #93
Conversation
vonovak
left a comment
There was a problem hiding this comment.
hi! thanks for your contribution, this is looking, good. Can you just rebase on top of master and resolve the comments? thanks!
| event.type = 'dismissed'; | ||
| onChange(event); | ||
| break; | ||
| case NEUTRAL_BUTTON_ACTION: |
There was a problem hiding this comment.
can you move this case above the default branch for readability? thanks
| boolean is24hour = DateFormat.is24HourFormat(activityContext); | ||
|
|
||
| RNTimePickerDisplay display = RNTimePickerDisplay.DEFAULT; | ||
| TimePickerDialog dialog = null; |
There was a problem hiding this comment.
instead of having this local variable that you assign later on, would it be possible to extract the logic of the ifs and switch statements into a separate function that just returns the TimePickerDialog instance?
There was a problem hiding this comment.
Absolutely, I've just mirrored existing code as I wanted to keep consistency of approach with existing codebase. https://github.com/react-native-community/react-native-datetimepicker/blob/bdcee75420bb796a94ef010f8c751378cd8b4e05/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java#L55
There was a problem hiding this comment.
I've refactored both to have same approach
| <RNDateTimePicker is24Hour={true} /> | ||
| ``` | ||
|
|
||
| ### `neutralButtonLabel` (`optional`, `Android only`) |
There was a problem hiding this comment.
please use #### which is a little more readable, the readme was just updated to that format, thank you.
bbf52f3 to
95968a2
Compare
Thank you very much for your review, I've updated code to reflect your comments. |
9181541 to
2356d9a
Compare
|
thanks! Would you be interested in becoming a maintainer? |
@vonovak I have interest to help to maintain the module |
Summary
I've needed to allow to display
CLEARbutton along the default two buttons present on Android pickers. In order to do so, I've utilised DialogInterface.BUTTON_NEUTRAL to which I assign label fromneutralButtonLabelproperty if present. If not, button is not rendered.Presses of this button can be observed in
onChangehandler and returnsneutralButtonPressedaction type.I've enabled this new button on both DatePickers and TimePickers to keep functional parity between them
Screenshot of date picker with added neutral button

Test Plan
What's required for testing (prerequisites)?
Run on Android and add your chosen
neutralButtonLabelproperty on DateTimePicker component.What are the steps to reproduce (after prerequisites)?
Open DateTimePicker and you should be able to see your new button with chosen label and it's presses can be obtained through
onChangehandler.Compatibility
Checklist
README.mdCHANGELOG.mdexample/App.js)