Skip to content

Introduce neutral button via neutralButtonLabel on Android pickers - #93

Merged
vonovak merged 8 commits into
react-native-datetimepicker:masterfrom
lochness42:support-neutral-button-on-android
Feb 2, 2020
Merged

vonovak merged 8 commits into
react-native-datetimepicker:masterfrom
lochness42:support-neutral-button-on-android

Conversation

@lochness42

Copy link
Copy Markdown

Summary

I've needed to allow to display CLEAR button 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 from neutralButtonLabel property if present. If not, button is not rendered.
Presses of this button can be observed in onChange handler and returns neutralButtonPressed action 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
Screenshot 2020-01-24 at 15 17 57

Test Plan

What's required for testing (prerequisites)?

Run on Android and add your chosen neutralButtonLabel property 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 onChange handler.

Compatibility

OS Implemented
iOS ❌
Android ✅

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I mentioned this change in CHANGELOG.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

@lochness42
lochness42 marked this pull request as ready for review January 24, 2020 15:31

@vonovak vonovak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi! thanks for your contribution, this is looking, good. Can you just rebase on top of master and resolve the comments? thanks!

Comment thread src/datetimepicker.android.js Outdated
event.type = 'dismissed';
onChange(event);
break;
case NEUTRAL_BUTTON_ACTION:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this case above the default branch for readability? thanks

boolean is24hour = DateFormat.is24HourFormat(activityContext);

RNTimePickerDisplay display = RNTimePickerDisplay.DEFAULT;
TimePickerDialog dialog = null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've refactored both to have same approach

Comment thread README.md Outdated
<RNDateTimePicker is24Hour={true} />
```

### `neutralButtonLabel` (`optional`, `Android only`)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use #### which is a little more readable, the readme was just updated to that format, thank you.

@lochness42
lochness42 force-pushed the support-neutral-button-on-android branch from bbf52f3 to 95968a2 Compare February 1, 2020 22:01
@lochness42

Copy link
Copy Markdown
Author

hi! thanks for your contribution, this is looking, good. Can you just rebase on top of master and resolve the comments? thanks!

Thank you very much for your review, I've updated code to reflect your comments.

@lochness42
lochness42 requested a review from vonovak February 1, 2020 22:09
@lochness42
lochness42 force-pushed the support-neutral-button-on-android branch from 9181541 to 2356d9a Compare February 2, 2020 19:29
@lochness42
lochness42 requested a review from vonovak February 2, 2020 19:31
@vonovak
vonovak merged commit 4a58709 into react-native-datetimepicker:master Feb 2, 2020
@vonovak

vonovak commented Feb 2, 2020

Copy link
Copy Markdown
Member

thanks! Would you be interested in becoming a maintainer?

@lochness42
lochness42 deleted the support-neutral-button-on-android branch February 2, 2020 20:03
@luancurti

Copy link
Copy Markdown
Member

thanks! Would you be interested in becoming a maintainer?

@vonovak I have interest to help to maintain the module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants