diff --git a/README.md b/README.md index 7c8a0929..d5496600 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ React Native date & time picker component for iOS, Android and Windows. - [`themeVariant` (`optional`, `iOS only`)](#themevariant-optional-ios-only) - [`locale` (`optional`, `iOS only`)](#locale-optional-ios-only) - [`is24Hour` (`optional`, `Windows and Android only`)](#is24hour-optional-windows-and-android-only) + - [`positiveButtonLabel` (`optional`, `Android only`)](#positiveButtonLabel-optional-android-only) + - [`negativeButtonLabel` (`optional`, `Android only`)](#negativeButtonLabel-optional-android-only) - [`neutralButtonLabel` (`optional`, `Android only`)](#neutralbuttonlabel-optional-android-only) - [`minuteInterval` (`optional`)](#minuteinterval-optional) - [`style` (`optional`, `iOS only`)](#style-optional-ios-only) @@ -427,6 +429,22 @@ Allows changing of the time picker to a 24 hour format. By default, this value i ``` +#### `positiveButtonLabel` (`optional`, `Android only`) + +Changes the label of the positive button. + +```js + +``` + +#### `negativeButtonLabel` (`optional`, `Android only`) + +Changes the label of the negative button. + +```js + +``` + #### `neutralButtonLabel` (`optional`, `Android only`) Allows displaying neutral button on picker dialog. diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java index 15b75128..eaaeb320 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNConstants.java @@ -9,6 +9,8 @@ public final class RNConstants { public static final String ARG_IS24HOUR = "is24Hour"; public static final String ARG_DISPLAY = "display"; public static final String ARG_NEUTRAL_BUTTON_LABEL = "neutralButtonLabel"; + public static final String ARG_POSITIVE_BUTTON_LABEL = "positiveButtonLabel"; + public static final String ARG_NEGATIVE_BUTTON_LABEL = "negativeButtonLabel"; public static final String ARG_TZOFFSET_MINS = "timeZoneOffsetInMinutes"; public static final String ACTION_DATE_SET = "dateSetAction"; public static final String ACTION_TIME_SET = "timeSetAction"; diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java index f2e43063..ad7b8fd3 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogFragment.java @@ -106,6 +106,12 @@ static DatePickerDialog createDialog( if (args != null && args.containsKey(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)) { dialog.setButton(DialogInterface.BUTTON_NEUTRAL, args.getString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL), mOnNeutralButtonActionListener); } + if (args != null && args.containsKey(RNConstants.ARG_POSITIVE_BUTTON_LABEL)) { + dialog.setButton(DialogInterface.BUTTON_POSITIVE, args.getString(RNConstants.ARG_POSITIVE_BUTTON_LABEL), dialog); + } + if (args != null && args.containsKey(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)) { + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, args.getString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL), dialog); + } final DatePicker datePicker = dialog.getDatePicker(); diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogModule.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogModule.java index 493ea2e2..9432c3c5 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogModule.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNDatePickerDialogModule.java @@ -171,6 +171,12 @@ private Bundle createFragmentArguments(ReadableMap options) { if (options.hasKey(RNConstants.ARG_NEUTRAL_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)) { args.putString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL, options.getString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)); } + if (options.hasKey(RNConstants.ARG_POSITIVE_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_POSITIVE_BUTTON_LABEL)) { + args.putString(RNConstants.ARG_POSITIVE_BUTTON_LABEL, options.getString(RNConstants.ARG_POSITIVE_BUTTON_LABEL)); + } + if (options.hasKey(RNConstants.ARG_NEGATIVE_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)) { + args.putString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL, options.getString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)); + } if (options.hasKey(RNConstants.ARG_TZOFFSET_MINS) && !options.isNull(RNConstants.ARG_TZOFFSET_MINS)) { args.putLong(RNConstants.ARG_TZOFFSET_MINS, (long) options.getDouble(RNConstants.ARG_TZOFFSET_MINS)); } diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogFragment.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogFragment.java index 9e53197d..800b28f2 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogFragment.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogFragment.java @@ -106,6 +106,12 @@ static TimePickerDialog createDialog( if (args != null && args.containsKey(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)) { dialog.setButton(DialogInterface.BUTTON_NEUTRAL, args.getString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL), mOnNeutralButtonActionListener); } + if (args != null && args.containsKey(RNConstants.ARG_POSITIVE_BUTTON_LABEL)) { + dialog.setButton(DialogInterface.BUTTON_POSITIVE, args.getString(RNConstants.ARG_POSITIVE_BUTTON_LABEL), dialog); + } + if (args != null && args.containsKey(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)) { + dialog.setButton(DialogInterface.BUTTON_NEGATIVE, args.getString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL), dialog); + } return dialog; } diff --git a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogModule.java b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogModule.java index 6734fda2..0a31f8cf 100644 --- a/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogModule.java +++ b/android/src/main/java/com/reactcommunity/rndatetimepicker/RNTimePickerDialogModule.java @@ -145,6 +145,12 @@ private Bundle createFragmentArguments(ReadableMap options) { if (options.hasKey(RNConstants.ARG_NEUTRAL_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)) { args.putString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL, options.getString(RNConstants.ARG_NEUTRAL_BUTTON_LABEL)); } + if (options.hasKey(RNConstants.ARG_POSITIVE_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_POSITIVE_BUTTON_LABEL)) { + args.putString(RNConstants.ARG_POSITIVE_BUTTON_LABEL, options.getString(RNConstants.ARG_POSITIVE_BUTTON_LABEL)); + } + if (options.hasKey(RNConstants.ARG_NEGATIVE_BUTTON_LABEL) && !options.isNull(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)) { + args.putString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL, options.getString(RNConstants.ARG_NEGATIVE_BUTTON_LABEL)); + } if (options.hasKey(RNConstants.ARG_INTERVAL) && !options.isNull(RNConstants.ARG_INTERVAL)) { args.putInt(RNConstants.ARG_INTERVAL, options.getInt(RNConstants.ARG_INTERVAL)); } diff --git a/src/DateTimePickerAndroid.android.js b/src/DateTimePickerAndroid.android.js index a12da178..3616b6ec 100644 --- a/src/DateTimePickerAndroid.android.js +++ b/src/DateTimePickerAndroid.android.js @@ -30,7 +30,9 @@ function open(props: AndroidNativeProps) { is24Hour, minimumDate, maximumDate, + positiveButtonLabel, neutralButtonLabel, + negativeButtonLabel, minuteInterval, timeZoneOffsetInMinutes, onChange, @@ -47,9 +49,11 @@ function open(props: AndroidNativeProps) { is24Hour, minimumDate, maximumDate, - neutralButtonLabel, minuteInterval, timeZoneOffsetInMinutes, + positiveButtonLabel, + neutralButtonLabel, + negativeButtonLabel, }); const presentPicker = async () => { diff --git a/src/androidUtils.js b/src/androidUtils.js index 8f63abc4..f7b9db12 100644 --- a/src/androidUtils.js +++ b/src/androidUtils.js @@ -21,6 +21,8 @@ type Params = { neutralButtonLabel: AndroidNativeProps['neutralButtonLabel'], minuteInterval: AndroidNativeProps['minuteInterval'], timeZoneOffsetInMinutes: AndroidNativeProps['timeZoneOffsetInMinutes'], + positiveButtonLabel: AndroidNativeProps['positiveButtonLabel'], + negativeButtonLabel: AndroidNativeProps['negativeButtonLabel'], }; export function getOpenPicker({ mode, @@ -32,6 +34,8 @@ export function getOpenPicker({ neutralButtonLabel, minuteInterval, timeZoneOffsetInMinutes, + positiveButtonLabel, + negativeButtonLabel, }: Params): PresentPickerCallback { switch (mode) { case ANDROID_MODE.time: @@ -44,6 +48,8 @@ export function getOpenPicker({ is24Hour, neutralButtonLabel, timeZoneOffsetInMinutes, + positiveButtonLabel, + negativeButtonLabel, }); default: return () => @@ -55,6 +61,8 @@ export function getOpenPicker({ maximumDate, neutralButtonLabel, timeZoneOffsetInMinutes, + positiveButtonLabel, + negativeButtonLabel, }); } } diff --git a/src/datetimepicker.android.js b/src/datetimepicker.android.js index 375e6882..379aa818 100644 --- a/src/datetimepicker.android.js +++ b/src/datetimepicker.android.js @@ -23,6 +23,8 @@ export default function RNDateTimePicker(props: AndroidNativeProps): null { neutralButtonLabel, minuteInterval, timeZoneOffsetInMinutes, + positiveButtonLabel, + negativeButtonLabel, onError, } = props; invariant(value, 'A date or time must be specified as `value` prop.'); @@ -46,6 +48,8 @@ export default function RNDateTimePicker(props: AndroidNativeProps): null { neutralButtonLabel, minuteInterval, timeZoneOffsetInMinutes, + positiveButtonLabel, + negativeButtonLabel, onError, onChange, }; diff --git a/src/index.d.ts b/src/index.d.ts index c1f14416..32092fa2 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -142,8 +142,9 @@ export type AndroidNativeProps = Readonly< */ minuteInterval?: MinuteInterval; + positiveButtonLabel?: string; neutralButtonLabel?: string; - + negativeButtonLabel?: string; /** * callback when an error occurs inside the date picker native code (such as null activity) */ diff --git a/src/types.js b/src/types.js index 32620ef8..6d4e62e1 100644 --- a/src/types.js +++ b/src/types.js @@ -172,6 +172,8 @@ export type AndroidNativeProps = $ReadOnly<{| minuteInterval?: MinuteInterval, neutralButtonLabel?: string, + positiveButtonLabel?: string, + negativeButtonLabel?: string, onError?: (Error) => void, |}>;