mmazzarolo / react-native-modal-datetime-picker

A React-Native datetime-picker for Android and iOS
MIT License
2.97k stars 397 forks source link

fix use defaultProps on android #757

Open gluhenko-dv opened 3 months ago

gluhenko-dv commented 3 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-modal-datetime-picker@17.1.0 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.android.js b/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.android.js
index 3495d1b..5e8d431 100644
--- a/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.android.js
+++ b/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.android.js
@@ -11,7 +11,15 @@ const areEqual = (prevProps, nextProps) => {
 };

 const DateTimePickerModal = memo(
-  ({ date, mode, isVisible, onCancel, onConfirm, onHide, ...otherProps }) => {
+  ({
+    date = new Date(),
+    mode,
+    isVisible = false,
+    onCancel,
+    onConfirm,
+    onHide = () => {},
+    ...otherProps
+  }) => {
     const currentDateRef = useRef(date);
     const [currentMode, setCurrentMode] = useState(null);

@@ -72,10 +80,4 @@ DateTimePickerModal.propTypes = {
   minimumDate: PropTypes.instanceOf(Date),
 };

-DateTimePickerModal.defaultProps = {
-  date: new Date(),
-  isVisible: false,
-  onHide: () => {},
-};
-
 export { DateTimePickerModal };
diff --git a/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.ios.js b/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.ios.js
index 6ef0b0a..baf7a97 100644
--- a/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.ios.js
+++ b/node_modules/react-native-modal-datetime-picker/src/DateTimePickerModal.ios.js
@@ -22,6 +22,9 @@ export const BUTTON_FONT_SIZE = 20;
 export const HIGHLIGHT_COLOR_DARK = "#444444";
 export const HIGHLIGHT_COLOR_LIGHT = "#ebebeb";

+
+
+
 export class DateTimePickerModal extends React.PureComponent {
   static propTypes = {
     buttonTextColorIOS: PropTypes.string,

This issue body was partially generated by patch-package.

marcofuentes05 commented 3 months ago

This patch fixes issue issue 748 👀 I would keep an eye on it